|
|
|
@ -98,17 +98,19 @@ class LegendasTVProvider(_LegendasTVProvider):
|
|
|
|
|
return _LegendasTVProvider.is_valid_title(title, title_id, sanitized_title, season, year)
|
|
|
|
|
|
|
|
|
|
@region.cache_on_arguments(expiration_time=SHOW_EXPIRATION_TIME, should_cache_fn=lambda value: value)
|
|
|
|
|
def search_titles(self, title, season, title_year, imdb_id):
|
|
|
|
|
def search_titles(self, titles, season, title_year, imdb_id):
|
|
|
|
|
"""Search for titles matching the `title`.
|
|
|
|
|
|
|
|
|
|
For episodes, each season has it own title
|
|
|
|
|
:param str title: the title to search for.
|
|
|
|
|
:param str titles: the titles to search for.
|
|
|
|
|
:param int season: season of the title
|
|
|
|
|
:param int title_year: year of the title
|
|
|
|
|
:return: found titles.
|
|
|
|
|
:rtype: dict
|
|
|
|
|
"""
|
|
|
|
|
titles = {}
|
|
|
|
|
titles_found = {}
|
|
|
|
|
|
|
|
|
|
for title in titles:
|
|
|
|
|
sanitized_titles = [sanitize(title)]
|
|
|
|
|
ignore_characters = {'\'', '.'}
|
|
|
|
|
if any(c in title for c in ignore_characters):
|
|
|
|
@ -172,19 +174,19 @@ class LegendasTVProvider(_LegendasTVProvider):
|
|
|
|
|
# Check against title without ignored chars
|
|
|
|
|
if self.is_valid_title(title, title_id, sanitized_titles[0], season, title_year, imdb_id):
|
|
|
|
|
logger.debug(u'Found title: %s', title)
|
|
|
|
|
titles[title_id] = title
|
|
|
|
|
titles_found[title_id] = title
|
|
|
|
|
|
|
|
|
|
logger.debug('Found %d titles', len(titles))
|
|
|
|
|
logger.debug('Found %d titles', len(titles_found))
|
|
|
|
|
|
|
|
|
|
return titles
|
|
|
|
|
return titles_found
|
|
|
|
|
|
|
|
|
|
def query(self, language, title, season=None, episode=None, year=None, imdb_id=None):
|
|
|
|
|
def query(self, language, titles, season=None, episode=None, year=None, imdb_id=None):
|
|
|
|
|
# search for titles
|
|
|
|
|
titles = self.search_titles(title, season, year, imdb_id)
|
|
|
|
|
titles_found = self.search_titles(titles, season, year, imdb_id)
|
|
|
|
|
|
|
|
|
|
subtitles = []
|
|
|
|
|
# iterate over titles
|
|
|
|
|
for title_id, t in titles.items():
|
|
|
|
|
for title_id, t in titles_found.items():
|
|
|
|
|
# Skip episodes or movies if it's not what was requested
|
|
|
|
|
if (season and t['type'] == 'movie') or (not season and t['type'] == 'episode'):
|
|
|
|
|
continue
|
|
|
|
@ -259,12 +261,11 @@ class LegendasTVProvider(_LegendasTVProvider):
|
|
|
|
|
titles = [video.title] + video.alternative_titles
|
|
|
|
|
imdb = video.imdb_id
|
|
|
|
|
|
|
|
|
|
for title in titles:
|
|
|
|
|
subtitles = [s for l in languages for s in
|
|
|
|
|
self.query(l, title, season=season, episode=episode, year=video.year, imdb_id=imdb)]
|
|
|
|
|
self.query(l, titles, season=season, episode=episode, year=video.year, imdb_id=imdb)]
|
|
|
|
|
if subtitles:
|
|
|
|
|
return subtitles
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
return []
|
|
|
|
|
|
|
|
|
|
def download_subtitle(self, subtitle):
|
|
|
|
|