Add some typings to methods
MODIFY
plextraktsync/media.py
plextraktsync/media.py
@@ -16,10 +16,11 @@ class Media:
"""
Class containing Plex and Trakt media items (Movie, Episode)
"""
+ plex: PlexLibraryItem
def __init__(
self,
- plex,
+ plex: PlexLibraryItem,
trakt,
plex_api: PlexApi = None,
trakt_api: TraktApi = None,
@@ -252,7 +253,7 @@ def resolve_trakt(self, tm: TraktItem) -> Media:
pm = self._guid_match(result, tm)
return self.make_media(pm, tm.item)
- def make_media(self, plex, trakt):
+ def make_media(self, plex: PlexLibraryItem, trakt):
return Media(plex, trakt, plex_api=self.plex, trakt_api=self.trakt, mf=self)
def _guid_match(self, candidates: List[PlexLibraryItem], tm: TraktItem) -> Optional[PlexLibraryItem]:

MODIFY
plextraktsync/walker.py
plextraktsync/walker.py
from collections import defaultdict
-from typing import List, NamedTuple, Set
+from typing import Any, Generator, List, NamedTuple, Set
from plexapi.video import Episode, Movie, Show
@@ -245,7 +245,7 @@ def print_plan(self, print=print):
if self.plan.episodes:
print(f"Sync Episodes: {self.plan.episodes}")
- def get_plex_movies(self):
+ def get_plex_movies(self) -> Generator[PlexLibraryItem, Any, None]:
"""
Iterate over movie sections unless specific movie is requested
"""
@@ -258,14 +258,14 @@ def get_plex_movies(self):
yield from movies
- def find_movies(self):
+ def find_movies(self) -> Generator[Media, Any, None]:
for plex in self.get_plex_movies():
movie = self.mf.resolve_any(plex)
if not movie:
continue
yield movie
- def get_plex_shows(self):
+ def get_plex_shows(self) -> Generator[PlexLibraryItem, Any, None]:
if self.plan.shows:
shows = self.media_from_items("show", self.plan.shows)
elif self.plan.show_sections:
@@ -290,7 +290,7 @@ def walk_shows(self, shows: Set[Media], title="Processing Shows"):
return
yield from self.progressbar(shows, desc=title)
- def get_plex_episodes(self, episodes):
+ def get_plex_episodes(self, episodes) -> Generator[Media, Any, None]:
it = self.progressbar(episodes, desc="Processing episodes")
for pe in it:
guid = PlexGuid(pe.grandparentGuid, "show")
@@ -304,7 +304,7 @@ def get_plex_episodes(self, episodes):
me.show = show
yield me
- def media_from_sections(self, sections: List[PlexLibrarySection]):
+ def media_from_sections(self, sections: List[PlexLibrarySection]) -> Generator[PlexLibraryItem, Any, None]:
for section in sections:
with measure_time(f"{section.title} processed"):
total = len(section)
@@ -315,12 +315,12 @@ def media_from_sections(self, sections: List[PlexLibrarySection]):
)
yield from it
- def media_from_items(self, libtype: str, items: List):
+ def media_from_items(self, libtype: str, items: List) -> Generator[PlexLibraryItem, Any, None]:
it = self.progressbar(items, desc=f"Processing {libtype}s")
for m in it:
yield PlexLibraryItem(m, self.plex)
- def episode_from_show(self, show: Media):
+ def episode_from_show(self, show: Media) -> Generator[Media, Any, None]:
for pe in show.plex.episodes():
me = self.mf.resolve_any(pe, show)
if not me:
@@ -337,14 +337,14 @@ def progressbar(self, iterable, **kwargs):
else:
yield from iterable
- def media_from_traktlist(self, items: List):
+ def media_from_traktlist(self, items: List) -> Generator[Media, Any, None]:
it = self.progressbar(items, desc="Processing Trakt watchlist")
for media in it:
tm = TraktItem(media, trakt=self.trakt)
m = self.mf.resolve_trakt(tm)
yield m
- def media_from_plexlist(self, items: List):
+ def media_from_plexlist(self, items: List) -> Generator[Media, Any, None]:
it = self.progressbar(items, desc="Processing Plex watchlist")
for media in it:
pm = PlexLibraryItem(media, plex=self.plex)

Add some typings to methods