def resource_get_subtitle_missed(self): """Return a list of episodes which are missing a specific subtitle language.""" language = self.get_argument('language' '').strip() main_db_con = db.DBConnection() results = main_db_con.select( 'SELECT show_name, tv_shows.show_id, tv_shows.indexer, ' 'tv_shows.indexer_id AS indexer_id, tv_episodes.subtitles subtitles, ' 'tv_episodes.episode AS episode, tv_episodes.season AS season, ' 'tv_episodes.name AS name ' 'FROM tv_episodes, tv_shows ' 'WHERE tv_shows.subtitles = 1 ' 'AND tv_episodes.status = ? ' 'AND tv_episodes.season != 0 ' "AND tv_episodes.location != '' " 'AND tv_episodes.showid = tv_shows.indexer_id ' 'AND tv_episodes.indexer = tv_shows.indexer ' 'ORDER BY show_name', [DOWNLOADED]) subtitle_status = {} for cur_status_result in results: cur_indexer = int(cur_status_result['indexer']) cur_series_id = int(cur_status_result['indexer_id']) show_slug = SeriesIdentifier.from_id(cur_indexer, cur_series_id).slug subtitles = cur_status_result['subtitles'].split(',') if language == 'all': if not frozenset(wanted_languages()).difference(subtitles): continue elif language in subtitles: continue if show_slug not in subtitle_status: subtitle_status[show_slug] = { 'selected': True, 'slug': show_slug, 'name': cur_status_result['show_name'], 'episodes': [], 'showEpisodes': False } subtitle_status[show_slug]['episodes'].append({ 'episode': cur_status_result['episode'], 'season': cur_status_result['season'], 'selected': True, 'slug': str( RelativeNumber(cur_status_result['season'], cur_status_result['episode'])), 'name': cur_status_result['name'], 'subtitles': subtitles }) return self._ok(data=subtitle_status)
def showSubtitleMissed(indexer, seriesid, whichSubs): main_db_con = db.DBConnection() cur_show_results = main_db_con.select( b'SELECT season, episode, name, subtitles ' b'FROM tv_episodes ' b'WHERE indexer = ? ' b'AND showid = ? ' b'AND season != 0 ' b'AND status = ? ' b"AND location != ''", [int(indexer), int(seriesid), DOWNLOADED]) result = {} for cur_result in cur_show_results: if whichSubs == 'all': if not frozenset(subtitles.wanted_languages()).difference( cur_result[b'subtitles'].split(',')): continue elif whichSubs in cur_result[b'subtitles']: continue cur_season = int(cur_result[b'season']) cur_episode = int(cur_result[b'episode']) if cur_season not in result: result[cur_season] = {} if cur_episode not in result[cur_season]: result[cur_season][cur_episode] = {} result[cur_season][cur_episode]['name'] = cur_result[b'name'] result[cur_season][cur_episode]['subtitles'] = cur_result[ b'subtitles'] return json.dumps(result)
def subtitleMissed(self, whichSubs=None): t = PageTemplate(rh=self, filename='manage_subtitleMissed.mako') if not whichSubs: return t.render(whichSubs=whichSubs, topmenu='manage', show_names=None, ep_counts=None, sorted_show_ids=None, controller='manage', action='subtitleMissed') main_db_con = db.DBConnection() status_results = main_db_con.select( b'SELECT show_name, tv_shows.show_id, tv_shows.indexer, ' b'tv_shows.indexer_id as indexer_id, tv_episodes.subtitles subtitles ' b'FROM tv_episodes, tv_shows ' b'WHERE tv_shows.subtitles = 1 ' b'AND tv_episodes.status LIKE \'%4\' ' b'AND tv_episodes.season != 0 ' b'AND tv_episodes.location != \'\' ' b'AND tv_episodes.showid = tv_shows.indexer_id ' b'AND tv_episodes.indexer = tv_shows.indexer ' b'ORDER BY show_name') ep_counts = {} show_names = {} sorted_show_ids = [] for cur_status_result in status_results: if whichSubs == 'all': if not frozenset(subtitles.wanted_languages()).difference( cur_status_result[b'subtitles'].split(',')): continue elif whichSubs in cur_status_result[b'subtitles']: continue # FIXME: This will cause multi-indexer results where series_id overlaps for different indexers. # Fix by using tv_shows.show_id in stead. cur_indexer_id = int(cur_status_result[b'indexer']) cur_series_id = int(cur_status_result[b'indexer_id']) if (cur_indexer_id, cur_series_id) not in ep_counts: ep_counts[(cur_indexer_id, cur_series_id)] = 1 else: ep_counts[(cur_indexer_id, cur_series_id)] += 1 show_names[(cur_indexer_id, cur_series_id)] = cur_status_result[b'show_name'] if (cur_indexer_id, cur_series_id) not in sorted_show_ids: sorted_show_ids.append((cur_indexer_id, cur_series_id)) return t.render(whichSubs=whichSubs, show_names=show_names, ep_counts=ep_counts, sorted_show_ids=sorted_show_ids, title='Missing Subtitles', header='Missing Subtitles', topmenu='manage', controller='manage', action='subtitleMissed')
def showSubtitleMissed(indexer, seriesid, whichSubs): main_db_con = db.DBConnection() cur_show_results = main_db_con.select( 'SELECT season, episode, name, subtitles ' 'FROM tv_episodes ' 'WHERE indexer = ? ' 'AND showid = ? ' 'AND season != 0 ' 'AND status = ? ' "AND location != ''", [int(indexer), int(seriesid), DOWNLOADED] ) result = {} for cur_result in cur_show_results: if whichSubs == 'all': if not frozenset(subtitles.wanted_languages()).difference(cur_result['subtitles'].split(',')): continue elif whichSubs in cur_result['subtitles']: continue cur_season = int(cur_result['season']) cur_episode = int(cur_result['episode']) if cur_season not in result: result[cur_season] = {} if cur_episode not in result[cur_season]: result[cur_season][cur_episode] = {} result[cur_season][cur_episode]['name'] = cur_result['name'] result[cur_season][cur_episode]['subtitles'] = cur_result['subtitles'] return json.dumps(result)
def config_subtitles(): return { 'enabled': bool(app.USE_SUBTITLES), 'languages': app.SUBTITLES_LANGUAGES, 'wantedLanguages': [{ 'id': code, 'name': name_from_code(code) } for code in wanted_languages()], 'codeFilter': [{ 'id': code, 'name': name_from_code(code) } for code in subtitle_code_filter()], 'services': app.SUBTITLE_SERVICES, 'stopAtFirst': bool(app.SUBTITLES_STOP_AT_FIRST), 'eraseCache': bool(app.SUBTITLES_ERASE_CACHE), 'location': app.SUBTITLES_DIR, 'finderFrequency': int(app.SUBTITLES_FINDER_FREQUENCY), 'perfectMatch': bool(app.SUBTITLES_PERFECT_MATCH), 'logHistory': bool(app.SUBTITLES_HISTORY), 'multiLanguage': bool(app.SUBTITLES_MULTI), 'keepOnlyWanted': bool(app.SUBTITLES_KEEP_ONLY_WANTED), 'ignoreEmbeddedSubs': bool(app.IGNORE_EMBEDDED_SUBS), 'acceptUnknownEmbeddedSubs': bool(app.ACCEPT_UNKNOWN_EMBEDDED_SUBS), 'hearingImpaired': bool(app.SUBTITLES_HEARING_IMPAIRED), 'preScripts': app.SUBTITLES_PRE_SCRIPTS, 'extraScripts': app.SUBTITLES_EXTRA_SCRIPTS, 'wikiUrl': app.SUBTITLES_URL, 'providerLogins': { 'addic7ed': { 'user': app.ADDIC7ED_USER, 'pass': app.ADDIC7ED_PASS }, 'legendastv': { 'user': app.LEGENDASTV_USER, 'pass': app.LEGENDASTV_PASS }, 'opensubtitles': { 'user': app.OPENSUBTITLES_USER, 'pass': app.OPENSUBTITLES_PASS } } }
def test_wanted_languages__only_valid_3letter_codes(monkeypatch): # Given monkeypatch.setattr(app, 'SUBTITLES_LANGUAGES', ['pob', 'trash', 'eng', 'fre', 'abc', 'pt-BR']) # When actual = sut.wanted_languages() # Then assert {'pob', 'eng', 'fre'} == actual
def test_wanted_languages__only_valid_3letter_codes(monkeypatch): # Given monkeypatch.setattr(app, 'SUBTITLES_LANGUAGES', ['pob', 'trash', 'eng', 'fre', 'abc', 'pt-BR']) # When actual = sut.wanted_languages() # Then assert {'pob', 'eng', 'fre'} == actual
def subtitleMissed(self, whichSubs=None): t = PageTemplate(rh=self, filename='manage_subtitleMissed.mako') if not whichSubs: return t.render(whichSubs=whichSubs, show_names=None, ep_counts=None, sorted_show_ids=None, controller='manage', action='subtitleMissed') main_db_con = db.DBConnection() status_results = main_db_con.select( 'SELECT show_name, tv_shows.show_id, tv_shows.indexer, ' 'tv_shows.indexer_id as indexer_id, tv_episodes.subtitles subtitles ' 'FROM tv_episodes, tv_shows ' 'WHERE tv_shows.subtitles = 1 ' 'AND tv_episodes.status = ? ' 'AND tv_episodes.season != 0 ' "AND tv_episodes.location != '' " 'AND tv_episodes.showid = tv_shows.indexer_id ' 'AND tv_episodes.indexer = tv_shows.indexer ' 'ORDER BY show_name', [DOWNLOADED] ) ep_counts = {} show_names = {} sorted_show_ids = [] for cur_status_result in status_results: if whichSubs == 'all': if not frozenset(subtitles.wanted_languages()).difference(cur_status_result['subtitles'].split(',')): continue elif whichSubs in cur_status_result['subtitles']: continue # FIXME: This will cause multi-indexer results where series_id overlaps for different indexers. # Fix by using tv_shows.show_id in stead. cur_indexer_id = int(cur_status_result['indexer']) cur_series_id = int(cur_status_result['indexer_id']) if (cur_indexer_id, cur_series_id) not in ep_counts: ep_counts[(cur_indexer_id, cur_series_id)] = 1 else: ep_counts[(cur_indexer_id, cur_series_id)] += 1 show_names[(cur_indexer_id, cur_series_id)] = cur_status_result['show_name'] if (cur_indexer_id, cur_series_id) not in sorted_show_ids: sorted_show_ids.append((cur_indexer_id, cur_series_id)) return t.render(whichSubs=whichSubs, show_names=show_names, ep_counts=ep_counts, sorted_show_ids=sorted_show_ids, title='Missing Subtitles', header='Missing Subtitles', controller='manage', action='subtitleMissed')