Skip to content

Commit

Permalink
Merge pull request #2022 from glensc/show-search-match
Browse files Browse the repository at this point in the history
Fix: Improve movie as show search correctness
  • Loading branch information
glensc authored Aug 18, 2024
2 parents 072ccdf + 8e4ab36 commit bd1494a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
4 changes: 4 additions & 0 deletions plextraktsync/plex/PlexGuid.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ def guid_is_imdb_legacy(self):
# old item, like imdb 'tt0112253'
return guid[0:2] == "tt" and guid[2:].isnumeric()

@property
def title(self):
return self.pm.item.title

@property
def title_link(self):
if self.pm:
Expand Down
16 changes: 10 additions & 6 deletions plextraktsync/trakt/TraktApi.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from plextraktsync.factory import factory, logging
from plextraktsync.path import pytrakt_file
from plextraktsync.trakt.PartialTraktMedia import PartialTraktMedia
from plextraktsync.trakt.TraktItem import TraktItem
from plextraktsync.trakt.TraktLookup import TraktLookup
from plextraktsync.trakt.TraktRatingCollection import TraktRatingCollection
from plextraktsync.trakt.WatchProgress import WatchProgress
Expand Down Expand Up @@ -254,16 +255,19 @@ def find_by_episode_guid(self, guid: PlexGuid):
def find_by_guid(self, guid: PlexGuid):
if guid.type == "episode" and guid.is_episode:
return self.find_by_episode_guid(guid)
else:
tm = self.search_by_id(guid.id, id_type=guid.provider, media_type=guid.type)
if tm is None and guid.type == "movie":
if self.search_by_id(guid.id, id_type=guid.provider, media_type="show"):

tm = self.search_by_id(guid.id, id_type=guid.provider, media_type=guid.type)
if tm is None and guid.type == "movie":
show = self.search_by_id(guid.id, id_type=guid.provider, media_type="show")
if show:
if guid.title == show.title:
ts = TraktItem(show)
self.logger.warning(
f"Found match using show search: {guid.title_link}",
f"Found id match using show search: {guid.title_link}: {ts.title_link}",
extra={"markup": True},
)

return tm
return tm

@staticmethod
def find_by_slug(slug: str, media_type: str):
Expand Down
10 changes: 9 additions & 1 deletion plextraktsync/trakt/TraktItem.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
from functools import cached_property
from typing import TYPE_CHECKING

from plextraktsync.mixin.RichMarkup import RichMarkup

if TYPE_CHECKING:
from plextraktsync.trakt.types import TraktMedia


class TraktItem:
class TraktItem(RichMarkup):
def __init__(self, item: TraktMedia):
self.item = item

Expand All @@ -22,3 +24,9 @@ def type(self):
@property
def guids(self):
return {k: v for k, v in self.item.ids["ids"].items() if k in ["imdb", "tmdb", "tvdb"]}

@property
def title_link(self):
link = f"https://trakt.tv/{self.item.ext}"

return self.markup_link(link, self.item.title)

0 comments on commit bd1494a

Please sign in to comment.