From 09d1eb78c95d2a1bee85f8e17cd9877149e26afb Mon Sep 17 00:00:00 2001 From: vitiko98 Date: Mon, 29 Aug 2022 20:50:50 -0400 Subject: [PATCH] Avoid error trying to scan some videos This removes unused code from subliminal_patch's core. Thanks to refining, we don't need extra magic to guess from filenames anymore. --- libs/subliminal_patch/core.py | 32 ++--------------------------- tests/subliminal_patch/test_core.py | 19 +++++++++++++++++ 2 files changed, 21 insertions(+), 30 deletions(-) create mode 100644 tests/subliminal_patch/test_core.py diff --git a/libs/subliminal_patch/core.py b/libs/subliminal_patch/core.py index d8c327f46..88b16db1f 100644 --- a/libs/subliminal_patch/core.py +++ b/libs/subliminal_patch/core.py @@ -739,7 +739,6 @@ def scan_video(path, dont_use_actual_file=False, hints=None, providers=None, ski """ hints = hints or {} - video_type = hints.get("type") # check for non-existing path if not dont_use_actual_file and not os.path.exists(path): @@ -752,42 +751,15 @@ def scan_video(path, dont_use_actual_file=False, hints=None, providers=None, ski dirpath, filename = os.path.split(path) logger.info('Determining basic video properties for %r in %r', filename, dirpath) - # hint guessit the filename itself and its 2 parent directories if we're an episode (most likely - # Series name/Season/filename), else only one - split_path = os.path.normpath(path).split(os.path.sep)[-3 if video_type == "episode" else -2:] - - # remove crap from folder names - if video_type == "episode": - if len(split_path) > 2: - split_path[-3] = remove_crap_from_fn(split_path[-3]) - else: - if len(split_path) > 1: - split_path[-2] = remove_crap_from_fn(split_path[-2]) - - guess_from = os.path.join(*split_path) - - # remove crap from file name - guess_from = remove_crap_from_fn(guess_from) - - # guess hints["single_value"] = True # if "title" in hints: # hints["expected_title"] = [hints["title"]] - guessed_result = guessit(guess_from, options=hints) + guessed_result = guessit(path, options=hints) logger.debug('GuessIt found: %s', json.dumps(guessed_result, cls=GuessitEncoder, indent=4, ensure_ascii=False)) video = Video.fromguess(path, guessed_result) - video.hints = hints - - # get possibly alternative title from the filename itself - alt_guess = guessit(filename, options=hints) - if "title" in alt_guess and alt_guess["title"] != guessed_result["title"]: - if video_type == "episode": - video.alternative_series.append(alt_guess["title"]) - else: - video.alternative_titles.append(alt_guess["title"]) - logger.debug("Adding alternative title: %s", alt_guess["title"]) + video.hints = hints # ? if dont_use_actual_file and not hash_from: return video diff --git a/tests/subliminal_patch/test_core.py b/tests/subliminal_patch/test_core.py new file mode 100644 index 000000000..17451ccdf --- /dev/null +++ b/tests/subliminal_patch/test_core.py @@ -0,0 +1,19 @@ +from pathlib import Path + +from subliminal_patch import core + + +def test_scan_video_movie(tmpdir): + video_path = Path(tmpdir, "Taxi Driver 1976 Bluray 720p x264.mkv") + video_path.touch() + + result = core.scan_video(str(video_path)) + assert isinstance(result, core.Movie) + + +def test_scan_video_episode(tmpdir): + video_path = Path(tmpdir, "The Wire S01E01 Bluray 720p x264.mkv") + video_path.touch() + + result = core.scan_video(str(video_path)) + assert isinstance(result, core.Episode)