def showEpisodeStatuses(indexername, seriesid, whichStatus): status_list = [int(whichStatus)] if status_list[0] == SNATCHED: status_list = [SNATCHED, SNATCHED_PROPER, SNATCHED_BEST] main_db_con = db.DBConnection() cur_show_results = main_db_con.select( b'SELECT season, episode, name ' b'FROM tv_episodes ' b'WHERE indexer = ? AND showid = ? ' b'AND season != 0 AND status IN ({statuses})'.format( statuses=','.join(['?'] * len(status_list))), [int(indexer_name_to_id(indexername)), int(seriesid)] + status_list) result = {} for cur_result in cur_show_results: cur_season = int(cur_result[b'season']) cur_episode = int(cur_result[b'episode']) if cur_season not in result: result[cur_season] = {} result[cur_season][cur_episode] = cur_result[b'name'] return json.dumps(result)
def showEpisodeStatuses(indexername, seriesid, whichStatus): status_list = [int(whichStatus)] if status_list[0] == SNATCHED: status_list = [SNATCHED, SNATCHED_PROPER, SNATCHED_BEST] main_db_con = db.DBConnection() cur_show_results = main_db_con.select( 'SELECT season, episode, name ' 'FROM tv_episodes ' 'WHERE indexer = ? AND showid = ? ' 'AND season != 0 AND status IN ({statuses})'.format( statuses=','.join(['?'] * len(status_list))), [int(indexer_name_to_id(indexername)), int(seriesid)] + status_list ) result = {} for cur_result in cur_show_results: cur_season = int(cur_result['season']) cur_episode = int(cur_result['episode']) if cur_season not in result: result[cur_season] = {} result[cur_season][cur_episode] = cur_result['name'] return json.dumps(result)
def find_by_id(series, indexer_id, series_id): """ Find a show by its indexer id in the provided list of shows. :param series: The list of shows to search in :param indexer_id: shows indexer :param series_id: The indexers show id of the desired show :return: The desired show if found, ``None`` if not found :throw: ``MultipleShowObjectsException`` if multiple shows match the provided ``indexer_id`` """ from medusa.indexers.utils import indexer_name_to_id if not indexer_id or not series_id: return None try: indexer_id = int(indexer_id) except ValueError: indexer_id = indexer_name_to_id(indexer_id) try: series_id = int(series_id) except ValueError: log.warning('Invalid series id: {series_id}', {'series_id': series_id}) if series_id is None or series is None or len(series) == 0: return None # indexer_ids = [show_id] if not isinstance(show_id, list) else show_id results = [show for show in series if show.indexer == indexer_id and show.indexerid == series_id] if not results: return None if len(results) == 1: return results[0]
def find_by_id(series, indexer_id, series_id): """ Find a show by its indexer id in the provided list of shows. :param series: The list of shows to search in :param indexer_id: shows indexer :param series_id: The indexers show id of the desired show :return: The desired show if found, ``None`` if not found :throw: ``MultipleShowObjectsException`` if multiple shows match the provided ``indexer_id`` """ from medusa.indexers.utils import indexer_name_to_id if not indexer_id or not series_id: return None try: indexer_id = int(indexer_id) except ValueError: indexer_id = indexer_name_to_id(indexer_id) if series_id is None or series is None or len(series) == 0: return None # indexer_ids = [show_id] if not isinstance(show_id, list) else show_id results = [ show for show in series if show.indexer == indexer_id and show.indexerid == series_id ] if not results: return None if len(results) == 1: return results[0]
def backlogShow(self, indexername, seriesid): indexer_id = indexer_name_to_id(indexername) series_obj = Show.find_by_id(app.showList, indexer_id, seriesid) if series_obj: app.backlog_search_scheduler.action.search_backlog([series_obj]) return self.redirect('/manage/backlogOverview/')
def backlogShow(self, indexername, seriesid): indexer_id = indexer_name_to_id(indexername) series_obj = Show.find_by_id(app.showList, indexer_id, seriesid) if series_obj: app.backlog_search_scheduler.action.search_backlog([series_obj]) return self.redirect('/manage/backlogOverview/')
def manualSearchSubtitles(self, showslug=None, season=None, episode=None, release_id=None, picked_id=None): mode = 'downloading' if picked_id else 'searching' description = '' logger.log('Starting to manual {mode} subtitles'.format(mode=mode)) try: if release_id: # Release ID is sent when using postpone release = app.RELEASES_IN_PP[int(release_id)] indexer_name = release['indexername'] series_id = release['seriesid'] season = release['season'] episode = release['episode'] filepath = release['release'] identifier = SeriesIdentifier.from_id( indexer_name_to_id(indexer_name), series_id) else: filepath = None identifier = SeriesIdentifier.from_slug(showslug) series_obj = Series.find_by_identifier(identifier) ep_obj = series_obj.get_episode(season, episode) video_path = filepath or ep_obj.location release_name = ep_obj.release_name or os.path.basename(video_path) except IndexError: ui.notifications.message('Outdated list', 'Please refresh page and try again') logger.log('Outdated list. Please refresh page and try again', logger.WARNING) return json.dumps({ 'result': 'failure', 'description': 'Outdated list. Please refresh page and try again' }) except (ValueError, TypeError) as e: ui.notifications.message('Error', 'Please check logs') logger.log( 'Error while manual {mode} subtitles. Error: {error_msg}'. format(mode=mode, error_msg=e), logger.ERROR) return json.dumps({ 'result': 'failure', 'description': 'Error while manual {mode} subtitles. Error: {error_msg}'. format(mode=mode, error_msg=e) }) if not os.path.isfile(video_path): ui.notifications.message( ep_obj.series.name, "Video file no longer exists. Can't search for subtitles") logger.log( 'Video file no longer exists: {video_file}'.format( video_file=video_path), logger.DEBUG) return json.dumps({ 'result': 'failure', 'description': 'Video file no longer exists: {video_file}'.format( video_file=video_path) }) if mode == 'searching': logger.log( 'Manual searching subtitles for: {0}'.format(release_name)) found_subtitles = subtitles.list_subtitles(tv_episode=ep_obj, video_path=video_path) if found_subtitles: ui.notifications.message( ep_obj.series.name, 'Found {} subtitles'.format(len(found_subtitles))) else: ui.notifications.message(ep_obj.series.name, 'No subtitle found') if found_subtitles: result = 'success' else: result = 'failure' description = 'No subtitles found' subtitles_result = found_subtitles else: logger.log( 'Manual downloading subtitles for: {0}'.format(release_name)) new_manual_subtitle = subtitles.save_subtitle( tv_episode=ep_obj, subtitle_id=picked_id, video_path=video_path) if new_manual_subtitle: ui.notifications.message( ep_obj.series.name, 'Subtitle downloaded: {0}'.format( ','.join(new_manual_subtitle))) else: ui.notifications.message( ep_obj.series.name, 'Failed to download subtitle for {0}'.format(release_name)) if new_manual_subtitle: result = 'success' else: result = 'failure' description = 'Failed to download subtitle for {0}'.format( release_name) subtitles_result = new_manual_subtitle return json.dumps({ 'result': result, 'release': release_name, 'subtitles': subtitles_result, 'description': description })
def from_slug(cls, slug): """Create Indexer from slug.""" identifier = indexer_name_to_id(slug) if identifier is not None: return Indexer(identifier)
def from_slug(cls, slug): """Create Indexer from slug.""" identifier = indexer_name_to_id(slug) if identifier is not None: return Indexer(identifier)