From 8e134dcceba3734cddf06d30b09d356f7dd317d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Louis=20V=C3=A9zina?= <5130500+morpheus65535@users.noreply.github.com> Date: Wed, 12 Feb 2020 12:41:40 -0500 Subject: [PATCH] WIP --- bazarr/api.py | 10 +- bazarr/list_subtitles.py | 4 +- bazarr/main.py | 68 +----- bazarr/utils.py | 8 +- views/_main.html | 56 ++--- views/episodes.html | 8 +- views/footer.html | 8 - views/history.html | 126 ----------- views/historymovies.html | 14 +- views/historyseries.html | 15 +- views/menu.html | 466 --------------------------------------- views/movie.html | 20 +- views/movies.html | 2 +- views/movieseditor.html | 6 +- views/series.html | 6 +- views/serieseditor.html | 6 +- views/system.html | 1 - views/wanted.html | 161 -------------- views/wantedmovies.html | 238 +++++--------------- views/wantedseries.html | 250 +++++---------------- 20 files changed, 213 insertions(+), 1260 deletions(-) delete mode 100644 views/footer.html delete mode 100644 views/history.html delete mode 100644 views/menu.html delete mode 100644 views/wanted.html diff --git a/bazarr/api.py b/bazarr/api.py index 5081292b1..14dd7920c 100644 --- a/bazarr/api.py +++ b/bazarr/api.py @@ -298,6 +298,8 @@ class EpisodesSubtitlesDownload(Resource): history_log(1, sonarrSeriesId, sonarrEpisodeId, message, path, language_code, provider, score) send_notifications(sonarrSeriesId, sonarrEpisodeId, message) store_subtitles(path, episodePath) + else: + event_stream.write(type='episode', action='update', series=int(sonarrSeriesId), episode=int(sonarrEpisodeId)) return result, 201 except OSError: pass @@ -637,6 +639,8 @@ class MovieSubtitlesDownload(Resource): history_log_movie(1, radarrId, message, path, language_code, provider, score) send_notifications_movie(radarrId, message) store_subtitles_movie(path, moviePath) + else: + event_stream.write(type='movie', action='update', movie=int(radarrId)) return result, 201 except OSError: pass @@ -953,7 +957,8 @@ class WantedSeries(Resource): else: monitored_only_query_string = '' - row_count = database.execute("SELECT COUNT(*) as count FROM table_episodes", only_one=True)['count'] + row_count = database.execute("SELECT COUNT(*) as count FROM table_episodes WHERE missing_subtitles != '[]'" + + monitored_only_query_string, only_one=True)['count'] data = database.execute("SELECT table_shows.title as seriesTitle, " "table_episodes.season || 'x' || table_episodes.episode as episode_number, " "table_episodes.title as episodeTitle, table_episodes.missing_subtitles, " @@ -996,7 +1001,8 @@ class WantedMovies(Resource): else: monitored_only_query_string = '' - row_count = database.execute("SELECT COUNT(*) as count FROM table_movies", only_one=True)['count'] + row_count = database.execute("SELECT COUNT(*) as count FROM table_movies WHERE missing_subtitles != '[]'" + + monitored_only_query_string, only_one=True)['count'] data = database.execute("SELECT title, missing_subtitles, radarrId, path, hearing_impaired, sceneName, " "failedAttempts FROM table_movies WHERE missing_subtitles != '[]'" + monitored_only_query_string + " ORDER BY _rowid_ DESC LIMIT ? OFFSET ?", diff --git a/bazarr/list_subtitles.py b/bazarr/list_subtitles.py index 9581be461..ca8721e5e 100644 --- a/bazarr/list_subtitles.py +++ b/bazarr/list_subtitles.py @@ -93,7 +93,6 @@ def store_subtitles(original_path, reversed_path): for episode in matching_episodes: if episode: logging.debug("BAZARR storing those languages to DB: " + str(actual_subtitles)) - event_stream.write(type='episode', action='update', series=episode['sonarrSeriesId'], episode=episode['sonarrEpisodeId']) list_missing_subtitles(epno=episode['sonarrEpisodeId']) else: logging.debug("BAZARR haven't been able to update existing subtitles to DB : " + str(actual_subtitles)) @@ -165,7 +164,6 @@ def store_subtitles_movie(original_path, reversed_path): for movie in matching_movies: if movie: logging.debug("BAZARR storing those languages to DB: " + str(actual_subtitles)) - event_stream.write(type='movie', action='update', movie=movie['radarrId']) list_missing_subtitles_movies(no=movie['radarrId']) else: logging.debug("BAZARR haven't been able to update existing subtitles to DB : " + str(actual_subtitles)) @@ -299,6 +297,8 @@ def list_missing_subtitles_movies(no=None): database.execute("UPDATE table_movies SET missing_subtitles=? WHERE radarrId=?", (missing_subtitles_item[0], missing_subtitles_item[1])) + event_stream.write(type='movie', action='update', movie=missing_subtitles_item[1]) + def series_full_scan_subtitles(): episodes = database.execute("SELECT path FROM table_episodes") diff --git a/bazarr/main.py b/bazarr/main.py index 46fc148ca..b71926dad 100644 --- a/bazarr/main.py +++ b/bazarr/main.py @@ -608,76 +608,16 @@ def historymovies(): return render_template('historymovies.html') -@app.route('/wanted') -@login_required -def wanted(): - - return render_template('wanted.html', bazarr_version=bazarr_version, base_url=base_url, current_port=settings.general.port) - - -@app.route('/wantedseries') +@app.route('/wantedseries/') @login_required def wantedseries(): + return render_template('wantedseries.html') - if settings.sonarr.getboolean('only_monitored'): - monitored_only_query_string = " AND monitored='True'" - else: - monitored_only_query_string = '' - - missing_count = database.execute("SELECT COUNT(*) as count FROM table_episodes WHERE missing_subtitles != '[]'" + - monitored_only_query_string, only_one=True)['count'] - page = request.data - if page == "": - page = "1" - page_size = int(settings.general.page_size) - offset = (int(page) - 1) * page_size - max_page = int(math.ceil(missing_count / (page_size + 0.0))) - - data = database.execute("SELECT table_shows.title as seriesTitle, " - "table_episodes.season || 'x' || table_episodes.episode as episode_number, " - "table_episodes.title as episodeTitle, table_episodes.missing_subtitles, table_episodes.sonarrSeriesId, " - "table_episodes.path, table_shows.hearing_impaired, table_episodes.sonarrEpisodeId, " - "table_episodes.scene_name, table_episodes.failedAttempts FROM table_episodes " - "INNER JOIN table_shows on table_shows.sonarrSeriesId = table_episodes.sonarrSeriesId " - "WHERE table_episodes.missing_subtitles != '[]'" + monitored_only_query_string + - " ORDER BY table_episodes._rowid_ DESC LIMIT ? OFFSET ?", (page_size, offset)) - # path_replace - dict_mapper.path_replace(data) - - return render_template('wantedseries.html', bazarr_version=bazarr_version, rows=data, missing_count=missing_count, page=page, - max_page=max_page, base_url=base_url, page_size=page_size, current_port=settings.general.port) - - -@app.route('/wantedmovies') +@app.route('/wantedmovies/') @login_required def wantedmovies(): - - - if settings.radarr.getboolean('only_monitored'): - monitored_only_query_string = " AND monitored='True'" - else: - monitored_only_query_string = '' - - missing_count = database.execute("SELECT COUNT(*) as count FROM table_movies WHERE missing_subtitles != '[]'" + - monitored_only_query_string, only_one=True)['count'] - page = request.args.page - if page == "": - page = "1" - page_size = int(settings.general.page_size) - offset = (int(page) - 1) * page_size - max_page = int(math.ceil(missing_count / (page_size + 0.0))) - - data = database.execute("SELECT title, missing_subtitles, radarrId, path, hearing_impaired, sceneName, " - "failedAttempts FROM table_movies WHERE missing_subtitles != '[]'" + - monitored_only_query_string + " ORDER BY _rowid_ DESC LIMIT ? OFFSET ?", - (page_size, offset)) - # path_replace - dict_mapper.path_replace_movie(data) - - return render_template('wantedmovies.html', bazarr_version=bazarr_version, rows=data, - missing_count=missing_count, page=page, max_page=max_page, base_url=base_url, page_size=page_size, - current_port=settings.general.port) + return render_template('wantedmovies.html') @app.route('/wanted_search_missing_subtitles') diff --git a/bazarr/utils.py b/bazarr/utils.py index 2b436125e..4b40888e6 100644 --- a/bazarr/utils.py +++ b/bazarr/utils.py @@ -10,26 +10,30 @@ import requests from whichcraft import which from get_args import args from config import settings, url_sonarr, url_radarr +from database import database +from websocket_handler import event_stream from subliminal import region as subliminal_cache_region import datetime import glob +from threading import Event def history_log(action, sonarr_series_id, sonarr_episode_id, description, video_path=None, language=None, provider=None, score=None): - from database import database + thread = Event() database.execute("INSERT INTO table_history (action, sonarrSeriesId, sonarrEpisodeId, timestamp, description," "video_path, language, provider, score) VALUES (?,?,?,?,?,?,?,?,?)", (action, sonarr_series_id, sonarr_episode_id, time.time(), description, video_path, language, provider, score)) + event_stream.write(type='episodeHistory') def history_log_movie(action, radarr_id, description, video_path=None, language=None, provider=None, score=None): - from database import database database.execute("INSERT INTO table_history_movie (action, radarrId, timestamp, description, video_path, language, " "provider, score) VALUES (?,?,?,?,?,?,?,?)", (action, radarr_id, time.time(), description, video_path, language, provider, score)) + event_stream.write(type='movieHistory') def get_binary(name): diff --git a/views/_main.html b/views/_main.html index 8c6667b23..51b002977 100644 --- a/views/_main.html +++ b/views/_main.html @@ -169,39 +169,39 @@