From c2de011fad50600e0aab34ad0656f205ce96a115 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Louis=20V=C3=A9zina?= <5130500+morpheus65535@users.noreply.github.com> Date: Tue, 21 Jan 2020 23:54:32 -0500 Subject: [PATCH] WIP --- bazarr/api.py | 62 +++++++++++ bazarr/get_episodes.py | 7 ++ bazarr/list_subtitles.py | 6 +- bazarr/logger.py | 6 +- bazarr/main.py | 62 +---------- views/_main.html | 49 ++------- views/episodes.html | 232 ++++++++++++++++++++++++++++++++++----- views/series.html | 18 +-- 8 files changed, 296 insertions(+), 146 deletions(-) diff --git a/bazarr/api.py b/bazarr/api.py index 259d717c7..b3440c22c 100644 --- a/bazarr/api.py +++ b/bazarr/api.py @@ -44,6 +44,16 @@ class Badges(Resource): return jsonify(result) +class Languages(Resource): + def get(self): + enabled = request.args.get('enabled') + if enabled.lower() in ['true', '1']: + result = database.execute("SELECT * FROM table_settings_languages WHERE enabled=1") + else: + result = database.execute("SELECT * FROM table_settings_languages") + return jsonify(result) + + class Series(Resource): def get(self): start = request.args.get('start') or 0 @@ -96,6 +106,41 @@ class Series(Resource): return jsonify(draw=draw, recordsTotal=row_count, recordsFiltered=row_count, data=result) + def post(self): + seriesId = request.args.get('seriesid') + + lang = request.form.getlist('languages') + if len(lang) > 0: + pass + else: + lang = 'None' + + single_language = settings.general.getboolean('single_language') + if single_language: + if str(lang) == "['None']": + lang = 'None' + else: + lang = str(lang) + else: + if str(lang) == "['']": + lang = '[]' + + hi = request.form.get('hearing_impaired') + forced = request.form.get('forced') + + if hi == "on": + hi = "True" + else: + hi = "False" + + result = database.execute("UPDATE table_shows SET languages=?, hearing_impaired=?, forced=? WHERE " + "sonarrSeriesId=?", (str(lang), hi, forced, seriesId)) + + list_missing_subtitles(no=seriesId) + + return '', 204 + + class Episodes(Resource): def get(self): start = request.args.get('start') or 0 @@ -317,6 +362,20 @@ class EpisodesSubtitlesUpload(Resource): return '', 204 +class EpisodesScanDisk(Resource): + def get(self): + seriesid = request.args.get('seriesid') + series_scan_subtitles(seriesid) + return '', 200 + + +class EpisodesSearchMissing(Resource): + def get(self): + seriesid = request.args.get('seriesid') + series_download_subtitles(seriesid) + return '', 200 + + class Movies(Resource): def get(self): start = request.args.get('start') or 0 @@ -622,6 +681,7 @@ class WantedMovies(Resource): api.add_resource(Badges, '/badges') +api.add_resource(Languages, '/languages') api.add_resource(Series, '/series') api.add_resource(Episodes, '/episodes') api.add_resource(EpisodesSubtitlesDelete, '/episodes_subtitles_delete') @@ -629,6 +689,8 @@ api.add_resource(EpisodesSubtitlesDownload, '/episodes_subtitles_download') api.add_resource(EpisodesSubtitlesManualSearch, '/episodes_subtitles_manual_search') api.add_resource(EpisodesSubtitlesManualDownload, '/episodes_subtitles_manual_download') api.add_resource(EpisodesSubtitlesUpload, '/episodes_subtitles_upload') +api.add_resource(EpisodesScanDisk, '/episodes_scan_disk') +api.add_resource(EpisodesSearchMissing, '/episodes_search_missing') api.add_resource(Movies, '/movies') api.add_resource(HistorySeries, '/history_series') api.add_resource(HistoryMovies, '/history_movies') diff --git a/bazarr/get_episodes.py b/bazarr/get_episodes.py index 6bdf32202..2a2830374 100644 --- a/bazarr/get_episodes.py +++ b/bazarr/get_episodes.py @@ -12,6 +12,7 @@ from config import settings, url_sonarr from helper import path_replace from list_subtitles import list_missing_subtitles, store_subtitles, series_full_scan_subtitles from get_subtitle import episode_download_subtitles +from websocket_handler import event_stream def update_all_episodes(): @@ -128,7 +129,11 @@ def sync_episodes(): removed_episodes = list(set(current_episodes_db_list) - set(current_episodes_sonarr)) for removed_episode in removed_episodes: + episode_to_delete = database.execute("SELECT sonarrSeriesId, sonarrEpisodeId FROM table_episodes WHERE " + "sonarrEpisodeId=?", (removed_episode,), only_one=True) database.execute("DELETE FROM table_episodes WHERE sonarrEpisodeId=?", (removed_episode,)) + event_stream.write(type='episode', action='delete', series=episode_to_delete['sonarrSeriesId'], + episode=episode_to_delete['sonarrEpisodeId']) # Update existing episodes in DB episode_in_db_list = [] @@ -157,6 +162,8 @@ def sync_episodes(): ''')''', query.values) if result > 0: altered_episodes.append([added_episode['sonarrEpisodeId'], added_episode['path']]) + event_stream.write(type='episode', action='insert', series=added_episode['sonarrSeriesId'], + episode=added_episode['sonarrEpisodeId']) else: logging.debug('BAZARR unable to insert this episode into the database:', path_replace(added_episode['path'])) diff --git a/bazarr/list_subtitles.py b/bazarr/list_subtitles.py index 281f38d76..84afda725 100644 --- a/bazarr/list_subtitles.py +++ b/bazarr/list_subtitles.py @@ -232,12 +232,16 @@ def list_missing_subtitles(no=None, epno=None): else: actual_subtitles_list.append(item[0]) missing_subtitles = list(set(desired_subtitles) - set(actual_subtitles_list)) - missing_subtitles_global.append(tuple([str(missing_subtitles), episode_subtitles['sonarrEpisodeId']])) + missing_subtitles_global.append(tuple([str(missing_subtitles), episode_subtitles['sonarrEpisodeId'], + episode_subtitles['sonarrSeriesId']])) for missing_subtitles_item in missing_subtitles_global: database.execute("UPDATE table_episodes SET missing_subtitles=? WHERE sonarrEpisodeId=?", (missing_subtitles_item[0], missing_subtitles_item[1])) + event_stream.write(type='episode', action='update', series=missing_subtitles_item[2], + episode=missing_subtitles_item[1]) + def list_missing_subtitles_movies(no=None): if no is not None: diff --git a/bazarr/logger.py b/bazarr/logger.py index daa545a2e..1bf8a6476 100644 --- a/bazarr/logger.py +++ b/bazarr/logger.py @@ -84,6 +84,8 @@ def configure_logging(debug=False): logging.getLogger("subzero").setLevel(logging.DEBUG) logging.getLogger("git").setLevel(logging.DEBUG) logging.getLogger("apprise").setLevel(logging.DEBUG) + logging.getLogger("engineio.server").setLevel(logging.DEBUG) + logging.getLogger("socketio.server").setLevel(logging.DEBUG) logging.debug('Bazarr version: %s', os.environ["BAZARR_VERSION"]) logging.debug('Bazarr branch: %s', settings.general.branch) logging.debug('Operating system: %s', platform.platform()) @@ -94,7 +96,9 @@ def configure_logging(debug=False): logging.getLogger("subliminal").setLevel(logging.CRITICAL) logging.getLogger("subliminal_patch").setLevel(logging.CRITICAL) logging.getLogger("subzero").setLevel(logging.ERROR) - + logging.getLogger("engineio.server").setLevel(logging.ERROR) + logging.getLogger("socketio.server").setLevel(logging.ERROR) + logging.getLogger("enzyme").setLevel(logging.CRITICAL) logging.getLogger("guessit").setLevel(logging.WARNING) logging.getLogger("rebulk").setLevel(logging.WARNING) diff --git a/bazarr/main.py b/bazarr/main.py index c8f9b5759..600fb69f5 100644 --- a/bazarr/main.py +++ b/bazarr/main.py @@ -564,44 +564,6 @@ def search_json(query): return dict(items=search_list) -@app.route('/edit_series/', methods=['POST']) -@login_required -def edit_series(no): - - ref = request.environ['HTTP_REFERER'] - - lang = request.form.getlist('languages') - if len(lang) > 0: - pass - else: - lang = 'None' - - single_language = settings.general.getboolean('single_language') - if single_language: - if str(lang) == "['None']": - lang = 'None' - else: - lang = str(lang) - else: - if str(lang) == "['']": - lang = '[]' - - hi = request.form.get('hearing_impaired') - forced = request.form.get('forced') - - if hi == "on": - hi = "True" - else: - hi = "False" - - result = database.execute("UPDATE table_shows SET languages=?, hearing_impaired=?, forced=? WHERE " - "sonarrSeriesId=?", (str(lang), hi, forced, no)) - - list_missing_subtitles(no=no) - - redirect(ref) - - @app.route('/edit_serieseditor', methods=['POST']) @login_required def edit_serieseditor(): @@ -753,13 +715,6 @@ def movie(no): current_port=settings.general.port) -@app.route('/scan_disk/', methods=['GET']) -@login_required -def scan_disk(no): - series_scan_subtitles(no) - return '', 200 - - @app.route('/scan_disk_movie/', methods=['GET']) @login_required def scan_disk_movie(no): @@ -767,17 +722,6 @@ def scan_disk_movie(no): return '', 200 -@app.route('/search_missing_subtitles/', methods=['GET']) -@login_required -def search_missing_subtitles(no): - - ref = request.environ['HTTP_REFERER'] - - add_job(series_download_subtitles, args=[no], name=('search_missing_subtitles_' + str(no))) - - redirect(ref) - - @app.route('/search_missing_subtitles_movie/', methods=['GET']) @login_required def search_missing_subtitles_movie(no): @@ -1419,12 +1363,8 @@ def get_logs(): @app.route('/execute/') @login_required def execute_task(taskid): - - ref = request.environ['HTTP_REFERER'] - execute_now(taskid) - - redirect(ref) + return '', 200 @app.route('/remove_subtitles_movie', methods=['POST']) diff --git a/views/_main.html b/views/_main.html index b0c9ef3ef..f78d1e02a 100644 --- a/views/_main.html +++ b/views/_main.html @@ -33,6 +33,7 @@ href="{{ url_for('static',filename='datatables/responsive.dataTables.min.css') }}"> + {% endblock head_css %} {% block head %} @@ -252,6 +253,7 @@ + diff --git a/views/series.html b/views/series.html index 380c44c6b..452f4a788 100644 --- a/views/series.html +++ b/views/series.html @@ -86,25 +86,11 @@ }, { "data": "hearing_impaired", - "className": "dt-center", - "render": function (data) { - if (data === 'False') { - return ''; - } else if (data === 'True') { - return ''; - } - } + "className": "dt-center" }, { "data": "forced", - "className": "dt-center", - "render": function (data) { - if (data === 'False') { - return ''; - } else if (data === 'True') { - return ''; - } - } + "className": "dt-center" }, { "data": null,