def get_ban_list(profile_id): if profile_id: profile = get_profiles_list(profile_id) if profile: return { 'must_contain': profile['mustContain'] or [], 'must_not_contain': profile['mustNotContain'] or [] } return None
def _get_language_obj(profile_id): initial_language_set = set() language_set = set() # where [3] is items list of dict(id, lang, forced, hi) language_items = get_profiles_list(profile_id=int(profile_id))['items'] for language in language_items: forced = language['forced'] hi = language['hi'] language = language['language'] lang = alpha3_from_alpha2(language) lang_obj = _get_lang_obj(lang) if forced == "True": lang_obj = Language.rebuild(lang_obj, forced=True) if hi == "True": lang_obj = Language.rebuild(lang_obj, hi=True) initial_language_set.add(lang_obj) language_set = initial_language_set.copy() for language in language_set.copy(): lang_obj_for_hi = language if not language.forced and not language.hi: lang_obj_hi = Language.rebuild(lang_obj_for_hi, hi=True) elif not language.forced and language.hi: lang_obj_hi = Language.rebuild(lang_obj_for_hi, hi=False) else: continue language_set.add(lang_obj_hi) return language_set, initial_language_set
def list_missing_subtitles_movies(no=None, epno=None, send_event=True): if no is not None: movies_subtitles_clause = " WHERE radarrId=" + str(no) else: movies_subtitles_clause = "" movies_subtitles = database.execute( "SELECT radarrId, subtitles, profileId, audio_language FROM table_movies" + movies_subtitles_clause) if isinstance(movies_subtitles, str): logging.error( "BAZARR list missing subtitles query to DB returned this instead of rows: " + movies_subtitles) return use_embedded_subs = settings.general.getboolean('use_embedded_subs') for movie_subtitles in movies_subtitles: missing_subtitles_text = '[]' if movie_subtitles['profileId']: # get desired subtitles desired_subtitles_temp = get_profiles_list( profile_id=movie_subtitles['profileId']) desired_subtitles_list = [] if desired_subtitles_temp: for language in ast.literal_eval( desired_subtitles_temp['items']): if language['audio_exclude'] == "True": cutoff_lang_temp = get_profile_cutoff( profile_id=movie_subtitles['profileId']) if cutoff_lang_temp: if language_from_alpha2( cutoff_lang_temp[0] ['language']) in ast.literal_eval( movie_subtitles['audio_language']): desired_subtitles_list = [] break if language_from_alpha2( language['language']) in ast.literal_eval( movie_subtitles['audio_language']): continue desired_subtitles_list.append([ language['language'], language['forced'], language['hi'] ]) # get existing subtitles actual_subtitles_list = [] if movie_subtitles['subtitles'] is not None: if use_embedded_subs: actual_subtitles_temp = ast.literal_eval( movie_subtitles['subtitles']) else: actual_subtitles_temp = [ x for x in ast.literal_eval(movie_subtitles['subtitles']) if x[1] ] for subtitles in actual_subtitles_temp: subtitles = subtitles[0].split(':') lang = subtitles[0] forced = False hi = False if len(subtitles) > 1: if subtitles[1] == 'forced': forced = True hi = False elif subtitles[1] == 'hi': forced = False hi = True actual_subtitles_list.append([lang, str(forced), str(hi)]) # check if cutoff is reached and skip any further check cutoff_met = False cutoff_temp_list = get_profile_cutoff( profile_id=movie_subtitles['profileId']) if cutoff_temp_list: for cutoff_temp in cutoff_temp_list: cutoff_language = [ cutoff_temp['language'], cutoff_temp['forced'], cutoff_temp['hi'] ] if cutoff_language in actual_subtitles_list: cutoff_met = True missing_subtitles_text = str([]) elif cutoff_language and [ cutoff_language[0], 'True', 'False' ] in actual_subtitles_list: cutoff_met = True missing_subtitles_text = str([]) elif cutoff_language and [ cutoff_language[0], 'False', 'True' ] in actual_subtitles_list: cutoff_met = True missing_subtitles_text = str([]) if not cutoff_met: # get difference between desired and existing subtitles missing_subtitles_list = [] for item in desired_subtitles_list: if item not in actual_subtitles_list: missing_subtitles_list.append(item) # remove missing that have forced or hi subtitles for this language in existing for item in actual_subtitles_list: if item[1] == 'True' or item[2] == 'True': try: missing_subtitles_list.remove( [item[0], 'False', 'False']) except ValueError: pass # make the missing languages list looks like expected missing_subtitles_output_list = [] for item in missing_subtitles_list: lang = item[0] if item[1] == 'True': lang += ':forced' elif item[2] == 'True': lang += ':hi' missing_subtitles_output_list.append(lang) missing_subtitles_text = str(missing_subtitles_output_list) database.execute( "UPDATE table_movies SET missing_subtitles=? WHERE radarrId=?", (missing_subtitles_text, movie_subtitles['radarrId'])) if send_event: event_stream(type='movie', action='update', movie=movie_subtitles['radarrId']) event_stream(type='badges_movies')
def get(self): return jsonify(get_profiles_list())
def list_missing_subtitles_movies(no=None, send_event=True): movies_subtitles = TableMovies.select(TableMovies.radarrId, TableMovies.subtitles, TableMovies.profileId, TableMovies.audio_language)\ .where((TableMovies.radarrId == no) if no else None)\ .dicts() if isinstance(movies_subtitles, str): logging.error("BAZARR list missing subtitles query to DB returned this instead of rows: " + movies_subtitles) return use_embedded_subs = settings.general.getboolean('use_embedded_subs') for movie_subtitles in movies_subtitles: missing_subtitles_text = '[]' if movie_subtitles['profileId']: # get desired subtitles desired_subtitles_temp = get_profiles_list(profile_id=movie_subtitles['profileId']) desired_subtitles_list = [] if desired_subtitles_temp: for language in desired_subtitles_temp['items']: if language['audio_exclude'] == "True": if language_from_alpha2(language['language']) in ast.literal_eval( movie_subtitles['audio_language']): continue desired_subtitles_list.append([language['language'], language['forced'], language['hi']]) # get existing subtitles actual_subtitles_list = [] if movie_subtitles['subtitles'] is not None: if use_embedded_subs: actual_subtitles_temp = ast.literal_eval(movie_subtitles['subtitles']) else: actual_subtitles_temp = [x for x in ast.literal_eval(movie_subtitles['subtitles']) if x[1]] for subtitles in actual_subtitles_temp: subtitles = subtitles[0].split(':') lang = subtitles[0] forced = False hi = False if len(subtitles) > 1: if subtitles[1] == 'forced': forced = True hi = False elif subtitles[1] == 'hi': forced = False hi = True actual_subtitles_list.append([lang, str(forced), str(hi)]) # check if cutoff is reached and skip any further check cutoff_met = False cutoff_temp_list = get_profile_cutoff(profile_id=movie_subtitles['profileId']) if cutoff_temp_list: for cutoff_temp in cutoff_temp_list: cutoff_language = [cutoff_temp['language'], cutoff_temp['forced'], cutoff_temp['hi']] if cutoff_temp['audio_exclude'] == 'True' and language_from_alpha2(cutoff_temp['language']) in \ ast.literal_eval(movie_subtitles['audio_language']): cutoff_met = True elif cutoff_language in actual_subtitles_list: cutoff_met = True elif cutoff_language and [cutoff_language[0], 'True', 'False'] in actual_subtitles_list: cutoff_met = True elif cutoff_language and [cutoff_language[0], 'False', 'True'] in actual_subtitles_list: cutoff_met = True if cutoff_met: missing_subtitles_text = str([]) else: # get difference between desired and existing subtitles missing_subtitles_list = [] for item in desired_subtitles_list: if item not in actual_subtitles_list: missing_subtitles_list.append(item) # remove missing that have forced or hi subtitles for this language in existing for item in actual_subtitles_list: if item[2] == 'True': try: missing_subtitles_list.remove([item[0], 'False', 'False']) except ValueError: pass # make the missing languages list looks like expected missing_subtitles_output_list = [] for item in missing_subtitles_list: lang = item[0] if item[1] == 'True': lang += ':forced' elif item[2] == 'True': lang += ':hi' missing_subtitles_output_list.append(lang) missing_subtitles_text = str(missing_subtitles_output_list) TableMovies.update({TableMovies.missing_subtitles: missing_subtitles_text})\ .where(TableMovies.radarrId == movie_subtitles['radarrId'])\ .execute() if send_event: event_stream(type='movie', payload=movie_subtitles['radarrId']) event_stream(type='badges')