Fixed subtitles conversion when use original format is enabled and prevented hearing-impaired detection for non srt format subtitles. #2693

pull/2717/head
morpheus65535 3 months ago committed by GitHub
parent f50bcf34ac
commit 43563cdcbd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -13,7 +13,7 @@ from subliminal_patch.core_persistent import download_best_subtitles
from subliminal_patch.score import ComputeScore
from app.config import settings, get_scores, get_array_from
from app.database import TableEpisodes, TableMovies, database, select
from app.database import TableEpisodes, TableMovies, database, select, get_profiles_list
from utilities.path_mappings import path_mappings
from utilities.helper import get_target_folder, force_unicode
from languages.get_languages import alpha3_from_alpha2
@ -24,8 +24,8 @@ from .processing import process_subtitle
@update_pools
def generate_subtitles(path, languages, audio_language, sceneName, title, media_type, forced_minimum_score=None,
is_upgrade=False, profile_id=None, check_if_still_required=False,
def generate_subtitles(path, languages, audio_language, sceneName, title, media_type, profile_id,
forced_minimum_score=None, is_upgrade=False, check_if_still_required=False,
previous_subtitles_to_delete=None):
if not languages:
return None
@ -41,6 +41,8 @@ def generate_subtitles(path, languages, audio_language, sceneName, title, media_
providers = pool.providers
language_set = _get_language_obj(languages=languages)
profile = get_profiles_list(profile_id=profile_id)
original_format = profile['originalFormat']
hi_required = "force HI" if any([x.hi for x in language_set]) else False
also_forced = any([x.forced for x in language_set])
forced_required = all([x.forced for x in language_set])
@ -72,7 +74,8 @@ def generate_subtitles(path, languages, audio_language, sceneName, title, media_
pool_instance=pool,
min_score=int(min_score),
hearing_impaired=hi_required,
compute_score=ComputeScore(get_scores()))
compute_score=ComputeScore(get_scores()),
use_original_format=original_format in (1, "1", "True", True))
if downloaded_subtitles:
for video, subtitles in downloaded_subtitles.items():
@ -100,7 +103,7 @@ def generate_subtitles(path, languages, audio_language, sceneName, title, media_
tags=None, # fixme
directory=fld,
chmod=chmod,
formats=tuple(subtitle_formats),
formats=subtitle_formats,
path_decoder=force_unicode
)
except Exception as e:

@ -135,7 +135,9 @@ def guess_external_subtitles(dest_folder, subtitles, media_type, previously_inde
continue
text = text.decode(encoding)
if core.parse_for_hi_regex(subtitle_text=text,
alpha3_language=language.alpha3 if hasattr(language, 'alpha3') else None):
subtitles[subtitle] = Language.rebuild(subtitles[subtitle], forced=False, hi=True)
if os.path.splitext(subtitle_path)[1] == 'srt':
if core.parse_for_hi_regex(subtitle_text=text,
alpha3_language=language.alpha3 if hasattr(language, 'alpha3') else
None):
subtitles[subtitle] = Language.rebuild(subtitles[subtitle], forced=False, hi=True)
return subtitles

@ -158,7 +158,7 @@ def manual_download_subtitle(path, audio_language, hi, forced, subtitle, provide
subtitle.language.forced = True
else:
subtitle.language.forced = False
if use_original_format in ("1", "True"):
if use_original_format in (1, "1", "True", True):
subtitle.use_original_format = True
subtitle.mods = get_array_from(settings.general.subzero_mods)

@ -30,7 +30,8 @@ def movies_download_subtitles(no):
TableMovies.sceneName,
TableMovies.title,
TableMovies.tags,
TableMovies.monitored)
TableMovies.monitored,
TableMovies.profileId)
.where(reduce(operator.and_, conditions))) \
.first()
if not movie:
@ -79,6 +80,7 @@ def movies_download_subtitles(no):
str(movie.sceneName),
movie.title,
'movie',
movie.profileId,
check_if_still_required=True):
if result:

@ -43,7 +43,8 @@ def series_download_subtitles(no):
TableShows.title,
TableEpisodes.season,
TableEpisodes.episode,
TableEpisodes.title.label('episodeTitle'))
TableEpisodes.title.label('episodeTitle'),
TableShows.profileId)
.select_from(TableEpisodes)
.join(TableShows)
.where(reduce(operator.and_, conditions))) \
@ -87,6 +88,7 @@ def series_download_subtitles(no):
str(episode.sceneName),
episode.title,
'series',
episode.profileId,
check_if_still_required=True):
if result:
if isinstance(result, tuple) and len(result):
@ -117,7 +119,8 @@ def episode_download_subtitles(no, send_progress=False):
TableShows.seriesType,
TableEpisodes.title.label('episodeTitle'),
TableEpisodes.season,
TableEpisodes.episode)
TableEpisodes.episode,
TableShows.profileId)
.select_from(TableEpisodes)
.join(TableShows)
.where(reduce(operator.and_, conditions))) \
@ -159,6 +162,7 @@ def episode_download_subtitles(no, send_progress=False):
str(episode.sceneName),
episode.title,
'series',
episode.profileId,
check_if_still_required=True):
if result:
if isinstance(result, tuple) and len(result):

