1
0
Fork 0
mirror of https://github.com/morpheus65535/bazarr synced 2024-12-26 09:37:25 +00:00

Betaseries: Use release group to choose which subtitle to download in archive

This commit is contained in:
Mexx62 2019-12-21 22:56:45 +01:00
parent 8d9023af80
commit 3b360db1c0

View file

@ -75,6 +75,7 @@ class BetaSeriesProvider(Provider):
def query(self, languages, video): def query(self, languages, video):
# query the server # query the server
result = None result = None
self.video = video
matches = set() matches = set()
if video.tvdb_id: if video.tvdb_id:
params = {'key': self.token, params = {'key': self.token,
@ -137,8 +138,13 @@ class BetaSeriesProvider(Provider):
r.raise_for_status() r.raise_for_status()
archive = _get_archive(r.content) archive = _get_archive(r.content)
subtitle_content = _get_subtitle_from_archive( if archive:
archive) if archive else r.content subtitle_names = _get_subtitle_names_from_archive(archive)
subtitle_to_download = _choose_subtitle_with_release_group(subtitle_names, self.video.release_group)
logger.debug('Subtitle to download: ' + subtitle_to_download)
subtitle_content = archive.read(subtitle_to_download)
else:
subtitle_content = r.content
if subtitle_content: if subtitle_content:
subtitle.content = fix_line_ending(subtitle_content) subtitle.content = fix_line_ending(subtitle_content)
@ -160,7 +166,8 @@ def _get_archive(content):
return archive return archive
def _get_subtitle_from_archive(archive): def _get_subtitle_names_from_archive(archive):
subtitlesToConsider = []
for name in archive.namelist(): for name in archive.namelist():
# discard hidden files # discard hidden files
if os.path.split(name)[-1].startswith('.'): if os.path.split(name)[-1].startswith('.'):
@ -170,8 +177,12 @@ def _get_subtitle_from_archive(archive):
if not name.lower().endswith(SUBTITLE_EXTENSIONS): if not name.lower().endswith(SUBTITLE_EXTENSIONS):
continue continue
return archive.read(name) subtitlesToConsider.append(name)
if len(subtitlesToConsider)>0:
logger.debug('Subtitles in archive: ' + ' '.join(subtitlesToConsider))
return subtitlesToConsider
else:
return None return None
@ -180,3 +191,11 @@ def _translateLanguageCodeToLanguage(languageCode):
return Language.fromalpha2('en') return Language.fromalpha2('en')
elif languageCode.lower() == 'vf': elif languageCode.lower() == 'vf':
return Language.fromalpha2('fr') return Language.fromalpha2('fr')
def _choose_subtitle_with_release_group(subtitle_names, release_group):
if release_group:
for subtitle in subtitle_names:
if release_group in subtitle:
return subtitle
return subtitle_names[0]