Fixed -RP release issues.

Removes .nzb and .torrent extensions from files for parsing purposes.
This commit is contained in:
echel0n 2014-07-19 15:23:01 -07:00
parent 423c09fd9e
commit 02c8b867c6
5 changed files with 43 additions and 20 deletions

View file

@ -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):
'''

View file

@ -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

View file

@ -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)

View file

@ -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:

View file

@ -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)