diff --git a/sabnzbd/sorting.py b/sabnzbd/sorting.py index b1e156d..5afda8e 100644 --- a/sabnzbd/sorting.py +++ b/sabnzbd/sorting.py @@ -41,7 +41,6 @@ import sabnzbd.cfg as cfg from sabnzbd.constants import EXCLUDED_GUESSIT_PROPERTIES from sabnzbd.nzbstuff import NzbObject, scan_password - # Do not rename .vob files as they are usually DVD's EXCLUDED_FILE_EXTS = (".vob", ".bin") @@ -92,6 +91,10 @@ class BaseSorter: """Implemented by child classes""" pass + def get_values(self): + """Implemented by child classes""" + pass + def get_final_path(self) -> str: if self.matched: # Construct the final path @@ -335,10 +338,6 @@ class Sorter: return self.sorter.get_final_path() if self.sort_file else complete_dir - def rename(self, newfiles: List[str], workdir_complete: str) -> Tuple[str, bool]: - """Rename files of the job""" - return self.sorter.rename(newfiles, workdir_complete) - class SeriesSorter(BaseSorter): """Methods for Series Sorting""" @@ -357,19 +356,12 @@ class SeriesSorter(BaseSorter): def match(self): """Try to guess series info if config and category sort out or force is set""" - if self.force or (cfg.enable_tv_sorting() and cfg.tv_sort_string()): - if ( - self.force - or (not self.cats) - or (self.cat and self.cat.lower() in self.cats) - or (not self.cat and "None" in self.cats) - ): - if not self.guess: - self.guess = guess_what(self.original_job_name, sort_type="episode") - if self.guess.get("type") == "episode" and not "date" in self.guess: - logging.debug("Using tv sorter for %s", self.original_job_name) - self.matched = True - self.type = "tv" + if self.force or (cfg.enable_tv_sorting() and cfg.tv_sort_string() and self.cat.lower() in self.cats): + self.guess = guess_what(self.original_job_name, sort_type="episode") + if self.guess.get("type") == "episode" and "date" not in self.guess: + logging.debug("Using tv sorter for %s", self.original_job_name) + self.matched = True + self.type = "tv" def get_values(self): """Collect all values needed for path replacement""" @@ -427,14 +419,12 @@ class MovieSorter(BaseSorter): def match(self): """Try to guess movie info if config and category sort out or force is set""" - if self.force or (cfg.enable_movie_sorting() and self.sort_string): - if self.force or (self.cat and self.cat.lower() in self.cats) or (not self.cat and "None" in self.cats): - if not self.guess: - self.guess = guess_what(self.original_job_name, sort_type="movie") - if self.guess.get("type") == "movie": - logging.debug("Using movie sorter for %s", self.original_job_name) - self.matched = True - self.type = "movie" + if self.force or (cfg.enable_movie_sorting() and self.sort_string and self.cat.lower() in self.cats): + self.guess = guess_what(self.original_job_name, sort_type="movie") + if self.guess.get("type") == "movie": + logging.debug("Using movie sorter for %s", self.original_job_name) + self.matched = True + self.type = "movie" def get_values(self): """Collect all values needed for path replacement""" @@ -509,14 +499,12 @@ class DateSorter(BaseSorter): def match(self): """Checks the category for a match, if so set self.matched to true""" - if self.force or (cfg.enable_date_sorting() and self.sort_string): - if self.force or (self.cat and self.cat.lower() in self.cats) or (not self.cat and "None" in self.cats): - if not self.guess: - self.guess = guess_what(self.original_job_name, sort_type="episode") - if self.guess.get("type") == "episode" and "date" in self.guess: - logging.debug("Using date sorter for %s", self.original_job_name) - self.matched = True - self.type = "date" + if self.force or (cfg.enable_date_sorting() and self.sort_string and self.cat.lower() in self.cats): + self.guess = guess_what(self.original_job_name, sort_type="episode") + if self.guess.get("type") == "episode" and "date" in self.guess: + logging.debug("Using date sorter for %s", self.original_job_name) + self.matched = True + self.type = "date" def get_date(self): """Get month and day""" @@ -607,7 +595,7 @@ def guess_what(name: str, sort_type: Optional[str] = None) -> MatchesDict: guess["title"] = guess.get("title", "")[len(digit_fix) :] # Force season to 1 for seasonless episodes with no date - if guess.get("type") == "episode" and not "date" in guess: + if guess.get("type") == "episode" and "date" not in guess: guess.setdefault("season", 1) # Try to avoid setting the type to movie on arbitrary jobs (e.g. 'Setup.exe') just because guessit defaults to that diff --git a/tests/test_sorting.py b/tests/test_sorting.py index e8ff5ba..a249c04 100644 --- a/tests/test_sorting.py +++ b/tests/test_sorting.py @@ -681,15 +681,32 @@ class TestSortingSorters: ) def test_sorter_generic(self, job_name, result_sort_file, result_class): """Check if the generic sorter makes the right choices""" - generic = sorting.Sorter(None, None) - generic.detect(job_name, SAB_CACHE_DIR) - assert generic.sort_file is result_sort_file - if result_sort_file: - assert generic.sorter - assert generic.sorter.__class__ is result_class - else: - assert not generic.sorter + @set_config( + { + "tv_sort_string": "test", # TV + "tv_categories": "test_cat", + "enable_tv_sorting": 1, + "movie_sort_string": "test", # Movie + "movie_categories": "test_cat", + "enable_movie_sorting": 1, + "date_sort_string": "test", # Date + "date_categories": "test_cat", + "enable_date_sorting": 1, + } + ) + def _func(): + generic = sorting.Sorter(None, "test_cat") + generic.detect(job_name, SAB_CACHE_DIR) + + assert generic.sort_file is result_sort_file + if result_sort_file: + assert generic.sorter + assert generic.sorter.__class__ is result_class + else: + assert not generic.sorter + + _func() @pytest.mark.parametrize( "name, result",