def watch(): server = factory.plex_server() trakt = factory.trakt_api() plex = factory.plex_api() mf = factory.media_factory() config = factory.config() ws = WebSocketListener(server) updater = WatchStateUpdater(plex, trakt, mf, config) ws.on( PlaySessionStateNotification, updater.on_play, state=["playing", "stopped", "paused"], ) ws.on( ActivityNotification, updater.on_activity, type="library.refresh.items", event="ended", progress=100, ) ws.on(TimelineEntry, updater.on_delete, state=9, metadata_state="deleted") ws.on(Error, updater.on_error) print("Listening for events!") ws.listen()
def login(): api = factory.trakt_api() trakt_authenticate(api) user = api.me.username CONFIG = factory.config() CONFIG["TRAKT_USERNAME"] = user CONFIG.save() click.echo(TRAKT_LOGIN_SUCCESS)
def clear_collections(confirm, dry_run): if not confirm and not dry_run: click.echo("You need to pass --confirm or --dry-run option to proceed") return trakt = factory.trakt_api() for movie in trakt.movie_collection: logger.info(f"Deleting: {movie}") if not dry_run: trakt.remove_from_library(movie) for show in trakt.show_collection: logger.info(f"Deleting: {show}") if not dry_run: trakt.remove_from_library(show)
def print_watched_shows(): from rich.table import Table from plextraktsync.console import console 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))) console.print(table)
def unmatched(no_progress_bar: bool, local: bool): """ List media that has no match in Trakt or Plex """ config = factory.run_config().update(progressbar=not no_progress_bar) ensure_login() plex = factory.plex_api() trakt = factory.trakt_api() mf = factory.media_factory() pb = factory.progressbar(config.progressbar) wc = WalkConfig() walker = Walker(plex, trakt, mf, wc, progressbar=pb) if not wc.is_valid(): click.echo("Nothing to scan, this is likely due conflicting options given.") return failed = [] if local: for pm in walker.get_plex_movies(): if pm.guids[0].provider == 'local': failed.append(pm) else: for pm in walker.get_plex_movies(): movie = mf.resolve_any(pm) if not movie: failed.append(pm) for pm in failed: p = pm.item url = plex.media_url(pm) print("=" * 80) print(f"No match: {pm}") print(f"URL: {url}") print(f"Title: {p.title}") print(f"Year: {p.year}") print(f"Updated At: {p.updatedAt}") for l in p.locations: print(f"Location: {l}") print("")