diff --git a/sickbeard/__init__.py b/sickbeard/__init__.py index d981bed6..b18c037f 100644 --- a/sickbeard/__init__.py +++ b/sickbeard/__init__.py @@ -50,6 +50,8 @@ from sickbeard.databases import mainDB, cache_db, failed_db from lib.configobj import ConfigObj +import xml.etree.ElementTree as ElementTree + invoked_command = None PID = None @@ -135,6 +137,7 @@ ROOT_DIRS = None UPDATE_SHOWS_ON_START = None SORT_ARTICLE = None DEBUG = False +CLEAR_CACHE = None USE_LISTVIEW = None METADATA_XBMC = None @@ -521,7 +524,7 @@ def initialize(consoleLogging=True): USE_SYNOLOGYNOTIFIER, SYNOLOGYNOTIFIER_NOTIFY_ONSNATCH, SYNOLOGYNOTIFIER_NOTIFY_ONDOWNLOAD, SYNOLOGYNOTIFIER_NOTIFY_ONSUBTITLEDOWNLOAD, \ USE_EMAIL, EMAIL_HOST, EMAIL_PORT, EMAIL_TLS, EMAIL_USER, EMAIL_PASSWORD, EMAIL_FROM, EMAIL_NOTIFY_ONSNATCH, EMAIL_NOTIFY_ONDOWNLOAD, EMAIL_NOTIFY_ONSUBTITLEDOWNLOAD, EMAIL_LIST, \ USE_LISTVIEW, METADATA_XBMC, METADATA_XBMC_12PLUS, METADATA_MEDIABROWSER, METADATA_PS3, metadata_provider_dict, \ - NEWZBIN, NEWZBIN_USERNAME, NEWZBIN_PASSWORD, GIT_PATH, MOVE_ASSOCIATED_FILES, \ + NEWZBIN, NEWZBIN_USERNAME, NEWZBIN_PASSWORD, GIT_PATH, MOVE_ASSOCIATED_FILES, CLEAR_CACHE, \ GUI_NAME, HOME_LAYOUT, HISTORY_LAYOUT, DISPLAY_SHOW_SPECIALS, COMING_EPS_LAYOUT, COMING_EPS_SORT, COMING_EPS_DISPLAY_PAUSED, COMING_EPS_MISSED_RANGE, DATE_PRESET, TIME_PRESET, TIME_PRESET_W_SECONDS, \ METADATA_WDTV, METADATA_TIVO, METADATA_MEDE8ER, IGNORE_WORDS, CALENDAR_UNPROTECTED, CREATE_MISSING_SHOW_DIRS, \ ADD_SHOWS_WO_DIR, USE_SUBTITLES, SUBTITLES_LANGUAGES, SUBTITLES_DIR, SUBTITLES_SERVICES_LIST, SUBTITLES_SERVICES_ENABLED, SUBTITLES_HISTORY, SUBTITLES_FINDER_FREQUENCY, subtitlesFinderScheduler, \ @@ -1123,6 +1126,15 @@ def initialize(consoleLogging=True): showList = [] loadingShowList = {} + url = 'http://raw.github.com/echel0n/sickrage-init/master/settings.ini' + clear_cache = ElementTree.XML(helpers.getURL(url)).find('cache/clear').text + CLEAR_CACHE = check_setting_str(CFG, 'General', 'clear_cache', '') + if CLEAR_CACHE != clear_cache: + for curProvider in [x for x in providers.sortedProviderList() if x.isActive()]: + curProvider.cache._clearCache() + CLEAR_CACHE = clear_cache + save_config() + __INITIALIZED__ = True return True @@ -1442,6 +1454,8 @@ def save_config(): new_config['General']['ignore_words'] = IGNORE_WORDS new_config['General']['calendar_unprotected'] = int(CALENDAR_UNPROTECTED) + new_config['General']['clear_cache'] = CLEAR_CACHE + new_config['Blackhole'] = {} new_config['Blackhole']['nzb_dir'] = NZB_DIR new_config['Blackhole']['torrent_dir'] = TORRENT_DIR diff --git a/sickbeard/helpers.py b/sickbeard/helpers.py index 5726e90c..751fa59a 100644 --- a/sickbeard/helpers.py +++ b/sickbeard/helpers.py @@ -212,10 +212,11 @@ def getURL(url, post_data=None, headers=None, params=None, timeout=30, json=Fals logger.log(u"Connection timed out " + str(e.message) + " while loading URL " + url, logger.WARNING) return None - if json: - return r.json() if r.ok else None + if r.ok: + if json: + return r.json() - return r.content if r.ok else None + return r.content def _remove_file_failed(file): @@ -284,7 +285,7 @@ def makeDir(path): return True -def searchDBForShow(regShowName): +def searchDBForShow(regShowName, log=False): showNames = [re.sub('[. -]', ' ', regShowName)] myDB = db.DBConnection() @@ -303,17 +304,20 @@ def searchDBForShow(regShowName): # if we didn't get exactly one result then try again with the year stripped off if possible match = re.match(yearRegex, showName) if match and match.group(1): - logger.log(u"Unable to match original name but trying to manually strip and specify show year", - logger.DEBUG) + if log: + logger.log(u"Unable to match original name but trying to manually strip and specify show year", + logger.DEBUG) sqlResults = myDB.select( "SELECT * FROM tv_shows WHERE (show_name LIKE ?) AND startyear = ?", [match.group(1) + '%', match.group(3)]) if len(sqlResults) == 0: - logger.log(u"Unable to match a record in the DB for " + showName, logger.DEBUG) + if log: + logger.log(u"Unable to match a record in the DB for " + showName, logger.DEBUG) continue elif len(sqlResults) > 1: - logger.log(u"Multiple results for " + showName + " in the DB, unable to match show name", logger.DEBUG) + if log: + logger.log(u"Multiple results for " + showName + " in the DB, unable to match show name", logger.DEBUG) continue else: return (int(sqlResults[0]["indexer_id"]), sqlResults[0]["show_name"]) diff --git a/sickbeard/name_parser/parser.py b/sickbeard/name_parser/parser.py index d2dae022..aacad9f5 100644 --- a/sickbeard/name_parser/parser.py +++ b/sickbeard/name_parser/parser.py @@ -377,7 +377,10 @@ class ParseResult(object): if self.season_number == None: return self # can't work without a season if len(self.episode_numbers) == 0: return self # need at least one episode - self.show = helpers.get_show_by_name(self.series_name) + showResult = helpers.searchDBForShow(self.series_name) + if showResult: + self.show = helpers.findCertainShow(sickbeard.showList, int(showResult[0])) + if not self.show: return self diff --git a/sickbeard/tvcache.py b/sickbeard/tvcache.py index f59d03ff..6f90739f 100644 --- a/sickbeard/tvcache.py +++ b/sickbeard/tvcache.py @@ -232,7 +232,7 @@ class TVCache(): # if we don't have complete info then parse the filename to get it try: myParser = NameParser() - parse_result = myParser.parse(name) + parse_result = myParser.parse(name).convert() except InvalidNameException: logger.log(u"Unable to parse the filename " + name + " into a valid episode", logger.DEBUG) return None @@ -255,13 +255,6 @@ class TVCache(): if showResult: indexerid = int(showResult[0]) - # if not indexerid: - # for curShow in sickbeard.showList: - # if curShow.name == parse_result.series_name: - # if show_name_helpers.isGoodResult(name, curShow, False): - # indexerid = int(curShow.indexerid) - # break - showObj = None if indexerid: showObj = helpers.findCertainShow(sickbeard.showList, indexerid) @@ -327,14 +320,14 @@ class TVCache(): def findNeededEpisodes(self, epObj=None, manualSearch=False): neededEps = {} - myDB = self._getDB() + cacheDB = self._getDB() if not epObj: - sqlResults = myDB.select("SELECT * FROM [" + self.providerID + "]") + sqlResults = cacheDB.select("SELECT * FROM [" + self.providerID + "]") else: - sqlResults = myDB.select( + sqlResults = cacheDB.select( "SELECT * FROM [" + self.providerID + "] WHERE indexerid = ? AND season = ? AND episodes LIKE ?", - [epObj.show.indexerid, epObj.scene_season, "%|" + str(epObj.scene_episode) + "|%"]) + [epObj.show.indexerid, epObj.season, "%|" + str(epObj.episode) + "|%"]) # for each cache entry for curResult in sqlResults: @@ -386,9 +379,9 @@ class TVCache(): # add it to the list if epObj not in neededEps: - neededEps[epObj] = [result] + neededEps[epObj.episode] = [result] else: - neededEps[epObj].append(result) + neededEps[epObj.episode].append(result) return neededEps