def get_scene_exception_by_name(series_name): """Get the season of a scene exception.""" # Flatten the exceptions_cache. scene_exceptions = [] for exception_set in list(exceptions_cache.values()): for title_exception in list(exception_set.values()): scene_exceptions += title_exception # First attempt exact match. for title_exception in scene_exceptions: if series_name == title_exception.title: return title_exception # Let's try out some sanitized names. for title_exception in scene_exceptions: sanitized_name = sanitize_scene_name(title_exception.title) titles = ( title_exception.title.lower(), sanitized_name.lower().replace('.', ' '), ) if series_name.lower() in titles: logger.debug( 'Scene exception lookup got series id {title_exception.series_id} ' 'from indexer {title_exception.indexer},' ' using that', title_exception=title_exception) return title_exception
def get_scene_exceptions_by_name(show_name): """Look for a series_id, season and indexer for a given series scene exception.""" # TODO: Rewrite to use exceptions_cache since there is no need to hit db. # TODO: Make the query more linient. For example. `Jojo's Bizarre Adventure Stardust Crusaders` will not match # while `Jojo's Bizarre Adventure - Stardust Crusaders` is available. if show_name is None: logger.debug('Scene exception lookup failed because no show name was provided') return [(None, None, None)] # Try the obvious case first cache_db_con = db.DBConnection('cache.db') scene_exceptions = cache_db_con.select( 'SELECT indexer, indexer_id, season ' 'FROM scene_exceptions ' 'WHERE show_name = ? ORDER BY season ASC', [show_name]) if scene_exceptions: # FIXME: Need to add additional layer indexer. return [(int(exception['indexer_id']), int(exception['season']), int(exception['indexer'])) for exception in scene_exceptions] result = [] scene_exceptions = cache_db_con.select( 'SELECT show_name, indexer, indexer_id, season ' 'FROM scene_exceptions' ) for exception in scene_exceptions: indexer = int(exception['indexer']) indexer_id = int(exception['indexer_id']) season = int(exception['season']) exception_name = exception['show_name'] sanitized_name = helpers.sanitize_scene_name(exception_name) show_names = ( exception_name.lower(), sanitized_name.lower().replace('.', ' '), ) if show_name.lower() in show_names: logger.debug( 'Scene exception lookup got indexer ID {cur_indexer},' ' using that', {'cur_indexer': indexer_id} ) result.append((indexer_id, season, indexer)) return result or [(None, None, None)]
def get_scene_exceptions_by_name(show_name): """Look for a series_id, season and indexer for a given series scene exception.""" # TODO: Rewrite to use exceptions_cache since there is no need to hit db. # TODO: Make the query more linient. For example. `Jojo's Bizarre Adventure Stardust Crusaders` will not match # while `Jojo's Bizarre Adventure - Stardust Crusaders` is available. if show_name is None: logger.debug('Scene exception lookup failed because no show name was provided') return [(None, None, None)] # Try the obvious case first cache_db_con = db.DBConnection('cache.db') scene_exceptions = cache_db_con.select( 'SELECT indexer, indexer_id, season ' 'FROM scene_exceptions ' 'WHERE show_name = ? ORDER BY season ASC', [show_name]) if scene_exceptions: # FIXME: Need to add additional layer indexer. return [(int(exception['indexer_id']), int(exception['season']), int(exception['indexer'])) for exception in scene_exceptions] result = [] scene_exceptions = cache_db_con.select( 'SELECT show_name, indexer, indexer_id, season ' 'FROM scene_exceptions' ) for exception in scene_exceptions: indexer = int(exception['indexer']) indexer_id = int(exception['indexer_id']) season = int(exception['season']) exception_name = exception['show_name'] sanitized_name = helpers.sanitize_scene_name(exception_name) show_names = ( exception_name.lower(), sanitized_name.lower().replace('.', ' '), ) if show_name.lower() in show_names: logger.debug( 'Scene exception lookup got indexer ID {cur_indexer},' ' using that', {'cur_indexer': indexer_id} ) result.append((indexer_id, season, indexer)) return result or [(None, None, None)]
def get_scene_exceptions_by_name(show_name): """Get the indexer_id and season of the scene exception.""" # TODO: Rewrite to use exceptions_cache since there is no need to hit db. # Try the obvious case first cache_db_con = db.DBConnection('cache.db') scene_exceptions = cache_db_con.select( b'SELECT indexer, indexer_id, season ' b'FROM scene_exceptions ' b'WHERE show_name = ? ORDER BY season ASC', [show_name]) if scene_exceptions: # FIXME: Need to add additional layer indexer. return [(int(exception[b'indexer_id']), int(exception[b'season']), int(exception[b'indexer'])) for exception in scene_exceptions] result = [] scene_exceptions = cache_db_con.select( b'SELECT show_name, indexer, indexer_id, season ' b'FROM scene_exceptions' ) for exception in scene_exceptions: indexer = int(exception[b'indexer']) indexer_id = int(exception[b'indexer_id']) season = int(exception[b'season']) exception_name = exception[b'show_name'] sanitized_name = helpers.sanitize_scene_name(exception_name) show_names = ( exception_name.lower(), sanitized_name.lower().replace('.', ' '), ) if show_name.lower() in show_names: logger.debug( 'Scene exception lookup got indexer ID {cur_indexer},' ' using that', cur_indexer=indexer_id ) result.append((indexer_id, season, indexer)) return result or [(None, None, None)]