diff --git a/sickbeard/helpers.py b/sickbeard/helpers.py index 96927b41..d1d3c23d 100644 --- a/sickbeard/helpers.py +++ b/sickbeard/helpers.py @@ -1239,3 +1239,16 @@ def mapIndexersToShow(showObj): indexerMap[showObj.name] = mapped return mapped + + +def touchFile(self, fname, atime=None): + if None != atime: + try: + with file(fname, 'a'): + os.utime(fname, (atime, atime)) + return True + except: + logger.log(u"File air date stamping not available on your OS", logger.DEBUG) + pass + + return False \ No newline at end of file diff --git a/sickbeard/name_cache.py b/sickbeard/name_cache.py index d1ad28e9..fd793cf4 100644 --- a/sickbeard/name_cache.py +++ b/sickbeard/name_cache.py @@ -20,7 +20,7 @@ import sickbeard from sickbeard import db from sickbeard import logger -nameCache = None +nameCache = {} nameCacheLock = threading.Lock() def addNameToCache(name, indexer_id=0): @@ -94,10 +94,6 @@ def saveNameCacheToDb(): def buildNameCache(show=None): global nameCache - # init name cache - if not nameCache: - nameCache = {} - with nameCacheLock: # clear internal name cache clearCache() diff --git a/sickbeard/postProcessor.py b/sickbeard/postProcessor.py index 190b84d5..8759f10e 100644 --- a/sickbeard/postProcessor.py +++ b/sickbeard/postProcessor.py @@ -71,13 +71,13 @@ class PostProcessor(object): self.file_path = file_path # file name only - self.file_name = helpers.remove_extension(ek.ek(os.path.basename, file_path)) + self.file_name = ek.ek(os.path.basename, file_path) # the name of the folder only - self.folder_name = helpers.remove_extension(ek.ek(os.path.basename, self.folder_path)) + self.folder_name = ek.ek(os.path.basename, self.folder_path) # name of the NZB that resulted in this folder - self.nzb_name = helpers.remove_extension(nzb_name) + self.nzb_name = nzb_name self.process_method = process_method if process_method else sickbeard.PROCESS_METHOD @@ -1007,7 +1007,7 @@ class PostProcessor(object): # download subtitles if sickbeard.USE_SUBTITLES and ep_obj.show.subtitles: - for curEp in [ep_obj]: + for cur_ep in [ep_obj] + ep_obj.relatedEps: with cur_ep.lock: cur_ep.location = ek.ek(os.path.join, dest_path, new_file_name) cur_ep.downloadSubtitles(force=True) @@ -1017,21 +1017,20 @@ class PostProcessor(object): for cur_ep in [ep_obj] + ep_obj.relatedEps: with cur_ep.lock: cur_ep.location = ek.ek(os.path.join, dest_path, new_file_name) - sql_l.append(cur_ep.get_sql()) - # set file modify stamp to show airdate - if sickbeard.AIRDATE_EPISODES: - ep_obj.show.airdateModifyStamp(cur_ep) - - # generate nfo/tbn - ep_obj.createMetaFiles() - sql_l.append(ep_obj.get_sql()) - if len(sql_l) > 0: myDB = db.DBConnection() myDB.mass_action(sql_l) + # set file modify stamp to show airdate + if sickbeard.AIRDATE_EPISODES: + for cur_ep in [ep_obj] + ep_obj.relatedEps: + with cur_ep.lock: + cur_ep.airdateModifyStamp() + + # generate nfo/tbn + ep_obj.createMetaFiles() # log it to history history.logDownload(ep_obj, self.file_path, new_ep_quality, self.release_group) diff --git a/sickbeard/providers/generic.py b/sickbeard/providers/generic.py index deaf62dc..1878c154 100644 --- a/sickbeard/providers/generic.py +++ b/sickbeard/providers/generic.py @@ -383,10 +383,10 @@ class GenericProvider: if not result: continue - if epNum in results: - results[epNum].append(result) - else: + if epNum not in results: results[epNum] = [result] + else: + results[epNum].append(result) return results diff --git a/sickbeard/searchBacklog.py b/sickbeard/searchBacklog.py index c0f665dd..4bccad8f 100644 --- a/sickbeard/searchBacklog.py +++ b/sickbeard/searchBacklog.py @@ -162,11 +162,10 @@ class BacklogSearcher: common.SNATCHED_BEST) and curQuality < highestBestQuality) or curStatus == common.WANTED: epObj = show.getEpisode(int(result["season"]), int(result["episode"])) - - if epObj.season in wanted: - wanted[epObj.season].append(epObj) - else: + if epObj.season not in wanted: wanted[epObj.season] = [epObj] + else: + wanted[epObj.season].append(epObj) return wanted diff --git a/sickbeard/tv.py b/sickbeard/tv.py index 7bf1ced3..73f7ad89 100644 --- a/sickbeard/tv.py +++ b/sickbeard/tv.py @@ -1076,52 +1076,12 @@ class TVShow(object): else: # the file exists, set its modify file stamp if sickbeard.AIRDATE_EPISODES: - self.airdateModifyStamp(curEp) + curEp.airdateModifyStamp() if len(sql_l) > 0: myDB = db.DBConnection() myDB.mass_action(sql_l) - - def airdateModifyStamp(self, ep_obj): - """ - Make the modify date and time of a file reflect the show air date and time. - Note: Also called from postProcessor - - """ - hr = min = 0 - airs = re.search('.*?(\d{1,2})(?::\s*?(\d{2}))?\s*(pm)?', ep_obj.show.airs, re.I) - if airs: - hr = int(airs.group(1)) - hr = (12 + hr, hr)[None is airs.group(3)] - min = int((airs.group(2), min)[None is airs.group(2)]) - airtime = datetime.time(hr, min) - - airdatetime = datetime.datetime.combine(ep_obj.airdate, airtime) - - filemtime = datetime.datetime.fromtimestamp(os.path.getmtime(ep_obj.location)) - - if filemtime != airdatetime: - import time - - airdatetime = airdatetime.timetuple() - if self.touch(ep_obj.location, time.mktime(airdatetime)): - logger.log(str(self.indexerid) + u": Changed modify date of " + os.path.basename(ep_obj.location) - + " to show air date " + time.strftime("%b %d,%Y (%H:%M)", airdatetime)) - - def touch(self, fname, atime=None): - - if None != atime: - try: - with file(fname, 'a'): - os.utime(fname, (atime, atime)) - return True - except: - logger.log(u"File air date stamping not available on your OS", logger.DEBUG) - pass - - return False - def downloadSubtitles(self, force=False): # TODO: Add support for force option if not ek.ek(os.path.isdir, self._location): @@ -2441,6 +2401,32 @@ class TVEpisode(object): myDB = db.DBConnection() myDB.mass_action(sql_l) + def airdateModifyStamp(self): + """ + Make the modify date and time of a file reflect the show air date and time. + Note: Also called from postProcessor + + """ + hr = min = 0 + airs = re.search('.*?(\d{1,2})(?::\s*?(\d{2}))?\s*(pm)?', self.show.airs, re.I) + if airs: + hr = int(airs.group(1)) + hr = (12 + hr, hr)[None is airs.group(3)] + min = int((airs.group(2), min)[None is airs.group(2)]) + airtime = datetime.time(hr, min) + + airdatetime = datetime.datetime.combine(self.airdate, airtime) + + filemtime = datetime.datetime.fromtimestamp(os.path.getmtime(self.location)) + + if filemtime != airdatetime: + import time + + airdatetime = airdatetime.timetuple() + if helpers.touchFile(self.location, time.mktime(airdatetime)): + logger.log(str(self.show.indexerid) + u": Changed modify date of " + os.path.basename(self.location) + + " to show air date " + time.strftime("%b %d,%Y (%H:%M)", airdatetime)) + def __getstate__(self): d = dict(self.__dict__) del d['lock'] diff --git a/sickbeard/tvcache.py b/sickbeard/tvcache.py index f04e7b87..0ee9e760 100644 --- a/sickbeard/tvcache.py +++ b/sickbeard/tvcache.py @@ -138,8 +138,7 @@ class TVCache(): return RSSFeeds(self.providerID).getFeed(url, post_data, request_headers) def _translateTitle(self, title): - title = u'' + title - return title.replace(' ', '.') + return u'' + title.replace(' ', '.') def _translateLinkURL(self, url): @@ -345,32 +344,29 @@ class TVCache(): if not showObj.wantEpisode(curSeason, curEp, curQuality, manualSearch): logger.log(u"Skipping " + curResult["name"] + " because we don't want an episode that's " + Quality.qualityStrings[curQuality], logger.DEBUG) + continue + + # build a result object + title = curResult["name"] + url = curResult["url"] + + logger.log(u"Found result " + title + " at " + url) + + result = self.provider.getResult([epObj]) + result.show = showObj + result.url = url + result.name = title + result.quality = curQuality + result.release_group = curReleaseGroup + result.content = self.provider.getURL(url) \ + if self.provider.providerType == sickbeard.providers.generic.GenericProvider.TORRENT \ + and not url.startswith('magnet') else None + + # add it to the list + if epObj not in neededEps: + neededEps[epObj] = [result] else: - - if not epObj: - epObj = showObj.getEpisode(curSeason, curEp) - - # build a result object - title = curResult["name"] - url = curResult["url"] - - logger.log(u"Found result " + title + " at " + url) - - result = self.provider.getResult([epObj]) - result.show = showObj - result.url = url - result.name = title - result.quality = curQuality - result.release_group = curReleaseGroup - result.content = self.provider.getURL(url) \ - if self.provider.providerType == sickbeard.providers.generic.GenericProvider.TORRENT \ - and not url.startswith('magnet') else None - - # add it to the list - if epObj not in neededEps: - neededEps[epObj] = [result] - else: - neededEps[epObj].append(result) + neededEps[epObj].append(result) # datetime stamp this search so cache gets cleared self.setLastSearch()