Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added file-based authentication #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pip install requirements.txt
URL can be any of the following ip:port, plex.direct:port, hostname:port, plex.tv

```
usage: main.py [-h] -u USERNAME -p PASSWORD url
usage: main.py [-h] [-u USERNAME] [-p PASSWORD] [-c COOKIE] [--original-filename] [-t TOKEN] [-f AUTHFILE] url

positional arguments:
url URL to Movie, Show, Season, Episode.
Expand All @@ -41,10 +41,25 @@ optional arguments:
--original-filename Name content by original name
-t TOKEN, --token TOKEN
Plex Token
-f AUTHFILE, --authfile AUTHFILE
Path to a json file containing authentication data
```

## Example
## Examples

```
python main.py -u codedninja -p 3U7qYhaBAk8yfa 'https://app.plex.tv/desktop#!/server/0893cadc04a6f52efa052691d6a07c5b54890ca1/details?key=%2Flibrary%2Fmetadata%2F208649&context=source%3Ahub.tv.recentlyaired'
```

```
python main.py -f auth.json 'https://app.plex.tv/desktop#!/server/0893cadc04a6f52efa052691d6a07c5b54890ca1/details?key=%2Flibrary%2Fmetadata%2F208649&context=source%3Ahub.tv.recentlyaired'
```

Content of `auth.json` :
```json
{
"email": "codedninja",
"password": "3U7qYhaBAk8yfa"
}
```

24 changes: 21 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ def command_line(self):

ap.add_argument("-t", "--token", required=False, help="Plex Token")

ap.add_argument("-f", "--authfile", required=False, help="Path to a json file containing authentication data")

ap.add_argument(
"url", help="URL to Movie, Show, Season, Episode. TIP: Put url inside single quotes.")

Expand All @@ -287,12 +289,28 @@ def command_line(self):
self.cookie = args.cookie
self.original_filename = args.original_filename

if ((self.email is None or self.password is None) and self.token is None and self.cookie is None):
print("Username and psasword, token, or cookie is required")
quit(1)
if args.authfile is not None and self.cantAuthenticateUser():
with open(args.authfile, 'r') as f:
auth_data = json.load(f)
for field in ['email', 'password', 'token', 'cookie']:
if field in auth_data and type(auth_data[field]) == str:
self.__dict__[field] = auth_data[field]

if self.cantAuthenticateUser():
if self.email is None:
self.email = input('Enter username > ')
if self.password is None:
try:
from stdiomask import getpass
except ImportError:
from getpass import getpass
self.password = getpass('Enter password > ')

self.parse_url(args.url)
self.download()

def cantAuthenticateUser(self) :
return ((self.email is None or self.password is None) and self.token is None and self.cookie is None)

def __init__(self):
return
Expand Down