From 41b18cb5de058f793c808c0c09223eeaee8166fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Louis=20V=C3=A9zina?= <5130500+morpheus65535@users.noreply.github.com> Date: Mon, 11 May 2020 00:39:21 -0400 Subject: [PATCH] WIP --- bazarr/check_update.py | 12 ----------- bazarr/get_episodes.py | 5 ----- bazarr/get_movies.py | 5 ----- bazarr/get_series.py | 5 ----- bazarr/get_subtitle.py | 33 ---------------------------- bazarr/list_subtitles.py | 5 ----- bazarr/queueconfig.py | 43 ------------------------------------- bazarr/websocket_handler.py | 2 +- views/_main.html | 1 + 9 files changed, 2 insertions(+), 109 deletions(-) delete mode 100644 bazarr/queueconfig.py diff --git a/bazarr/check_update.py b/bazarr/check_update.py index 732f4572b..418263072 100644 --- a/bazarr/check_update.py +++ b/bazarr/check_update.py @@ -7,7 +7,6 @@ import tarfile from get_args import args from config import settings -from queueconfig import notifications from database import database if not args.no_update and not args.release_update: @@ -45,7 +44,6 @@ def check_and_apply_update(): g.fetch('origin') result = g.diff('--shortstat', 'origin/' + branch) if len(result) == 0: - notifications.write(msg='No new version of Bazarr available.', queue='check_update') logging.info('BAZARR No new version of Bazarr available.') else: g.reset('--hard', 'HEAD') @@ -59,8 +57,6 @@ def check_and_apply_update(): releases = request_json(url, timeout=20, whitelist_status_code=404, validator=lambda x: type(x) == list) if releases is None: - notifications.write(msg='Could not get releases from GitHub.', - queue='check_update', type='warning') logging.warning('BAZARR Could not get releases from GitHub.') return else: @@ -70,7 +66,6 @@ def check_and_apply_update(): if ('v' + os.environ["BAZARR_VERSION"]) != latest_release: update_from_source() else: - notifications.write(msg='Bazarr is up to date', queue='check_update') logging.info('BAZARR is up to date') @@ -79,13 +74,10 @@ def update_from_source(): update_dir = os.path.join(os.path.dirname(__file__), '..', 'update') logging.info('BAZARR Downloading update from: ' + tar_download_url) - notifications.write(msg='Downloading update from: ' + tar_download_url, queue='check_update') data = request_content(tar_download_url) if not data: logging.error("BAZARR Unable to retrieve new version from '%s', can't update", tar_download_url) - notifications.write(msg=("Unable to retrieve new version from '%s', can't update", tar_download_url), - type='error', queue='check_update') return download_name = settings.general.branch + '-github' @@ -97,22 +89,18 @@ def update_from_source(): # Extract the tar to update folder logging.info('BAZARR Extracting file: ' + tar_download_path) - notifications.write(msg='Extracting file: ' + tar_download_path, queue='check_update') tar = tarfile.open(tar_download_path) tar.extractall(update_dir) tar.close() # Delete the tar.gz logging.info('BAZARR Deleting file: ' + tar_download_path) - notifications.write(msg='Deleting file: ' + tar_download_path, queue='check_update') os.remove(tar_download_path) # Find update dir name update_dir_contents = [x for x in os.listdir(update_dir) if os.path.isdir(os.path.join(update_dir, x))] if len(update_dir_contents) != 1: logging.error("BAZARR Invalid update data, update failed: " + str(update_dir_contents)) - notifications.write(msg="BAZARR Invalid update data, update failed: " + str(update_dir_contents), - type='error', queue='check_update') return content_dir = os.path.join(update_dir, update_dir_contents[0]) diff --git a/bazarr/get_episodes.py b/bazarr/get_episodes.py index 4ac83fab6..92c9afd57 100644 --- a/bazarr/get_episodes.py +++ b/bazarr/get_episodes.py @@ -1,7 +1,6 @@ # coding=utf-8 import requests import logging -from queueconfig import notifications from database import database, dict_converter from config import settings, url_sonarr @@ -17,7 +16,6 @@ def update_all_episodes(): def sync_episodes(): - notifications.write(msg='Episodes sync from Sonarr started...', queue='get_episodes') logging.debug('BAZARR Starting episodes sync from Sonarr.') apikey_sonarr = settings.sonarr.apikey @@ -36,7 +34,6 @@ def sync_episodes(): seriesIdListLength = len(seriesIdList) for i, seriesId in enumerate(seriesIdList, 1): - notifications.write(msg='Getting episodes data from Sonarr...', queue='get_episodes', item=i, length=seriesIdListLength) # Get episodes data for a series from Sonarr url_sonarr_api_episode = url_sonarr() + "/api/episode?seriesId=" + str(seriesId['sonarrSeriesId']) + "&apikey=" + apikey_sonarr try: @@ -165,8 +162,6 @@ def sync_episodes(): # Store subtitles for added or modified episodes for i, altered_episode in enumerate(altered_episodes, 1): - notifications.write(msg='Indexing episodes embedded subtitles...', queue='get_episodes', item=i, - length=len(altered_episodes)) store_subtitles(altered_episode[1], path_replace(altered_episode[1])) logging.debug('BAZARR All episodes synced from Sonarr into database.') diff --git a/bazarr/get_movies.py b/bazarr/get_movies.py index 83a613b66..16606b03a 100644 --- a/bazarr/get_movies.py +++ b/bazarr/get_movies.py @@ -3,7 +3,6 @@ import os import requests import logging -from queueconfig import notifications from config import settings, url_radarr from helper import path_replace_movie @@ -70,8 +69,6 @@ def update_movies(): moviesIdListLength = len(r.json()) for i, movie in enumerate(r.json(), 1): - notifications.write(msg="Getting movies data from Radarr...", queue='get_movies', item=i, - length=moviesIdListLength) if movie['hasFile'] is True: if 'movieFile' in movie: # Detect file separator @@ -233,8 +230,6 @@ def update_movies(): # Store subtitles for added or modified movies for i, altered_movie in enumerate(altered_movies, 1): - notifications.write(msg='Indexing movies embedded subtitles...', queue='get_movies', item=i, - length=len(altered_movies)) store_subtitles_movie(altered_movie[1], path_replace_movie(altered_movie[1])) logging.debug('BAZARR All movies synced from Radarr into database.') diff --git a/bazarr/get_series.py b/bazarr/get_series.py index fc5d96c3c..215e9d7e9 100644 --- a/bazarr/get_series.py +++ b/bazarr/get_series.py @@ -3,7 +3,6 @@ import os import requests import logging -from queueconfig import notifications from config import settings, url_sonarr from list_subtitles import list_missing_subtitles @@ -14,7 +13,6 @@ from websocket_handler import event_stream def update_series(): - notifications.write(msg="Update series list from Sonarr is running...", queue='get_series') apikey_sonarr = settings.sonarr.apikey if apikey_sonarr is None: return @@ -61,9 +59,6 @@ def update_series(): series_list_length = len(r.json()) for i, show in enumerate(r.json(), 1): - notifications.write(msg="Getting series data from Sonarr...", queue='get_series', item=i, - length=series_list_length) - overview = show['overview'] if 'overview' in show else '' poster = '' fanart = '' diff --git a/bazarr/get_subtitle.py b/bazarr/get_subtitle.py index 1a9cb1ebe..e7055f9cf 100644 --- a/bazarr/get_subtitle.py +++ b/bazarr/get_subtitle.py @@ -28,7 +28,6 @@ from list_subtitles import store_subtitles, list_missing_subtitles, store_subtit from utils import history_log, history_log_movie, get_binary from notifier import send_notifications, send_notifications_movie from get_providers import get_providers, get_providers_auth, provider_throttle, provider_pool -from queueconfig import notifications from knowit import api from database import database, dict_mapper @@ -579,8 +578,6 @@ def series_download_subtitles(no): if providers_list: for language in ast.literal_eval(episode['missing_subtitles']): if language is not None: - notifications.write(msg='Searching for Series Subtitles...', queue='get_subtitle', item=i, - length=count_episodes_details) result = download_subtitle(path_replace(episode['path']), str(alpha3_from_alpha2(language.split(':')[0])), series_details['audio_language'], @@ -602,13 +599,8 @@ def series_download_subtitles(no): history_log(1, no, episode['sonarrEpisodeId'], message, path, language_code, provider, score) send_notifications(no, episode['sonarrEpisodeId'], message) else: - notifications.write(msg='BAZARR All providers are throttled', queue='get_subtitle', duration='long') logging.info("BAZARR All providers are throttled") break - - if count_episodes_details: - notifications.write(msg='Search Complete. Please Reload The Page.', type='success', duration='permanent', - button='refresh', queue='get_subtitle') def episode_download_subtitles(no): @@ -635,9 +627,6 @@ def episode_download_subtitles(no): if providers_list: for language in ast.literal_eval(episode['missing_subtitles']): if language is not None: - notifications.write(msg='Searching for ' + str( - language_from_alpha2(language)) + ' Subtitles for this episode: ' + - path_replace(episode['path']), queue='get_subtitle') result = download_subtitle(path_replace(episode['path']), str(alpha3_from_alpha2(language.split(':')[0])), episode['audio_language'], @@ -659,7 +648,6 @@ def episode_download_subtitles(no): history_log(1, episode['sonarrSeriesId'], episode['sonarrEpisodeId'], message, path, language_code, provider, score) send_notifications(episode['sonarrSeriesId'], episode['sonarrEpisodeId'], message) else: - notifications.write(msg='BAZARR All providers are throttled', queue='get_subtitle', duration='long') logging.info("BAZARR All providers are throttled") break @@ -688,8 +676,6 @@ def movies_download_subtitles(no): for i, language in enumerate(ast.literal_eval(movie['missing_subtitles']), 1): if providers_list: if language is not None: - notifications.write(msg='Searching for Movie Subtitles', queue='get_subtitle', item=i, - length=count_movie) result = download_subtitle(path_replace_movie(movie['path']), str(alpha3_from_alpha2(language.split(':')[0])), movie['audio_language'], @@ -711,13 +697,8 @@ def movies_download_subtitles(no): history_log_movie(1, no, message, path, language_code, provider, score) send_notifications_movie(no, message) else: - notifications.write(msg='BAZARR All providers are throttled', queue='get_subtitle', duration='long') logging.info("BAZARR All providers are throttled") break - - if count_movie: - notifications.write(msg='Search Complete. Please Reload The Page.', type='success', duration='permanent', - button='refresh', queue='get_subtitle') def wanted_download_subtitles(path, l, count_episodes): @@ -752,8 +733,6 @@ def wanted_download_subtitles(path, l, count_episodes): for i in range(len(attempt)): if attempt[i][0] == language: if search_active(attempt[i][1]): - notifications.write(msg='Searching for Series Subtitles...', queue='get_subtitle', item=l, - length=count_episodes) result = download_subtitle(path_replace(episode['path']), str(alpha3_from_alpha2(language.split(':')[0])), episode['audio_language'], @@ -806,8 +785,6 @@ def wanted_download_subtitles_movie(path, l, count_movies): for i in range(len(attempt)): if attempt[i][0] == language: if search_active(attempt[i][1]) is True: - notifications.write(msg='Searching for Movie Subtitles...', queue='get_subtitle', item=l, - length=count_movies) result = download_subtitle(path_replace_movie(movie['path']), str(alpha3_from_alpha2(language.split(':')[0])), movie['audio_language'], @@ -850,7 +827,6 @@ def wanted_search_missing_subtitles_series(): if providers: wanted_download_subtitles(episode['path'], i, count_episodes) else: - notifications.write(msg='BAZARR All providers are throttled', queue='get_subtitle', duration='long') logging.info("BAZARR All providers are throttled") return @@ -874,7 +850,6 @@ def wanted_search_missing_subtitles_movies(): if providers: wanted_download_subtitles_movie(movie['path'], i, count_movies) else: - notifications.write(msg='BAZARR All providers are throttled', queue='get_subtitle', duration='long') logging.info("BAZARR All providers are throttled") return @@ -1081,7 +1056,6 @@ def upgrade_subtitles(): continue providers = get_providers() if not providers: - notifications.write(msg='BAZARR All providers are throttled', queue='get_subtitle', duration='long') logging.info("BAZARR All providers are throttled") return if episode['languages']: @@ -1094,9 +1068,6 @@ def upgrade_subtitles(): forced_languages = desired_languages if episode['language'] in forced_languages: - notifications.write(msg='Upgrading Series Subtitles...', - queue='upgrade_subtitle', item=i, length=count_episode_to_upgrade) - if episode['language'].endswith('forced'): language = episode['language'].split(':')[0] is_forced = "True" @@ -1133,7 +1104,6 @@ def upgrade_subtitles(): continue providers = get_providers() if not providers: - notifications.write(msg='BAZARR All providers are throttled', queue='get_subtitle', duration='long') logging.info("BAZARR All providers are throttled") return if movie['languages']: @@ -1146,9 +1116,6 @@ def upgrade_subtitles(): forced_languages = desired_languages if movie['language'] in forced_languages: - notifications.write(msg='Upgrading Movie Subtitles...', - queue='upgrade_subtitle', item=i, length=count_movie_to_upgrade) - if movie['language'].endswith('forced'): language = movie['language'].split(':')[0] is_forced = "True" diff --git a/bazarr/list_subtitles.py b/bazarr/list_subtitles.py index 59a829e26..b97374f56 100644 --- a/bazarr/list_subtitles.py +++ b/bazarr/list_subtitles.py @@ -18,7 +18,6 @@ from config import settings from helper import path_replace, path_replace_movie, path_replace_reverse, \ path_replace_reverse_movie, get_subtitle_destination_folder -from queueconfig import notifications from embedded_subs_reader import embedded_subs_reader from websocket_handler import event_stream import chardet @@ -305,8 +304,6 @@ def series_full_scan_subtitles(): count_episodes = len(episodes) for i, episode in enumerate(episodes, 1): - notifications.write(msg='Updating all episodes subtitles from disk...', - queue='list_subtitles_series', item=i, length=count_episodes) store_subtitles(episode['path'], path_replace(episode['path'])) gc.collect() @@ -317,8 +314,6 @@ def movies_full_scan_subtitles(): count_movies = len(movies) for i, movie in enumerate(movies, 1): - notifications.write(msg='Updating all movies subtitles from disk...', - queue='list_subtitles_movies', item=i, length=count_movies) store_subtitles_movie(movie['path'], path_replace_movie(movie['path'])) gc.collect() diff --git a/bazarr/queueconfig.py b/bazarr/queueconfig.py deleted file mode 100644 index ff5968d23..000000000 --- a/bazarr/queueconfig.py +++ /dev/null @@ -1,43 +0,0 @@ -from collections import deque -import json - - -class Notify: - """ - This class is used to read or write items to the notifications deque. - """ - - def __init__(self): - self.queue = deque(maxlen=10) - - def write(self, msg, type='info', duration='temporary', button='null', queue='main', item=0, length=0): - """ - :param msg: The message to display. - :type msg: str - :param type: The type of notification that can be: alert, success, error, warning, info - :type type: str - :param duration: The duration of the notification that can be: temporary, permanent - :type duration: str - :param button: The kind of button desired that can be: null, refresh, restart - :type button: str - :param queue: The name of the notification queue to use. Default is 'main' - :type duration: str - :param item: The number of the item for progress bar - :type item: int - :param length: The length of the group of item for progress bar - :type length: int - """ - - self.queue.append(json.dumps([msg, type, duration, button, queue, item, length])) - - def read(self): - """ - :return: Return the oldest notification available. - :rtype: str - """ - - if self.queue and (len(self.queue) > 0): - return self.queue.popleft() - - -notifications = Notify() diff --git a/bazarr/websocket_handler.py b/bazarr/websocket_handler.py index e22654432..c4ce33e0e 100644 --- a/bazarr/websocket_handler.py +++ b/bazarr/websocket_handler.py @@ -4,7 +4,7 @@ from app import socketio class EventStream: """ - This class is used to read or write items to the notifications deque. + This class is used to broadcast notifications to web client. """ def __init__(self): diff --git a/views/_main.html b/views/_main.html index b8723d9a8..f68ff8bdb 100644 --- a/views/_main.html +++ b/views/_main.html @@ -320,6 +320,7 @@ events = io.connect({ path: '{{ settings.general.base_url.rstrip('/') }}/socket.io', + transports: ['polling'], upgrade: false, reconnection: true, reconnectionDelay: 1000,