Skip to content

Commit

Permalink
Fix subtitles search for TV shows
Browse files Browse the repository at this point in the history
  • Loading branch information
i96751414 committed Aug 12, 2024
1 parent ae80511 commit 546b2af
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
19 changes: 10 additions & 9 deletions lib/opensubtitles/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@


class DataStruct(object):
ARRAY_TYPES = (list, tuple)
_ARRAY_TYPES = (list, tuple)
_SPEC_FIELD = "_spec"

@classmethod
def attributes(cls):
return [getattr(value.fset, "_spec") for value in cls.__dict__.values() if isinstance(value, property)]
return [getattr(value.fset, cls._SPEC_FIELD) for value in cls.__dict__.values() if isinstance(value, property)]

@classmethod
def from_data(cls, data, strict=False):
Expand All @@ -39,8 +40,8 @@ def from_data(cls, data, strict=False):

@classmethod
def _convert_from_data(cls, attribute, attribute_type, value, strict=False):
if isinstance(attribute_type, cls.ARRAY_TYPES):
if not isinstance(value, cls.ARRAY_TYPES):
if isinstance(attribute_type, cls._ARRAY_TYPES):
if not isinstance(value, cls._ARRAY_TYPES):
raise ValueError(
"Unexpected value type for attribute '{}'. Received {} but expecting [{}]".format(
attribute, value.__class__, attribute_type[0]))
Expand All @@ -66,12 +67,12 @@ def setter(self, value):
def getter(self):
return self.__dict__.get(attribute)

setter._spec = (attribute, clazz, kwargs)
setattr(setter, cls._SPEC_FIELD, (attribute, clazz, kwargs))
return property(getter, setter)

@classmethod
def _validate_class_type(cls, attribute, clazz):
while isinstance(clazz, cls.ARRAY_TYPES):
while isinstance(clazz, cls._ARRAY_TYPES):
if len(clazz) != 1:
raise TypeError("Type definition for arrays must be a list/tuple of size 1")
clazz = clazz[0]
Expand All @@ -81,8 +82,8 @@ def _validate_class_type(cls, attribute, clazz):

@classmethod
def _validate_attribute_value(cls, attribute, clazz, value):
if isinstance(clazz, cls.ARRAY_TYPES):
if not isinstance(value, cls.ARRAY_TYPES):
if isinstance(clazz, cls._ARRAY_TYPES):
if not isinstance(value, cls._ARRAY_TYPES):
raise TypeError("Expecting a {} type for '{}' attribute".format(clazz, attribute))
for v in value:
cls._validate_attribute_value(attribute + "[...]", clazz[0], v)
Expand All @@ -93,7 +94,7 @@ def _validate_attribute_value(cls, attribute, clazz, value):
def _convert_to_data(cls, value):
if isinstance(value, DataStruct):
value = {k: cls._convert_to_data(v) for k, v in value.__dict__.items()}
elif isinstance(value, cls.ARRAY_TYPES):
elif isinstance(value, cls._ARRAY_TYPES):
value = [cls._convert_to_data(v) for v in value]
return value

Expand Down
6 changes: 3 additions & 3 deletions lib/subtitles.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,13 @@ def search(self, languages, search_string=None, preferred_language=None):
tv_show_title = normalize_string(xbmc.getInfoLabel("VideoPlayer.TVshowtitle"))
imdb_number = xbmc.getInfoLabel("VideoPlayer.IMDBNumber")
if tv_show_title:
# Assuming its a tv show
# Assuming it's a tv show
payload.query = tv_show_title
season = xbmc.getInfoLabel("VideoPlayer.Season")
episode = xbmc.getInfoLabel("VideoPlayer.Episode")
if episode and season:
payload.season = season
payload.episode = episode
payload.season = int(season)
payload.episode = int(episode)
if imdb_number and imdb_number[2:].isdigit():
payload.imdb_id = int(imdb_number[2:])
else:
Expand Down

0 comments on commit 546b2af

Please sign in to comment.