From 55d96b3231ba78e2a5c0ae8a7df103b53f42b6c5 Mon Sep 17 00:00:00 2001 From: Thomas Anderson Date: Tue, 18 Jun 2024 05:44:13 -0400 Subject: [PATCH 1/3] Fixed usage of path mappings for video_analyzer operations --- bazarr/utilities/video_analyzer.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/bazarr/utilities/video_analyzer.py b/bazarr/utilities/video_analyzer.py index a1ccf319f..bfa75542e 100644 --- a/bazarr/utilities/video_analyzer.py +++ b/bazarr/utilities/video_analyzer.py @@ -121,7 +121,9 @@ def subtitles_sync_references(subtitles_path, sonarr_episode_id=None, radarr_mov if not media_data: return references_dict - data = parse_video_metadata(media_data.path, media_data.file_size, media_data.episode_file_id, None, + mapped_path = path_mappings.path_replace(media_data.path) + + data = parse_video_metadata(mapped_path, media_data.file_size, media_data.episode_file_id, None, use_cache=True) elif radarr_movie_id: media_data = database.execute( @@ -132,7 +134,9 @@ def subtitles_sync_references(subtitles_path, sonarr_episode_id=None, radarr_mov if not media_data: return references_dict - data = parse_video_metadata(media_data.path, media_data.file_size, None, media_data.movie_file_id, + mapped_path = path_mappings.path_replace_movie(media_data.path) + + data = parse_video_metadata(mapped_path, media_data.file_size, None, media_data.movie_file_id, use_cache=True) if not data: From 9a52b3c539b3f32841f45177a949b001c51abf39 Mon Sep 17 00:00:00 2001 From: modem <62859+modem@users.noreply.github.com> Date: Tue, 18 Jun 2024 10:50:34 +0100 Subject: [PATCH 2/3] Fixed legendasdivx provider while searching for movies subtitles --- custom_libs/subliminal_patch/providers/legendasdivx.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/custom_libs/subliminal_patch/providers/legendasdivx.py b/custom_libs/subliminal_patch/providers/legendasdivx.py index 2b04dc373..e4d839ed2 100644 --- a/custom_libs/subliminal_patch/providers/legendasdivx.py +++ b/custom_libs/subliminal_patch/providers/legendasdivx.py @@ -325,9 +325,9 @@ class LegendasdivxProvider(Provider): search_url = _searchurl.format( query=querytext, - season=video.season, - episode=video.episode, - imdbid=video.series_imdb_id.replace('tt', '') if video.series_imdb_id else None, + season='' if isinstance(video, Movie) else video.season, + episode='' if isinstance(video, Movie) else video.episode, + imdbid='' if isinstance(video, Movie) else video.series_imdb_id.replace('tt', '') if video.series_imdb_id else None, op=op, d_op=d_op, ) From 4430ec8f3ebadeacb199843370c3a107d6409f8a Mon Sep 17 00:00:00 2001 From: Vitiko Date: Tue, 18 Jun 2024 17:44:12 -0400 Subject: [PATCH 3/3] Subtitle class: get format dinamically (fix #2514) --- custom_libs/subliminal_patch/subtitle.py | 29 +++++++++++++++---- .../test_embeddedsubtitles.py | 27 ++++++++++++++--- 2 files changed, 46 insertions(+), 10 deletions(-) diff --git a/custom_libs/subliminal_patch/subtitle.py b/custom_libs/subliminal_patch/subtitle.py index d0cd585ed..36afea6d2 100644 --- a/custom_libs/subliminal_patch/subtitle.py +++ b/custom_libs/subliminal_patch/subtitle.py @@ -62,7 +62,7 @@ class Subtitle(Subtitle_): _guessed_encoding = None _is_valid = False use_original_format = False - format = "srt" # default format is srt + # format = "srt" # default format is srt def __init__(self, language, hearing_impaired=False, page_link=None, encoding=None, mods=None, original_format=False): # set subtitle language to hi if it's hearing_impaired @@ -74,6 +74,21 @@ class Subtitle(Subtitle_): self.mods = mods self._is_valid = False self.use_original_format = original_format + self._og_format = None + + @property + def format(self): + if self.use_original_format and self._og_format is not None: + logger.debug("Original format requested [%s]", self._og_format) + return self._og_format + + logger.debug("Will assume srt format") + return "srt" + + # Compatibility + @format.setter + def format(self, val): + self._og_format = val def __repr__(self): r_info = str(self.release_info or "").replace("\n", " | ").strip() @@ -292,11 +307,13 @@ class Subtitle(Subtitle_): logger.info("Got FPS from MicroDVD subtitle: %s", subs.fps) else: logger.info("Got format: %s", subs.format) - if self.use_original_format: - self.format = subs.format - self._is_valid = True - logger.debug("Using original format") - return True + 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 diff --git a/tests/subliminal_patch/test_embeddedsubtitles.py b/tests/subliminal_patch/test_embeddedsubtitles.py index d7f157de1..b7bfaa0a8 100644 --- a/tests/subliminal_patch/test_embeddedsubtitles.py +++ b/tests/subliminal_patch/test_embeddedsubtitles.py @@ -8,9 +8,9 @@ from fese.exceptions import LanguageNotFound import pytest from subliminal_patch.core import Episode from subliminal_patch.core import Movie +from subliminal_patch.providers.embeddedsubtitles import _clean_ass_subtitles from subliminal_patch.providers.embeddedsubtitles import ( _discard_possible_incomplete_subtitles, - _clean_ass_subtitles, ) from subliminal_patch.providers.embeddedsubtitles import _get_pretty_release_name from subliminal_patch.providers.embeddedsubtitles import _MemoizedFFprobeVideoContainer @@ -127,7 +127,9 @@ def fake_streams(): @pytest.mark.parametrize("tags_", [{}, {"language": "und", "title": "Unknown"}]) def test_list_subtitles_unknown_as_fallback(mocker, tags_, video_single_language): - with EmbeddedSubtitlesProvider(unknown_as_fallback=True, fallback_lang="en") as provider: + with EmbeddedSubtitlesProvider( + unknown_as_fallback=True, fallback_lang="en" + ) as provider: fake = FFprobeSubtitleStream( {"index": 3, "codec_name": "subrip", "tags": tags_} ) @@ -144,7 +146,9 @@ def test_list_subtitles_unknown_as_fallback(mocker, tags_, video_single_language def test_list_subtitles_unknown_as_fallback_w_real_english_subtitles( video_single_language, mocker ): - with EmbeddedSubtitlesProvider(unknown_as_fallback=True, fallback_lang="en") as provider: + with EmbeddedSubtitlesProvider( + unknown_as_fallback=True, fallback_lang="en" + ) as provider: fakes = [ FFprobeSubtitleStream( {"index": 3, "codec_name": "subrip", "tags": {"language": "und"}} @@ -165,7 +169,7 @@ def test_list_subtitles_unknown_as_fallback_w_real_english_subtitles( @pytest.mark.parametrize("tags_", [{}, {"language": "und", "title": "Unknown"}]) def test_list_subtitles_unknown_as_fallback_disabled(tags_): - with EmbeddedSubtitlesProvider(unknown_as_fallback=False,fallback_lang="en"): + with EmbeddedSubtitlesProvider(unknown_as_fallback=False, fallback_lang="en"): with pytest.raises(LanguageNotFound): assert FFprobeSubtitleStream( {"index": 3, "codec_name": "subrip", "tags": tags_} @@ -362,6 +366,21 @@ def test_download_subtitle_single(video_single_language): assert subtitle.is_valid() +def test_download_subtitle_single_is_ass(video_single_language): + with EmbeddedSubtitlesProvider() as provider: + subtitle = provider.list_subtitles( + video_single_language, {Language.fromalpha2("en")} + )[0] + provider.download_subtitle(subtitle) + assert subtitle.is_valid() + + assert subtitle.format == "srt" + + subtitle.use_original_format = True + + assert subtitle.format == "ass" + + def test_memoized(video_single_language, mocker): with EmbeddedSubtitlesProvider() as provider: provider.list_subtitles(video_single_language, {Language.fromalpha2("en")})