Lazy load plex-login command
MODIFY
plextraktsync/cli.py
plextraktsync/cli.py
from functools import wraps
+from os import environ
+
import click
-from plextraktsync.commands.plex_login import plex_login
from plextraktsync.commands.self_update import enable_self_update, self_update
from plextraktsync.commands.sync import sync
from plextraktsync.commands.trakt_login import trakt_login
from plextraktsync.commands.unmatched import unmatched
from plextraktsync.commands.watch import watch
+from plextraktsync.factory import factory
+
+CONFIG = factory.config()
def command():
@@ -112,6 +116,16 @@ def login():
pass
+@command()
+@click.option("--username", help="Plex login", default=lambda: environ.get("PLEX_USERNAME", CONFIG["PLEX_USERNAME"]))
+@click.option("--password", help="Plex password", default=lambda: environ.get("PLEX_PASSWORD", None))
+def plex_login():
+ """
+ Log in to Plex Account to obtain Access Token. Optionally can use managed user on servers that you own.
+ """
+ pass
+
+
cli.add_command(cache)
cli.add_command(clear_collections)
cli.add_command(info)

MODIFY
plextraktsync/commands/plex_login.py
plextraktsync/commands/plex_login.py
from typing import List
import click
-from click import Choice, ClickException
+from click import ClickException
+from InquirerPy import get_style, inquirer
from plexapi.exceptions import NotFound, Unauthorized
from plexapi.myplex import MyPlexAccount, MyPlexResource, ResourceConnection
from plexapi.server import PlexServer
)
CONFIG = factory.config()
-from InquirerPy import get_style, inquirer
style = get_style({"questionmark": "hidden", "question": "ansiyellow", "pointer": "fg:ansiblack bg:ansiyellow", })
@@ -49,7 +49,8 @@ def choose_managed_user(account: MyPlexAccount):
click.echo(success("Managed user(s) found:"))
users = sorted(users)
users.insert(0, account.username)
- user = inquirer.select(message="Select the user you would like to use:", choices=users, default=None, style=style, qmark="", pointer=">",).execute()
+ user = inquirer.select(message="Select the user you would like to use:", choices=users, default=None, style=style,
+ qmark="", pointer=">", ).execute()
if user == account.username:
return None
@@ -73,7 +74,8 @@ def fmt_server(s):
product = decorator(f"{s.product}/{s.productVersion}")
platform = decorator(f"{s.device}: {s.platform}/{s.platformVersion}")
- click.echo(f"- {highlight(s.name)}: [Last seen: {decorator(str(s.lastSeenAt))}, Server: {product} on {platform}]")
+ click.echo(
+ f"- {highlight(s.name)}: [Last seen: {decorator(str(s.lastSeenAt))}, Server: {product} on {platform}]")
c: ResourceConnection
for c in s.connections:
click.echo(f" {c.uri}")
@@ -94,7 +96,9 @@ def fmt_server(s):
fmt_server(s)
server_names.append(s.name)
- return inquirer.select(message="Select default server:", choices=sorted(server_names), default=None, style=style, qmark="", pointer=">",).execute()
+ return inquirer.select(message="Select default server:", choices=sorted(server_names), default=None, style=style,
+ qmark="", pointer=">", ).execute()
+
def pick_server(account: MyPlexAccount):
servers = account.resources()
@@ -144,14 +148,7 @@ def plex_login_autoconfig():
login(username, password)
-@click.command("plex-login")
-@click.option("--username", help="Plex login", default=lambda: environ.get("PLEX_USERNAME", CONFIG["PLEX_USERNAME"]))
-@click.option("--password", help="Plex password", default=lambda: environ.get("PLEX_PASSWORD", None))
def plex_login(username, password):
- """
- Log in to Plex Account to obtain Access Token. Optionally can use managed user on servers that you own.
- """
-
login(username, password)

Lazy load plex-login command