Move watched_shows logic to own command
MODIFY
plextraktsync/cli.py
plextraktsync/cli.py
@@ -99,13 +99,6 @@ def info():
@command()
@click.argument("input", nargs=-1)
-@click.option(
- "--watched-shows",
- type=bool,
- default=False,
- is_flag=True,
- help="Print Trakt watched_shows and exit",
-)
def inspect():
"""
Inspect details of an object

MODIFY
plextraktsync/commands/inspect.py
plextraktsync/commands/inspect.py
from plextraktsync.factory import factory
from plextraktsync.media import Media
from plextraktsync.plex_api import PlexLibraryItem
+from plextraktsync.util.expand_id import expand_id
from plextraktsync.version import version
-def print_watched_shows():
- from rich.table import Table
-
- trakt = factory.trakt_api()
-
- table = Table(
- show_header=True, header_style="bold magenta", title="Watched shows on Trakt"
- )
- table.add_column("Id", style="dim", width=6)
- table.add_column("Slug")
- table.add_column("Seasons", justify="right")
- for show_id, progress in sorted(trakt.watched_shows.shows.items()):
- id = f"[link=https://trakt.tv/shows/{show_id}]{show_id}[/]"
- slug = f"[link=https://trakt.tv/shows/{progress.slug}]{progress.slug}[/]"
- table.add_row(id, slug, str(len(progress.seasons)))
-
- print(table)
-
-
def inspect_media(id):
plex = factory.plex_api()
mf = factory.media_factory()
@@ -91,13 +73,8 @@ def inspect_media(id):
)
-def inspect(input, watched_shows: bool):
+def inspect(input):
print(f"PlexTraktSync [{version()}]")
- if watched_shows:
- print_watched_shows()
- return
-
- from plextraktsync.util.expand_id import expand_id
for id in expand_id(input):
inspect_media(id)

MODIFY
plextraktsync/commands/watched_shows.py
plextraktsync/commands/watched_shows.py
+from rich.table import Table
+
+from plextraktsync.console import print
+from plextraktsync.factory import factory
+
+
def watched_shows():
- pass
+ trakt = factory.trakt_api()
+
+ table = Table(
+ show_header=True, header_style="bold magenta", title="Watched shows on Trakt"
+ )
+ table.add_column("Id", style="dim", width=6)
+ table.add_column("Slug")
+ table.add_column("Seasons", justify="right")
+ for show_id, progress in sorted(trakt.watched_shows.shows.items()):
+ id = f"[link=https://trakt.tv/shows/{show_id}]{show_id}[/]"
+ slug = f"[link=https://trakt.tv/shows/{progress.slug}]{progress.slug}[/]"
+ table.add_row(id, slug, str(len(progress.seasons)))
+
+ print(table)

Move watched_shows logic to own command