def build(self, show): """Build internal name cache :param show: Specify show to build name cache for, if None, just do all shows """ if self.should_update(show): self.last_update[show.name] = datetime.fromtimestamp( int(time.mktime(datetime.today().timetuple()))) self.clear(indexer_id=show.indexer_id) show_names = [] for curSeason in [-1] + get_scene_seasons(show.indexer_id): for name in list( set( get_scene_exceptions(show.indexer_id, 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(name=show_name) self.put(show_name, show.indexer_id)
def get_show(self, name): show_id = None if not name: return show_id def indexer_lookup(term): for indexer in IndexerApi().indexers: result = IndexerApi(indexer).search_for_show_id(term) if result: return result def scene_exception_lookup(term): tv_show = find_show_by_scene_exception(term) if tv_show: return tv_show.indexer_id def show_cache_lookup(term): tv_show = find_show_by_name(term) if tv_show: return tv_show.indexer_id for lookup in [show_cache_lookup, scene_exception_lookup, indexer_lookup]: for show_name in list({name, strip_accents(name), strip_accents(name).replace("'", " ")}): try: show_id = lookup(show_name) if not show_id: continue if self.validate_show and not find_show(show_id): continue if show_id: return show_id except Exception as e: sickrage.app.log.debug('SiCKRAGE encountered a error when attempting to lookup a show ID by show name, Error: {!r}'.format(e))
def all_possible_show_names(show_id, season=-1, session=None): """ 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] """ from sickrage.core.scene_exceptions import get_scene_exceptions show = find_show(show_id, session=session) show_names = get_scene_exceptions(show_id, 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_id, 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 = common.countryList country_list.update( dict(zip(common.countryList.values(), common.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(r'\({}\)'.format(show.startyear), '', curName)) show_names += new_show_names return list(set(show_names))
def get_show(self, name): if not name: return None def series_provider_lookup(term): for _series_provider_id in SeriesProviderID: result = search_series_provider_for_series_id( term, _series_provider_id) if result: return result, _series_provider_id return None, None def scene_exception_lookup(term): tv_show = find_show_by_scene_exception(term) if tv_show: return tv_show.series_id, tv_show.series_provider_id return None, None def show_cache_lookup(term): tv_show = find_show_by_name(term) if tv_show: return tv_show.series_id, tv_show.series_provider_id return None, None for lookup in [ show_cache_lookup, scene_exception_lookup, series_provider_lookup ]: for show_name in list({ name, strip_accents(name), strip_accents(name).replace("'", " ") }): try: series_id, series_provider_id = lookup(show_name) if not series_id or not series_provider_id: continue if self.validate_show and not find_show( series_id, series_provider_id): continue if series_id and series_provider_id: return series_id, series_provider_id except Exception as e: sickrage.app.log.debug( 'SiCKRAGE encountered a error when attempting to lookup a series id by show name, Error: {!r}' .format(e))
def get_show(self, name): show_id = None show_names = [name] if not name: return show_id def cache_lookup(term): return sickrage.app.name_cache.get(term) def scene_exception_lookup(term): return scene_exceptions.get_scene_exception_by_name(term)[0] def showlist_lookup(term): try: return find_show_by_name(term).indexer_id 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 self.validate_show and not find_show(show_id): continue except Exception: pass if show_id is None: # ignore show name by caching it with a indexer_id of 0 sickrage.app.name_cache.put(show_name, 0) return show_id or 0
def get_show(self, name): show_id = None if not name: return show_id def indexer_lookup(term): for indexer in IndexerApi().indexers: result = IndexerApi(indexer).search_for_show_id(term) if result: return result def scene_exception_lookup(term): tv_show = find_show_by_scene_exception(term) if tv_show: return tv_show.indexer_id def show_cache_lookup(term): tv_show = find_show_by_name(term) if tv_show: return tv_show.indexer_id for lookup in [ show_cache_lookup, scene_exception_lookup, indexer_lookup ]: for show_name in list({ name, strip_accents(name), strip_accents(name).replace("'", " ") }): try: show_id = lookup(show_name) if not show_id: continue if self.validate_show and not find_show(show_id): continue if show_id: return show_id except Exception: pass