1
0
mirror of https://github.com/moparisthebest/SickRage synced 2024-12-12 11:02:21 -05:00

"Borrowed" code from SB's post-processing routine.

This commit is contained in:
echel0n 2014-07-19 16:08:50 -07:00
parent 1b84c6d281
commit 24cd235988

View File

@ -44,6 +44,7 @@ from sickbeard.name_parser.parser import NameParser, InvalidNameException, Inval
from lib import adba from lib import adba
class PostProcessor(object): class PostProcessor(object):
""" """
A class which will process a media file according to the post processing settings in the config. A class which will process a media file according to the post processing settings in the config.
@ -56,10 +57,6 @@ class PostProcessor(object):
IGNORED_FILESTRINGS = ["/.AppleDouble/", ".DS_Store"] IGNORED_FILESTRINGS = ["/.AppleDouble/", ".DS_Store"]
NZB_NAME = 1
FOLDER_NAME = 2
FILE_NAME = 3
def __init__(self, file_path, nzb_name=None, process_method=None, is_priority=None): def __init__(self, file_path, nzb_name=None, process_method=None, is_priority=None):
""" """
Creates a new post processor with the given file path and optionally an NZB name. Creates a new post processor with the given file path and optionally an NZB name.
@ -85,19 +82,17 @@ class PostProcessor(object):
self.process_method = process_method if process_method else sickbeard.PROCESS_METHOD self.process_method = process_method if process_method else sickbeard.PROCESS_METHOD
self.in_history = False self.in_history = False
self.release_group = None self.release_group = None
self.release_name = None
self.is_proper = False self.is_proper = False
self.is_priority = is_priority self.is_priority = is_priority
self.good_results = {self.NZB_NAME: False,
self.FOLDER_NAME: False,
self.FILE_NAME: False}
self.log = '' self.log = ''
def __del__(self):
pass
def _log(self, message, level=logger.MESSAGE): def _log(self, message, level=logger.MESSAGE):
""" """
A wrapper for the internal logger which also keeps track of messages and saves them to a string for later. A wrapper for the internal logger which also keeps track of messages and saves them to a string for later.
@ -442,25 +437,21 @@ class PostProcessor(object):
self.is_proper = re.search('(^|[\. _-])(proper|repack)([\. _-]|$)', parse_result.extra_info, re.I) != None self.is_proper = re.search('(^|[\. _-])(proper|repack)([\. _-]|$)', parse_result.extra_info, re.I) != None
# if the result is complete then remember that for later # 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: # if the result is complete then set release name
test_name = helpers.remove_extension(ek.ek(os.path.basename, parse_result.original_name)) if parse_result.series_name and ((parse_result.season_number is not None and parse_result.episode_numbers)
or parse_result.air_date) and parse_result.release_group:
if not self.release_name:
self.release_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:
self.good_results[self.FOLDER_NAME] = True
elif test_name == self.file_name:
self.good_results[self.FILE_NAME] = True
else: else:
logger.log(u"Nothing was good, found " + repr(test_name) + " and wanted either " + repr( logger.log(u"Parse result not sufficient (all following have to be set). will not save release name",
self.nzb_name) + ", " + repr(self.folder_name) + ", or " + repr(self.file_name))
else:
logger.log(u"Parse result not sufficient(all following have to be set). Will not save release name",
logger.DEBUG) logger.DEBUG)
logger.log("Parse result(series_name): " + str(parse_result.series_name), logger.DEBUG) logger.log(u"Parse result(series_name): " + str(parse_result.series_name), logger.DEBUG)
logger.log("Parse result(season_number): " + str(parse_result.season_number), logger.DEBUG) logger.log(u"Parse result(season_number): " + str(parse_result.season_number), logger.DEBUG)
logger.log("Parse result(episode_numbers): " + str(parse_result.episode_numbers), logger.DEBUG) logger.log(u"Parse result(episode_numbers): " + str(parse_result.episode_numbers), logger.DEBUG)
logger.log("Parse result(release_group): " + str(parse_result.release_group), logger.DEBUG) logger.log(u" or Parse result(air_date): " + str(parse_result.air_date), logger.DEBUG)
logger.log(u"Parse result(release_group): " + str(parse_result.release_group), logger.DEBUG)
def _analyze_name(self, name, file=True): def _analyze_name(self, name, file=True):
""" """
@ -621,11 +612,13 @@ class PostProcessor(object):
# for air-by-date shows we need to look up the season/episode from database # for air-by-date shows we need to look up the season/episode from database
if season == -1 and show and episodes: if season == -1 and show and episodes:
self._log(u"Looks like this is an air-by-date or sports show, attempting to convert the date to season/episode", self._log(
u"Looks like this is an air-by-date or sports show, attempting to convert the date to season/episode",
logger.DEBUG) logger.DEBUG)
airdate = episodes[0].toordinal() airdate = episodes[0].toordinal()
myDB = db.DBConnection() myDB = db.DBConnection()
sql_result = myDB.select("SELECT season, episode FROM tv_episodes WHERE showid = ? and indexer = ? and airdate = ?", sql_result = myDB.select(
"SELECT season, episode FROM tv_episodes WHERE showid = ? and indexer = ? and airdate = ?",
[show.indexerid, show.indexer, airdate]) [show.indexerid, show.indexer, airdate])
if sql_result: if sql_result:
@ -733,7 +726,9 @@ class PostProcessor(object):
if ep_obj.status in common.Quality.SNATCHED + common.Quality.SNATCHED_PROPER: if ep_obj.status in common.Quality.SNATCHED + common.Quality.SNATCHED_PROPER:
oldStatus, ep_quality = common.Quality.splitCompositeStatus(ep_obj.status) # @UnusedVariable oldStatus, ep_quality = common.Quality.splitCompositeStatus(ep_obj.status) # @UnusedVariable
if ep_quality != common.Quality.UNKNOWN: if ep_quality != common.Quality.UNKNOWN:
self._log(u"The old status had a quality in it, using that: " + common.Quality.qualityStrings[ep_quality], logger.DEBUG) self._log(
u"The old status had a quality in it, using that: " + common.Quality.qualityStrings[ep_quality],
logger.DEBUG)
return ep_quality return ep_quality
# Try guessing quality from the file name # Try guessing quality from the file name
@ -853,7 +848,8 @@ class PostProcessor(object):
# get the quality of the episode we're processing # get the quality of the episode we're processing
if quality: if quality:
self._log(u"Snatch history had a quality in it, using that: " + common.Quality.qualityStrings[quality], logger.DEBUG) self._log(u"Snatch history had a quality in it, using that: " + common.Quality.qualityStrings[quality],
logger.DEBUG)
new_ep_quality = quality new_ep_quality = quality
else: else:
new_ep_quality = self._get_quality(ep_obj) new_ep_quality = self._get_quality(ep_obj)
@ -873,7 +869,9 @@ class PostProcessor(object):
# if there's an existing file that we don't want to replace stop here # if there's an existing file that we don't want to replace stop here
if existing_file_status == PostProcessor.EXISTS_LARGER: if existing_file_status == PostProcessor.EXISTS_LARGER:
if self.is_proper: if self.is_proper:
self._log(u"File exists and new file is smaller, new file is a proper/repack, marking it safe to replace", logger.DEBUG) self._log(
u"File exists and new file is smaller, new file is a proper/repack, marking it safe to replace",
logger.DEBUG)
return True return True
else: else:
@ -922,21 +920,12 @@ class PostProcessor(object):
sql_l = [] sql_l = []
for cur_ep in [ep_obj] + ep_obj.relatedEps: for cur_ep in [ep_obj] + ep_obj.relatedEps:
with cur_ep.lock: with cur_ep.lock:
cur_release_name = None
# use the best possible representation of the release name if self.release_name:
if self.good_results[self.NZB_NAME]: self._log("Found release name " + self.release_name, logger.DEBUG)
cur_release_name = self.nzb_name cur_ep.release_name = self.release_name
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
if cur_release_name:
self._log("Found release name " + cur_release_name, logger.DEBUG)
cur_ep.release_name = cur_release_name
else: else:
logger.log("good results: " + repr(self.good_results), logger.DEBUG) cur_ep.release_name = ""
if ep_obj.status in common.Quality.SNATCHED_BEST: if ep_obj.status in common.Quality.SNATCHED_BEST:
cur_ep.status = common.Quality.compositeStatus(common.ARCHIVED, new_ep_quality) cur_ep.status = common.Quality.compositeStatus(common.ARCHIVED, new_ep_quality)