Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update find_movie to find also shows #205

Merged
merged 2 commits into from
Apr 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions plex_trakt_sync/plex_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ def type(self):
if type(self.item) is Show:
return "shows"

@property
@memoize
def media_type(self):
if type(self.item) is Movie:
return "movie"
if type(self.item) is Show:
return "show"

@property
@memoize
def provider(self):
Expand Down
13 changes: 7 additions & 6 deletions plex_trakt_sync/trakt_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from plex_trakt_sync import pytrakt_extensions
from plex_trakt_sync.path import pytrakt_file
from plex_trakt_sync.plex_api import PlexLibraryItem

trakt.core.CONFIG_PATH = pytrakt_file
import trakt.users
Expand Down Expand Up @@ -169,17 +170,17 @@ def add_to_collection(self, m):

@memoize
@rate_limit()
def find_movie(self, movie):
def find_movie(self, media: PlexLibraryItem):
try:
search = trakt.sync.search_by_id(movie.id, id_type=movie.provider)
search = trakt.sync.search_by_id(media.id, id_type=media.provider, media_type=media.media_type)
except JSONDecodeError as e:
raise ValueError(f"Unable to search result for {movie.provider}: {movie.id}: {e.doc!r}") from e
raise ValueError(f"Unable parse search result for {media.provider}/{media.id}: {e.doc!r}") from e
except ValueError as e:
# Search_type must be one of ('trakt', ..., 'imdb', 'tmdb', 'tvdb')
raise ValueError(f"Invalid id_type: {movie.provider}") from e
# look for the first movie in the results
raise ValueError(f"Invalid id_type: {media.provider}") from e
# look for the first wanted type in the results
for m in search:
if type(m) is trakt.movies.Movie:
if m.media_type == media.type:
return m

return None