def buildNameCache(self, show=None): """Build internal name cache :param show: Specify show to build name cache for, if None, just do all shows """ if self.shouldUpdate(): if not show: retrieve_exceptions() for show in sickrage.srCore.SHOWLIST: self.buildNameCache(show) else: self.lastUpdate = datetime.fromtimestamp( int(time.mktime(datetime.today().timetuple()))) sickrage.srLogger.debug( "Building internal name cache for [{}]".format(show.name)) self.clearCache(show.indexerid) for curSeason in [-1] + get_scene_seasons(show.indexerid): for name in list( set( get_scene_exceptions(show.indexerid, season=curSeason) + [show.name])): name = full_sanitizeSceneName(name) if name not in self.cache: self.cache[name] = int(show.indexerid) sickrage.srLogger.debug( "Internal name cache for [{}] set to: [{}]".format( show.name, [ key for key, value in self.cache.items() if value == show.indexerid ][0]))
def _get_season_search_strings(ep_obj): search_params = [] current_params = {'category': 'Season'} # Search for entire seasons: no need to do special things for air by date or sports shows if ep_obj.show.air_by_date or ep_obj.show.sports: # Search for the year of the air by date show current_params[b'name'] = str(ep_obj.airdate).split('-')[0] elif ep_obj.show.is_anime: current_params[b'name'] = "%d" % ep_obj.scene_absolute_number else: current_params[b'name'] = 'Season ' + str(ep_obj.scene_season) # search if ep_obj.show.indexer == 1: current_params[b'tvdb'] = ep_obj.show.indexerid search_params.append(current_params) else: name_exceptions = list( set(get_scene_exceptions(ep_obj.show.indexerid) + [ep_obj.show.name])) for name in name_exceptions: # Search by name if we don't have tvdb id current_params[b'series'] = sanitizeSceneName(name) search_params.append(current_params) return search_params
def _get_episode_search_strings(ep_obj, add_string=''): if not ep_obj: return [{}] to_return = [] search_params = {'category': 'Episode'} # episode if ep_obj.show.air_by_date or ep_obj.show.sports: date_str = str(ep_obj.airdate) # BTN uses dots in dates, we just search for the date since that # combined with the series identifier should result in just one episode search_params[b'name'] = date_str.replace('-', '.') elif ep_obj.show.anime: search_params[b'name'] = "%i" % int(ep_obj.scene_absolute_number) else: # Do a general name search for the episode, formatted like SXXEYY search_params[b'name'] = "S%02dE%02d" % (ep_obj.scene_season, ep_obj.scene_episode) # search if ep_obj.show.indexer == 1: search_params[b'tvdb'] = ep_obj.show.indexerid to_return.append(search_params) else: # add new query string for every exception name_exceptions = list( set(get_scene_exceptions(ep_obj.show.indexerid) + [ep_obj.show.name])) for cur_exception in name_exceptions: search_params[b'series'] = sanitizeSceneName(cur_exception) to_return.append(search_params) return to_return
def _get_episode_search_strings(self, ep_obj, add_string=""): to_return = [] params = {} if not ep_obj: return to_return params[b"maxage"] = (datetime.now() - datetime.combine(ep_obj.airdate, datetime.min.time())).days + 1 params[b"tvdbid"] = ep_obj.show.indexerid if ep_obj.show.air_by_date or ep_obj.show.sports: date_str = str(ep_obj.airdate) params[b"season"] = date_str.partition("-")[0] params[b"ep"] = date_str.partition("-")[2].replace("-", "/") else: params[b"season"] = ep_obj.scene_season params[b"ep"] = ep_obj.scene_episode # add new query strings for exceptions name_exceptions = list(set([ep_obj.show.name] + get_scene_exceptions(ep_obj.show.indexerid))) for cur_exception in name_exceptions: params[b"q"] = sanitizeSceneName(cur_exception) if add_string: params[b"q"] += " " + add_string to_return.append(dict(params)) return to_return
def buildNameCache(self, show=None): """Build internal name cache :param show: Specify show to build name cache for, if None, just do all shows """ if self.shouldUpdate(): if not show: retrieve_exceptions() for show in sickrage.srCore.SHOWLIST: self.buildNameCache(show) else: self.lastUpdate = datetime.fromtimestamp(int(time.mktime(datetime.today().timetuple()))) sickrage.srLogger.debug("Building internal name cache for [{}]".format(show.name)) self.clearCache(show.indexerid) for curSeason in [-1] + get_scene_seasons(show.indexerid): for name in list(set(get_scene_exceptions( show.indexerid, season=curSeason) + [show.name])): name = full_sanitizeSceneName(name) if name not in self.cache: self.cache[name] = int(show.indexerid) sickrage.srLogger.debug("Internal name cache for [{}] set to: [{}]".format( show.name, [key for key, value in self.cache.items() if value == show.indexerid][0]))
def _get_season_search_strings(self, ep_obj): to_return = [] params = {} if not ep_obj: return to_return params[b"maxage"] = (datetime.now() - datetime.combine(ep_obj.airdate, datetime.min.time())).days + 1 params[b"tvdbid"] = ep_obj.show.indexerid # season if ep_obj.show.air_by_date or ep_obj.show.sports: date_str = str(ep_obj.airdate).split("-")[0] params[b"season"] = date_str params[b"q"] = date_str.replace("-", ".") else: params[b"season"] = str(ep_obj.scene_season) save_q = " " + params[b"q"] if "q" in params else "" # add new query strings for exceptions name_exceptions = list(set([ep_obj.show.name] + get_scene_exceptions(ep_obj.show.indexerid))) for cur_exception in name_exceptions: params[b"q"] = sanitizeSceneName(cur_exception) + save_q to_return.append(dict(params)) return to_return
def _get_season_search_strings(ep_obj): search_params = [] current_params = {'category': 'Season'} # Search for entire seasons: no need to do special things for air by date or sports shows if ep_obj.show.air_by_date or ep_obj.show.sports: # Search for the year of the air by date show current_params[b'name'] = str(ep_obj.airdate).split('-')[0] elif ep_obj.show.is_anime: current_params[b'name'] = "%d" % ep_obj.scene_absolute_number else: current_params[b'name'] = 'Season ' + str(ep_obj.scene_season) # search if ep_obj.show.indexer == 1: current_params[b'tvdb'] = ep_obj.show.indexerid search_params.append(current_params) else: name_exceptions = list( set( get_scene_exceptions(ep_obj.show.indexerid) + [ep_obj.show.name])) for name in name_exceptions: # Search by name if we don't have tvdb id current_params[b'series'] = sanitizeSceneName(name) search_params.append(current_params) return search_params
def allPossibleShowNames(show, season=-1): """ Figures out every possible variation of the name for a particular show. Includes TVDB name, TVRage name, country codes on the end, eg. "Show Name (AU)", and any scene exception names. show: a TVShow object that we should get the names of Returns: a list of all the possible show names :rtype: list[unicode] """ showNames = get_scene_exceptions(show.indexerid, season=season)[:] if not showNames: # if we dont have any season specific exceptions fallback to generic exceptions season = -1 showNames = get_scene_exceptions(show.indexerid, season=season)[:] if season in [-1, 1]: showNames.append(show.name) if not show.is_anime: newShowNames = [] country_list = countryList country_list.update(dict(zip(countryList.values(), countryList.keys()))) for curName in set(showNames): if not curName: continue # if we have "Show Name Australia" or "Show Name (Australia)" this will add "Show Name (AU)" for # any countries defined in common.countryList # (and vice versa) for curCountry in country_list: if curName.endswith(' ' + curCountry): newShowNames.append( curName.replace(' ' + curCountry, ' (' + country_list[curCountry] + ')')) elif curName.endswith(' (' + curCountry + ')'): newShowNames.append( curName.replace(' (' + curCountry + ')', ' (' + country_list[curCountry] + ')')) # # if we have "Show Name (2013)" this will strip the (2013) show year from the show name # newShowNames.append(re.sub('\(\d{4}\)', '', curName)) showNames += newShowNames return showNames
def allPossibleShowNames(show, season=-1): """ Figures out every possible variation of the name for a particular show. Includes TVDB name, TVRage name, country codes on the end, eg. "Show Name (AU)", and any scene exception names. show: a TVShow object that we should get the names of Returns: a list of all the possible show names :rtype: list[unicode] """ showNames = get_scene_exceptions(show.indexerid, season=season)[:] if not showNames: # if we dont have any season specific exceptions fallback to generic exceptions season = -1 showNames = get_scene_exceptions(show.indexerid, season=season)[:] if season in [-1, 1]: showNames.append(show.name) if not show.is_anime: newShowNames = [] country_list = countryList country_list.update(dict(zip(countryList.values(), countryList.keys()))) for curName in set(showNames): if not curName: continue # if we have "Show Name Australia" or "Show Name (Australia)" this will add "Show Name (AU)" for # any countries defined in common.countryList # (and vice versa) for curCountry in country_list: if curName.endswith(' ' + curCountry): newShowNames.append(curName.replace(' ' + curCountry, ' (' + country_list[curCountry] + ')')) elif curName.endswith(' (' + curCountry + ')'): newShowNames.append(curName.replace(' (' + curCountry + ')', ' (' + country_list[curCountry] + ')')) # # if we have "Show Name (2013)" this will strip the (2013) show year from the show name # newShowNames.append(re.sub('\(\d{4}\)', '', curName)) showNames += newShowNames return showNames
def _get_episode_search_strings(ep_obj, add_string=''): if not ep_obj: return [{}] to_return = [] search_params = {'category': 'Episode'} # episode if ep_obj.show.air_by_date or ep_obj.show.sports: date_str = str(ep_obj.airdate) # BTN uses dots in dates, we just search for the date since that # combined with the series identifier should result in just one episode search_params[b'name'] = date_str.replace('-', '.') elif ep_obj.show.anime: search_params[b'name'] = "%i" % int(ep_obj.scene_absolute_number) else: # Do a general name search for the episode, formatted like SXXEYY search_params[b'name'] = "S%02dE%02d" % (ep_obj.scene_season, ep_obj.scene_episode) # search if ep_obj.show.indexer == 1: search_params[b'tvdb'] = ep_obj.show.indexerid to_return.append(search_params) else: # add new query string for every exception name_exceptions = list( set( get_scene_exceptions(ep_obj.show.indexerid) + [ep_obj.show.name])) for cur_exception in name_exceptions: search_params[b'series'] = sanitizeSceneName(cur_exception) to_return.append(search_params) return to_return
def test_sceneExceptionsBabylon5(self): self.assertEqual(sorted(get_scene_exceptions(70726)), ['Babylon 5', 'Babylon5'])
def test_sceneExceptionsEmpty(self): self.assertEqual(get_scene_exceptions(0), [])