def build(self, show): """Build internal name cache :param show: Specify show to build name cache for, if None, just do all shows """ retrieve_exceptions() if self.should_update(show): self.last_update[show.name] = datetime.fromtimestamp( int(time.mktime(datetime.today().timetuple()))) self.clear(show.indexerid) show_names = [] for curSeason in [-1] + get_scene_seasons(show.indexerid): for name in list( set( get_scene_exceptions(show.indexerid, season=curSeason) + [show.name])): show_names.append(name) show_names.append(strip_accents(name)) show_names.append(strip_accents(name).replace("'", " ")) for show_name in set(show_names): self.clear(show_name) self.put(show_name, show.indexerid)
def get_show(self, name): show = None show_id = None show_names = [name] if not all([name, sickrage.app.showlist]): return show, show_id def cache_lookup(term): return sickrage.app.name_cache.get(term) def scene_exception_lookup(term): return get_scene_exception_by_name(term)[0] def indexer_lookup(term): show_id1 = int(IndexerApi().searchForShowID( full_sanitizeSceneName(term))[2]) show_id2 = int(srTraktAPI()['search'].query( full_sanitizeSceneName(term), 'show')[0].ids['tvdb']) return (None, show_id1)[show_id1 == show_id2] show_names.append(strip_accents(name)) show_names.append(strip_accents(name).replace("'", " ")) for show_name in set(show_names): lookup_list = [ lambda: cache_lookup(show_name), lambda: scene_exception_lookup(show_name), lambda: indexer_lookup(show_name), ] # lookup show id for lookup in lookup_list: try: show_id = int(lookup()) if show_id == 0: continue sickrage.app.name_cache.put(show_name, show_id) if not show: if self.validate_show: show = findCertainShow(show_id) else: from sickrage.core.tv.show import TVShow show = TVShow(1, show_id) except Exception: pass if show_id is None: # ignore show name by caching it with a indexerid of 0 sickrage.app.name_cache.put(show_name, 0) return show, show_id or 0
def get_show(self, name): show = None show_id = None show_names = [name] if not all([name, sickrage.app.showlist]): return show, show_id def cache_lookup(term): return sickrage.app.name_cache.get(term) def scene_exception_lookup(term): return get_scene_exception_by_name(term)[0] def showlist_lookup(term): try: return search_showlist_by_name(term).indexerid except MultipleShowObjectsException: return None show_names.append(strip_accents(name)) show_names.append(strip_accents(name).replace("'", " ")) for show_name in set(show_names): lookup_list = [ lambda: cache_lookup(show_name), lambda: scene_exception_lookup(show_name), lambda: showlist_lookup(show_name), ] # lookup show id for lookup in lookup_list: try: show_id = int(lookup()) if show_id == 0: continue sickrage.app.name_cache.put(show_name, show_id) if not show: if self.validate_show: show = findCertainShow(show_id) else: from sickrage.core.tv.show import TVShow show = TVShow(1, show_id) except Exception: pass if show_id is None: # ignore show name by caching it with a indexerid of 0 sickrage.app.name_cache.put(show_name, 0) return show, show_id or 0
def get_show(self, name): show = None show_id = None show_names = [name] if not all([name, sickrage.app.showlist]): return show, show_id def cache_lookup(term): return sickrage.app.name_cache.get(term) def scene_exception_lookup(term): return get_scene_exception_by_name(term)[0] def showlist_lookup(term): try: return search_showlist_by_name(term).indexerid except MultipleShowObjectsException: return None show_names.append(strip_accents(name)) show_names.append(strip_accents(name).replace("'", " ")) for show_name in set(show_names): lookup_list = [ lambda: cache_lookup(show_name), lambda: scene_exception_lookup(show_name), lambda: showlist_lookup(show_name), ] # lookup show id for lookup in lookup_list: try: show_id = int(lookup()) if show_id == 0: continue sickrage.app.name_cache.put(show_name, show_id) if not show: if self.validate_show: show = findCertainShow(show_id) else: from sickrage.core.tv.show import TVShow show = TVShow(1, show_id) except Exception: pass if show_id is None: # ignore show name by caching it with a indexerid of 0 sickrage.app.name_cache.put(show_name, 0) return show, show_id or 0
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] """ show_names = get_scene_exceptions(show.indexerid, season=season)[:] if not show_names: # if we dont have any season specific exceptions fallback to generic exceptions season = -1 show_names = get_scene_exceptions(show.indexerid, season=season)[:] if season in [-1, 1]: show_names.append(show.name) show_names.append(strip_accents(show.name)) show_names.append(strip_accents(show.name).replace("'", " ")) if not show.is_anime: new_show_names = [] country_list = countryList country_list.update(dict(zip(countryList.values(), countryList.keys()))) for curName in set(show_names): 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): new_show_names.append( curName.replace(' ' + curCountry, ' (' + country_list[curCountry] + ')')) elif curName.endswith(' (' + curCountry + ')'): new_show_names.append( curName.replace(' (' + curCountry + ')', ' (' + country_list[curCountry] + ')')) # # if we have "Show Name (2013)" this will strip the (2013) show year from the show name # new_show_names.append(re.sub('\(\d{4}\)', '', curName)) show_names += new_show_names return list(set(show_names))
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] """ show_names = get_scene_exceptions(show.indexerid, season=season)[:] if not show_names: # if we dont have any season specific exceptions fallback to generic exceptions season = -1 show_names = get_scene_exceptions(show.indexerid, season=season)[:] if season in [-1, 1]: show_names.append(show.name) show_names.append(strip_accents(show.name)) show_names.append(strip_accents(show.name).replace("'", " ")) if not show.is_anime: new_show_names = [] country_list = countryList country_list.update(dict(zip(countryList.values(), countryList.keys()))) for curName in set(show_names): 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): new_show_names.append(curName.replace(' ' + curCountry, ' (' + country_list[curCountry] + ')')) elif curName.endswith(' (' + curCountry + ')'): new_show_names.append(curName.replace(' (' + curCountry + ')', ' (' + country_list[curCountry] + ')')) # # if we have "Show Name (2013)" this will strip the (2013) show year from the show name # new_show_names.append(re.sub('\(\d{4}\)', '', curName)) show_names += new_show_names return list(set(show_names))
def build(self, show): """Build internal name cache :param show: Specify show to build name cache for, if None, just do all shows """ retrieve_exceptions() if self.should_update(show): self.last_update[show.name] = datetime.fromtimestamp(int(time.mktime(datetime.today().timetuple()))) self.clear(show.indexerid) show_names = [] for curSeason in [-1] + get_scene_seasons(show.indexerid): for name in list(set(get_scene_exceptions(show.indexerid, season=curSeason) + [show.name])): show_names.append(name) show_names.append(strip_accents(name)) show_names.append(strip_accents(name).replace("'", " ")) for show_name in set(show_names): self.clear(show_name) self.put(show_name, show.indexerid)