def _get_episode_search_strings(self, show_id, season, episode, add_string='', session=None): search_string = {'Episode': []} show_object = find_show(show_id, session=session) episode_object = show_object.get_episode(season, episode) for show_name in set(show_names.all_possible_show_names(show_id)): for sep in ' ', ' - ': ep_string = sanitize_scene_name(show_name) + sep if show_object.air_by_date: ep_string += str(episode_object.airdate).replace('-', '|') elif show_object.sports: ep_string += str(episode_object.airdate).replace('-', '|') + '|' + episode_object.airdate.strftime('%b') elif show_object.anime: ep_string += '%i' % int(episode_object.scene_absolute_number) else: ep_string += sickrage.app.naming_ep_type[2] % {'seasonnumber': episode_object.scene_season, 'episodenumber': episode_object.scene_episode} if add_string: ep_string += ' %s' % add_string search_string['Episode'].append(re.sub(r'\s+', ' ', ep_string.replace('.', ' ').strip())) return [search_string]
def get_scene_exception_by_name_multiple(show_name, session=None): """ Given a show name, return the indexer_id of the exception, None if no exception is present. """ out = [] # try the obvious case first exception_result = session.query(CacheDB.SceneException).filter_by( show_name=show_name.lower()).order_by(CacheDB.SceneException.season) if exception_result.count(): return [(int(x.indexer_id), int(x.season)) for x in exception_result] for cur_exception in session.query(CacheDB.SceneException).order_by( CacheDB.SceneException.season): cur_exception_name = cur_exception.show_name cur_indexer_id = int(cur_exception.indexer_id) cur_season = int(cur_exception.season) if show_name.lower() == sanitize_scene_name( cur_exception_name).lower().replace('.', ' '): sickrage.app.log.debug( "Scene exception lookup got indexer ID {}, using that".format( cur_indexer_id)) out.append((cur_indexer_id, cur_season)) if out: return out return [(None, None)]
def _search_params(self, show_id, season, episode, mode, season_numbering=None, session=None): searches = [] show_object = find_show(show_id, session=session) episode_object = show_object.get_episode(season, episode) air_by_date = show_object.air_by_date sports = show_object.sports if not season_numbering and (air_by_date or sports): date_fmt = '%Y' if mode == 'Season' else '%Y.%m.%d' search_name = episode_object.airdate.strftime(date_fmt) else: search_name = '{type} {number}'.format( type='Season' if mode == 'Season' else '', number=episode_object.scene_season if mode == 'Season' and season else episode_num( episode_object.scene_season, episode_object.scene_episode), ).strip() params = { 'category': mode, 'name': search_name, } # Search if show_object.indexer == 1: params['tvdb'] = show_object.indexer_id params['series'] = show_object.name searches.append(params) for name in list( set( scene_exceptions.get_scene_exceptions( show_object.indexer_id))): series_params = params.copy() series_params['series'] = sanitize_scene_name(name) searches.append(series_params) # extend air by date searches to include season numbering if air_by_date and not season_numbering: searches.extend( self._search_params(show_id, season, episode, mode, season_numbering=True)) return searches
def _get_episode_search_strings(self, series_id, series_provider_id, season, episode, add_string=''): search_string = {'Episode': []} show_object = find_show(series_id, series_provider_id) if not show_object: return [search_string] episode_object = show_object.get_episode(season, episode) for show_name in set( show_names.all_possible_show_names(series_id, series_provider_id)): for sep in ' ', ' - ': ep_string = sanitize_scene_name(show_name) + sep if show_object.search_format == SearchFormat.AIR_BY_DATE: ep_string += str(episode_object.airdate).replace('-', '|') elif show_object.search_format == SearchFormat.SPORTS: ep_string += str(episode_object.airdate).replace( '-', '|') + '|' + episode_object.airdate.strftime('%b') elif show_object.search_format == SearchFormat.ANIME: ep_string += '%i' % episode_object.get_absolute_numbering() else: ep_string += sickrage.app.naming_ep_type[2] % { 'seasonnumber': episode_object.get_season_episode_numbering()[0], 'episodenumber': episode_object.get_season_episode_numbering()[1] } if add_string: ep_string += ' %s' % add_string search_string['Episode'].append( re.sub(r'\s+', ' ', ep_string.replace('.', ' ').strip())) return [search_string]
def _search_params(self, show_id, season, episode, mode, season_numbering=None): searches = [] show_object = find_show(show_id) if not show_object: return searches episode_object = show_object.get_episode(season, episode) if not season_numbering and show_object.search_format in [SearchFormats.AIR_BY_DATE, SearchFormats.SPORTS]: date_fmt = '%Y' if mode == 'Season' else '%Y.%m.%d' search_name = episode_object.airdate.strftime(date_fmt) else: search_name = '{type} {number}'.format( type='Season' if mode == 'Season' else '', number=episode_object.get_season_episode_numbering()[0] if mode == 'Season' and season else episode_num(episode_object.get_season_episode_numbering()[0], episode_object.get_season_episode_numbering()[1]), ).strip() params = { 'category': mode, 'name': search_name, } # Search if show_object.indexer == 1: params['tvdb'] = show_object.indexer_id params['series'] = show_object.name searches.append(params) for scene_exception in [x.split('|')[0] for x in show_object.scene_exceptions]: series_params = params.copy() series_params['series'] = sanitize_scene_name(scene_exception) searches.append(series_params) # extend air by date searches to include season numbering if show_object.search_format == SearchFormats.AIR_BY_DATE and not season_numbering: searches.extend(self._search_params(show_id, season, episode, mode, season_numbering=True)) return searches
def dot(name): return sanitize_scene_name(name)