diff --git a/sickbeard/databases/mainDB.py b/sickbeard/databases/mainDB.py index 68464f6936c418534367e9bbda16f5df5ab5cd88..d1bb697ba9862bb3b8854674004929d2469bb0f9 100644 --- a/sickbeard/databases/mainDB.py +++ b/sickbeard/databases/mainDB.py @@ -26,6 +26,7 @@ from sickbeard.providers.generic import GenericProvider from sickbeard import encodingKludge as ek from sickbeard.exceptions import ex +from sickbeard.name_parser.parser import NameParser, InvalidNameException class MainSanityCheck(db.DBSanityCheck): @@ -385,6 +386,13 @@ class AddSizeAndSceneNameFields(SetNzbTorrentSettings): if not snatch_results: continue + nzb_name = snatch_results[0]["resource"] + file_name = ek.ek(os.path.basename, cur_result["resource"]) + + # take the extension off the filename, it's not needed + if '.' in file_name: + file_name = file_name.rpartition('.')[0] + # find the associated episode on disk ep_results = self.connection.select("SELECT episode_id, status FROM tv_episodes WHERE showid = ? AND season = ? AND episode = ?", [cur_result["showid"], cur_result["season"], cur_result["episode"]]) @@ -399,11 +407,21 @@ class AddSizeAndSceneNameFields(SetNzbTorrentSettings): if ep_quality != int(snatch_results[0]["quality"]): continue - # if all is well by here we'll just put the release name into the database - self.connection.action("UPDATE tv_episodes SET release_name = ? WHERE episode_id = ?", [snatch_results[0]["resource"], ep_results[0]["episode_id"]]) - + # make sure this is actually a real release name and not a season pack or something + for cur_name in (nzb_name, file_name): + logger.log(u"Checking if "+cur_name+" is actually a good release name", logger.DEBUG) + try: + np = NameParser(False) + parse_result = np.parse(cur_name) + except InvalidNameException: + continue + + if parse_result.series_name and parse_result.season_number != None and parse_result.episode_numbers and parse_result.release_group: + # if all is well by this point we'll just put the release name into the database + self.connection.action("UPDATE tv_episodes SET release_name = ? WHERE episode_id = ?", [cur_name, ep_results[0]["episode_id"]]) + break - #self.incDBVersion() + self.incDBVersion() class SetNzbTorrentSettings(PopulateRootDirs): def test(self): diff --git a/sickbeard/postProcessor.py b/sickbeard/postProcessor.py index 0f708a6ce28666a7d37305bed7e4681f90136e2b..855f7e8afd0ed87416938834bc2b0d0ffce5f325 100755 --- a/sickbeard/postProcessor.py +++ b/sickbeard/postProcessor.py @@ -51,6 +51,10 @@ class PostProcessor(object): EXISTS_SMALLER = 3 DOESNT_EXIST = 4 + NZB_NAME = 1 + FOLDER_NAME = 2 + FILE_NAME = 3 + def __init__(self, file_path, nzb_name = None): # absolute path to the folder that is being processed self.folder_path = ek.ek(os.path.dirname, ek.ek(os.path.abspath, file_path)) @@ -70,7 +74,10 @@ class PostProcessor(object): self.in_history = False self.release_group = None self.is_proper = False - self.good_folder = False + + self.good_results = {self.NZB_NAME: False, + self.FOLDER_NAME: False, + self.FILE_NAME: False} self.log = '' @@ -345,10 +352,14 @@ class PostProcessor(object): if parse_result.extra_info: self.is_proper = re.search('(^|[\. _-])(proper|repack)([\. _-]|$)', parse_result.extra_info, re.I) != None - # if we are doing the folder name and the folder is good then remember that for later - if name == self.folder_name: - if parse_result.series_name and parse_result.season_number != None and parse_result.episode_numbers and parse_result.release_group: - self.good_folder = True + # 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 name == self.nzb_name: + self.good_results[self.NZB_NAME] = True + elif name == self.folder_name: + self.good_results[self.FOLDER_NAME] = True + elif name == self.file_name: + self.good_results[self.FILE_NAME] = True # for each possible interpretation of that scene name for cur_name in name_list: @@ -704,11 +715,11 @@ class PostProcessor(object): for cur_ep in [ep_obj] + ep_obj.relatedEps: with cur_ep.lock: # use the best possible representation of the release name - if self.nzb_name: + if self.good_results[self.NZB_NAME]: cur_ep.release_name = self.nzb_name - elif self.good_folder: + elif self.good_results[self.FOLDER_NAME]: cur_ep.release_name = self.folder_name - else: + elif self.good_results[self.FILE_NAME]: cur_ep.release_name = self.file_name cur_ep.location = ek.ek(os.path.join, dest_path, new_file_name) cur_ep.saveToDB()