diff --git a/README.md b/README.md index 247a5cf..bf558a4 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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" +} +``` + diff --git a/main.py b/main.py index 8e1dca2..97019d2 100644 --- a/main.py +++ b/main.py @@ -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.") @@ -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