From 02c8b867c654871fe202b9bb0458e46da93594eb Mon Sep 17 00:00:00 2001 From: echel0n Date: Sat, 19 Jul 2014 15:23:01 -0700 Subject: [PATCH] Fixed -RP release issues. Removes .nzb and .torrent extensions from files for parsing purposes. --- sickbeard/helpers.py | 23 +++++++++++++++++++++++ sickbeard/name_parser/parser.py | 10 +++++----- sickbeard/postProcessor.py | 17 +++++++---------- sickbeard/properFinder.py | 3 ++- sickbeard/tv.py | 10 ++++++---- 5 files changed, 43 insertions(+), 20 deletions(-) diff --git a/sickbeard/helpers.py b/sickbeard/helpers.py index 039c7aa1..88560834 100644 --- a/sickbeard/helpers.py +++ b/sickbeard/helpers.py @@ -86,6 +86,29 @@ def indentXML(elem, level=0): if level and (not elem.tail or not elem.tail.strip()): elem.tail = i +def remove_extension(name): + """ + Remove download or media extension from name (if any) + """ + + if name and "." in name: + base_name, sep, extension = name.rpartition('.') # @UnusedVariable + if base_name and extension.lower() in ['nzb', 'torrent'] + mediaExtensions: + name = base_name + + return name + +def remove_non_release_groups(name): + """ + Remove non release groups from name + """ + + if name and "-" in name: + name_group = name.rsplit('-', 1) + if name_group[-1].upper() in ["RP", "NZBGEEK"]: + name = name_group[0] + + return name def replaceExtension(filename, newExt): ''' diff --git a/sickbeard/name_parser/parser.py b/sickbeard/name_parser/parser.py index a2ad1b74..0fedbab7 100644 --- a/sickbeard/name_parser/parser.py +++ b/sickbeard/name_parser/parser.py @@ -26,7 +26,7 @@ import os.path import regexes import sickbeard -from sickbeard import logger, helpers, scene_numbering, common, exceptions, scene_exceptions +from sickbeard import logger, helpers, scene_numbering, common, exceptions, scene_exceptions, encodingKludge as ek from dateutil import parser @@ -329,10 +329,10 @@ class NameParser(object): return cached # break it into parts if there are any (dirname, file name, extension) - dir_name, file_name = os.path.split(name) - ext_match = re.match('(.*)\.\w{3,4}$', file_name) - if ext_match and self.file_name: - base_file_name = ext_match.group(1) + dir_name, file_name = ek.ek(os.path.split, name) + + if self.file_name: + base_file_name = helpers.remove_extension(file_name) else: base_file_name = file_name diff --git a/sickbeard/postProcessor.py b/sickbeard/postProcessor.py index bab606b1..194923ff 100644 --- a/sickbeard/postProcessor.py +++ b/sickbeard/postProcessor.py @@ -74,20 +74,19 @@ class PostProcessor(object): self.file_path = file_path # file name only - self.file_name = ek.ek(os.path.basename, file_path) + self.file_name = helpers.remove_extension(ek.ek(os.path.basename, file_path)) # the name of the folder only - self.folder_name = ek.ek(os.path.basename, self.folder_path) + self.folder_name = helpers.remove_extension(ek.ek(os.path.basename, self.folder_path)) # name of the NZB that resulted in this folder - self.nzb_name = nzb_name + self.nzb_name = helpers.remove_extension(nzb_name) self.process_method = process_method if process_method else sickbeard.PROCESS_METHOD self.in_history = False self.release_group = None self.is_proper = False - self.is_priority = is_priority self.good_results = {self.NZB_NAME: False, @@ -444,7 +443,8 @@ class PostProcessor(object): # if the result is complete then remember that for later if parse_result.series_name and parse_result.season_number != None and parse_result.episode_numbers and parse_result.release_group: - test_name = ek.ek(os.path.basename, parse_result.original_name) + test_name = helpers.remove_extension(ek.ek(os.path.basename, parse_result.original_name)) + if test_name == self.nzb_name: self.good_results[self.NZB_NAME] = True elif test_name == self.folder_name: @@ -479,6 +479,8 @@ class PostProcessor(object): if not name: return to_return + name = helpers.remove_non_release_groups(helpers.remove_extension(name)) + # parse the name to break it into show name, season, and episode np = NameParser(file, useIndexers=True, convert=True) parse_result = np.parse(name) @@ -925,15 +927,10 @@ class PostProcessor(object): # use the best possible representation of the release name if self.good_results[self.NZB_NAME]: cur_release_name = self.nzb_name - if cur_release_name.lower().endswith('.nzb'): - cur_release_name = cur_release_name.rpartition('.')[0] elif self.good_results[self.FOLDER_NAME]: cur_release_name = self.folder_name elif self.good_results[self.FILE_NAME]: cur_release_name = self.file_name - # take the extension off the filename, it's not needed - if '.' in self.file_name: - cur_release_name = self.file_name.rpartition('.')[0] if cur_release_name: self._log("Found release name " + cur_release_name, logger.DEBUG) diff --git a/sickbeard/properFinder.py b/sickbeard/properFinder.py index f4348065..68730cea 100644 --- a/sickbeard/properFinder.py +++ b/sickbeard/properFinder.py @@ -226,10 +226,11 @@ class ProperFinder(): else: # make sure that none of the existing history downloads are the same proper we're trying to download + clean_proper_name = self._genericName(helpers.remove_non_release_groups(curProper.name)) isSame = False for curResult in historyResults: # if the result exists in history already we need to skip it - if self._genericName(curResult["resource"]) == self._genericName(curProper.name): + if self._genericName(helpers.remove_non_release_groups(curResult["resource"])) == clean_proper_name: isSame = True break if isSame: diff --git a/sickbeard/tv.py b/sickbeard/tv.py index b2357fc3..7bf1ced3 100644 --- a/sickbeard/tv.py +++ b/sickbeard/tv.py @@ -2069,13 +2069,15 @@ class TVEpisode(object): return re.sub('[ -]', '_', name) def release_name(name): - if name and name.lower().endswith('.nzb'): - name = name.rpartition('.')[0] + if name: + name = helpers.remove_non_release_groups(helpers.remove_extension(name)) return name def release_group(show, name): - if not name: - return '' + if name: + name = helpers.remove_non_release_groups(helpers.remove_extension(name)) + else: + return "" try: np = NameParser(name, showObj=show, naming_pattern=True)