@ -107,6 +107,7 @@ def upgrade_subtitles():
str(episode['sceneName']),
episode['seriesTitle'],
'series',
episode['profileId'],
forced_minimum_score=int(episode['score']),
is_upgrade=True,
previous_subtitles_to_delete=path_mappings.path_replace(
@ -192,6 +193,7 @@ def upgrade_subtitles():
str(movie['sceneName']),
movie['title'],
'movie',
movie['profileId'],
forced_minimum_score=int(movie['score']),
is_upgrade=True,
previous_subtitles_to_delete=path_mappings.path_replace_movie(

@ -50,6 +50,7 @@ def _wanted_movie(movie):
str(movie.sceneName),
movie.title,
'movie',
movie.profileId,
check_if_still_required=True):
if result:
@ -69,7 +70,8 @@ def wanted_download_subtitles_movie(radarr_id):
TableMovies.audio_language,
TableMovies.sceneName,
TableMovies.failedAttempts,
TableMovies.title)
TableMovies.title,
TableMovies.profileId)
.where(TableMovies.radarrId == radarr_id)) \
.all()

@ -51,6 +51,7 @@ def _wanted_episode(episode):
str(episode.sceneName),
episode.title,
'series',
episode.profileId,
check_if_still_required=True):
if result:
if isinstance(result, tuple) and len(result):
@ -71,7 +72,8 @@ def wanted_download_subtitles(sonarr_episode_id):
TableEpisodes.audio_language,
TableEpisodes.sceneName,
TableEpisodes.failedAttempts,
TableShows.title)
TableShows.title,
TableShows.profileId)
.select_from(TableEpisodes)
.join(TableShows)
.where((TableEpisodes.sonarrEpisodeId == sonarr_episode_id))) \

@ -524,7 +524,7 @@ class SZProviderPool(ProviderPool):
return True
def download_best_subtitles(self, subtitles, video, languages, min_score=0, hearing_impaired=False, only_one=False,
compute_score=None):
compute_score=None, use_original_format=False):
"""Download the best matching subtitles.
patch:
@ -543,6 +543,7 @@ class SZProviderPool(ProviderPool):
:param bool only_one: download only one subtitle, not one per language.
:param compute_score: function that takes `subtitle` and `video` as positional arguments,
`hearing_impaired` as keyword argument and returns the score.
:param bool use_original_format: preserve original subtitles format
:return: downloaded subtitles.
:rtype: list of :class:`~subliminal.subtitle.Subtitle`
@ -620,6 +621,9 @@ class SZProviderPool(ProviderPool):
subtitle, score)
continue
# make sure to preserve original subtitles format if requested
subtitle.use_original_format = use_original_format
# download
logger.debug("%r: Trying to download subtitle with matches %s, score: %s; release(s): %s", subtitle,
matches, score, subtitle.release_info)
@ -1213,10 +1217,9 @@ def save_subtitles(file_path, subtitles, single=False, directory=None, chmod=Non
continue
# create subtitle path
if subtitle.text and parse_for_hi_regex(subtitle_text=subtitle.text,
alpha3_language=subtitle.language.alpha3 if
(hasattr(subtitle, 'language') and hasattr(subtitle.language, 'alpha3'))
else None):
if (subtitle.text and subtitle.format == 'srt' and
parse_for_hi_regex(subtitle_text=subtitle.text, alpha3_language=subtitle.language.alpha3 if
(hasattr(subtitle, 'language') and hasattr(subtitle.language, 'alpha3')) else None)):
subtitle.language.hi = True
subtitle_path = get_subtitle_path(file_path, None if single else subtitle.language,
forced_tag=subtitle.language.forced,

@ -50,6 +50,7 @@ def download_best_subtitles(
hearing_impaired=False,
only_one=False,
compute_score=None,
use_original_format=False,
**kwargs
):
downloaded_subtitles = defaultdict(list)
@ -77,6 +78,7 @@ def download_best_subtitles(
hearing_impaired=hearing_impaired,
only_one=only_one,
compute_score=compute_score,
use_original_format=use_original_format,
)
logger.info("Downloaded %d subtitle(s)", len(subtitles))
downloaded_subtitles[video].extend(subtitles)

@ -313,13 +313,10 @@ class Subtitle(Subtitle_):
logger.info("Got FPS from MicroDVD subtitle: %s", subs.fps)
else:
logger.info("Got format: %s", subs.format)
self._og_format = subs.format
self._is_valid = True
# if self.use_original_format:
# self.format = subs.format
# self._is_valid = True
# logger.debug("Using original format")
return True
if self.use_original_format:
self._og_format = subs.format
self._is_valid = True
return True
except pysubs2.UnknownFPSError:
# if parsing failed, use frame rate from provider

Loading…
Cancel
Save