Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed file extension when automatically searching for a subtitles and use original format is enabled #2711

Merged
merged 4 commits into from
Oct 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions bazarr/subtitles/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@


@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
Expand Down Expand Up @@ -74,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():
Expand All @@ -84,8 +85,6 @@ def generate_subtitles(path, languages, audio_language, sceneName, title, media_
subtitle_formats = set()
for s in subtitles:
s.mods = subz_mods
if original_format in (1, "1", "True", True):
s.use_original_format = True
subtitle_formats.add(s.format)

try:
Expand Down
8 changes: 5 additions & 3 deletions bazarr/subtitles/indexer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion bazarr/subtitles/mass_download/movies.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -79,6 +80,7 @@ def movies_download_subtitles(no):
str(movie.sceneName),
movie.title,
'movie',
movie.profileId,
check_if_still_required=True):

if result:
Expand Down
8 changes: 6 additions & 2 deletions bazarr/subtitles/mass_download/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))) \
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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))) \
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 2 additions & 0 deletions bazarr/subtitles/upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 3 additions & 1 deletion bazarr/subtitles/wanted/movies.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def _wanted_movie(movie):
str(movie.sceneName),
movie.title,
'movie',
movie.profileId,
check_if_still_required=True):

if result:
Expand All @@ -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()

Expand Down
4 changes: 3 additions & 1 deletion bazarr/subtitles/wanted/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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))) \
Expand Down
13 changes: 8 additions & 5 deletions custom_libs/subliminal_patch/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ def download_subtitle(self, subtitle):
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:
Expand All @@ -543,6 +543,7 @@ def download_best_subtitles(self, subtitles, video, languages, min_score=0, hear
: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`

Expand Down Expand Up @@ -620,6 +621,9 @@ def download_best_subtitles(self, subtitles, video, languages, min_score=0, hear
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)
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions custom_libs/subliminal_patch/core_persistent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
15 changes: 8 additions & 7 deletions custom_libs/subliminal_patch/subtitle.py
morpheus65535 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -313,13 +313,14 @@ def is_valid(self):
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
# if self.use_original_format:
# self.format = subs.format
# self._is_valid = True
# logger.debug("Using original format")
return True

except pysubs2.UnknownFPSError:
# if parsing failed, use frame rate from provider
Expand Down