From 27f906fe71336270e0421723ca33400e8392b562 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Louis=20V=C3=A9zina?=
<5130500+morpheus65535@users.noreply.github.com>
Date: Fri, 15 Mar 2019 14:28:57 -0400
Subject: [PATCH 01/25] Initial development on subtitles upgrade
---
bazarr/config.py | 3 ++-
bazarr/get_subtitle.py | 12 ++++++++++++
bazarr/main.py | 8 +++++++-
3 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/bazarr/config.py b/bazarr/config.py
index 92beec7bf..d73059752 100644
--- a/bazarr/config.py
+++ b/bazarr/config.py
@@ -37,7 +37,8 @@ defaults = {
'multithreading': 'True',
'chmod': '0640',
'subfolder': 'current',
- 'subfolder_custom': ''
+ 'subfolder_custom': '',
+ 'days_to_upgrade_subs': '7'
},
'auth': {
'type': 'None',
diff --git a/bazarr/get_subtitle.py b/bazarr/get_subtitle.py
index 7531d565e..bf3886075 100644
--- a/bazarr/get_subtitle.py
+++ b/bazarr/get_subtitle.py
@@ -700,3 +700,15 @@ def refine_from_db(path, video):
if data[6]: video.audio_codec = data[6]
return video
+
+
+def upgrade_subtitles():
+ days_to_upgrade_subs = settings.general.days_to_upgrade_subs
+ minimum_timestamp = ((datetime.now() - timedelta(days=int(days_to_upgrade_subs))) - datetime(1970,1,1)).total_seconds()
+
+ db = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30)
+ c = db.cursor()
+ data = c.execute("SELECT * FROM table_history WHERE timestamp > ? AND score is not null", (minimum_timestamp,)).fetchall()
+ db.close()
+
+ return data
diff --git a/bazarr/main.py b/bazarr/main.py
index bfb98fe42..d27d87bfe 100644
--- a/bazarr/main.py
+++ b/bazarr/main.py
@@ -62,7 +62,7 @@ if not args.no_update:
from list_subtitles import store_subtitles, store_subtitles_movie, series_scan_subtitles, movies_scan_subtitles, \
list_missing_subtitles, list_missing_subtitles_movies
from get_subtitle import download_subtitle, series_download_subtitles, movies_download_subtitles, \
- wanted_download_subtitles, wanted_search_missing_subtitles, manual_search, manual_download_subtitle
+ wanted_download_subtitles, wanted_search_missing_subtitles, manual_search, manual_download_subtitle, upgrade_subtitles
from utils import history_log, history_log_movie
from scheduler import *
from notifier import send_notifications, send_notifications_movie
@@ -1088,6 +1088,12 @@ def wanted_search_missing_subtitles_list():
redirect(ref)
+@route(base_url + 'upgrade_subtitles')
+@custom_auth_basic(check_credentials)
+def upgrade_subtitles_route():
+ return dict(data=upgrade_subtitles())
+
+
@route(base_url + 'settings')
@custom_auth_basic(check_credentials)
def _settings():
From efbbd9b958e9db67374d348da5aeb6ec876b714d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Louis=20V=C3=A9zina?=
<5130500+morpheus65535@users.noreply.github.com>
Date: Sat, 16 Mar 2019 15:30:06 -0400
Subject: [PATCH 02/25] Continuing development.
---
bazarr/get_subtitle.py | 34 +++++++++++++++++++++++++++++++---
1 file changed, 31 insertions(+), 3 deletions(-)
diff --git a/bazarr/get_subtitle.py b/bazarr/get_subtitle.py
index bf3886075..909e93310 100644
--- a/bazarr/get_subtitle.py
+++ b/bazarr/get_subtitle.py
@@ -100,7 +100,7 @@ def get_scores(video, media_type, min_score_movie_perc=60 * 100 / 120.0, min_sco
return min_score, max_score, set(scores)
-def download_subtitle(path, language, hi, providers, providers_auth, sceneName, title, media_type):
+def download_subtitle(path, language, hi, providers, providers_auth, sceneName, title, media_type, forced_minimum_score=None):
# fixme: supply all missing languages, not only one, to hit providers only once who support multiple languages in
# one query
@@ -143,6 +143,8 @@ def download_subtitle(path, language, hi, providers, providers_auth, sceneName,
min_score_series_perc=int(minimum_score))
if providers:
+ if forced_minimum_score:
+ min_score = int(forced_minimum_score) + 1
downloaded_subtitles = download_best_subtitles({video}, language_set, int(min_score), hi,
providers=providers,
provider_configs=providers_auth,
@@ -708,7 +710,33 @@ def upgrade_subtitles():
db = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30)
c = db.cursor()
- data = c.execute("SELECT * FROM table_history WHERE timestamp > ? AND score is not null", (minimum_timestamp,)).fetchall()
+ data = c.execute('SELECT video_path, language, score FROM table_history WHERE action = 1 AND timestamp > ? AND score is not null AND score < "360"', (minimum_timestamp,)).fetchall()
db.close()
- return data
+ episodes_to_upgrade = []
+ for episode in data:
+ if os.path.exists(path_replace(episode[0])):
+ episodes_to_upgrade.append(episode)
+
+ providers_list = get_providers()
+ providers_auth = get_providers_auth()
+
+ for episode in episodes_to_upgrade:
+ notifications.write(
+ msg='Searching for ' + str(language_from_alpha2(episode[1])) + ' subtitles for this episode: ' + path_replace(
+ episode[0]), queue='get_subtitle')
+ result = download_subtitle(path_replace(episode[0]), str(alpha3_from_alpha2(episode[1])),
+ series_details[0], providers_list, providers_auth, str(episode[3]),
+ series_details[1], 'series', forced_minimum_score=int(score))
+ if result is not None:
+ message = result[0]
+ path = result[1]
+ language_code = result[2]
+ provider = result[3]
+ score = result[4]
+ store_subtitles(path_replace(episode[0]))
+ history_log(1, no, episode[2], message, path, language_code, provider, score)
+ send_notifications(no, episode[2], message)
+
+
+ return episodes_to_upgrade
From 07b44cf2801f93b4a6875991e9701fe7acf6f09b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Louis=20V=C3=A9zina?=
<5130500+morpheus65535@users.noreply.github.com>
Date: Sun, 17 Mar 2019 10:29:38 -0400
Subject: [PATCH 03/25] Continuing development.
---
bazarr/get_subtitle.py | 37 ++++++++++++++++++++++++-------------
bazarr/main.py | 6 ------
bazarr/scheduler.py | 5 ++++-
3 files changed, 28 insertions(+), 20 deletions(-)
diff --git a/bazarr/get_subtitle.py b/bazarr/get_subtitle.py
index 909e93310..5c4b94cec 100644
--- a/bazarr/get_subtitle.py
+++ b/bazarr/get_subtitle.py
@@ -407,7 +407,12 @@ def manual_download_subtitle(path, language, hi, subtitle, provider, providers_a
else:
logging.info('BAZARR Post-processing result for file ' + path + ' : ' + out)
- return message
+ if media_type == 'series':
+ reversed_path = path_replace_reverse(path)
+ else:
+ reversed_path = path_replace_reverse_movie(path)
+
+ return message, reversed_path, downloaded_language_code2, downloaded_provider, subtitle.score
else:
logging.error(
"BAZARR Tried to manually download a subtitles for file: " + path + " but we weren't able to do (probably throttled by " + str(
@@ -706,15 +711,24 @@ def refine_from_db(path, video):
def upgrade_subtitles():
days_to_upgrade_subs = settings.general.days_to_upgrade_subs
- minimum_timestamp = ((datetime.now() - timedelta(days=int(days_to_upgrade_subs))) - datetime(1970,1,1)).total_seconds()
+ minimum_timestamp = ((datetime.now() - timedelta(days=int(days_to_upgrade_subs))) -
+ datetime(1970, 1, 1)).total_seconds()
db = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30)
c = db.cursor()
- data = c.execute('SELECT video_path, language, score FROM table_history WHERE action = 1 AND timestamp > ? AND score is not null AND score < "360"', (minimum_timestamp,)).fetchall()
+ episodes_list = c.execute("""SELECT table_history.video_path, table_history.language, table_history.score,
+ table_shows.hearing_impaired, table_episodes.scene_name, table_episodes.title,
+ table_episodes.sonarrSeriesId, table_episodes.sonarrEpisodeId,
+ MAX(table_history.timestamp)
+ FROM table_history
+ INNER JOIN table_shows on table_shows.sonarrSeriesId = table_history.sonarrSeriesId
+ INNER JOIN table_episodes on table_episodes.sonarrEpisodeId = table_history.sonarrEpisodeId
+ WHERE action = 1 AND timestamp > ? AND score is not null AND score < "360"
+ GROUP BY table_history.video_path""", (minimum_timestamp,)).fetchall()
db.close()
episodes_to_upgrade = []
- for episode in data:
+ for episode in episodes_list:
if os.path.exists(path_replace(episode[0])):
episodes_to_upgrade.append(episode)
@@ -723,11 +737,11 @@ def upgrade_subtitles():
for episode in episodes_to_upgrade:
notifications.write(
- msg='Searching for ' + str(language_from_alpha2(episode[1])) + ' subtitles for this episode: ' + path_replace(
- episode[0]), queue='get_subtitle')
+ msg='Searching to upgrade ' + str(language_from_alpha2(episode[1])) + ' subtitles for this episode: ' +
+ path_replace(episode[0]), queue='get_subtitle')
result = download_subtitle(path_replace(episode[0]), str(alpha3_from_alpha2(episode[1])),
- series_details[0], providers_list, providers_auth, str(episode[3]),
- series_details[1], 'series', forced_minimum_score=int(score))
+ episode[3], providers_list, providers_auth, str(episode[4]),
+ episode[5], 'series', forced_minimum_score=int(episode[2]))
if result is not None:
message = result[0]
path = result[1]
@@ -735,8 +749,5 @@ def upgrade_subtitles():
provider = result[3]
score = result[4]
store_subtitles(path_replace(episode[0]))
- history_log(1, no, episode[2], message, path, language_code, provider, score)
- send_notifications(no, episode[2], message)
-
-
- return episodes_to_upgrade
+ history_log(1, episode[6], episode[7], message, path, language_code, provider, score)
+ send_notifications(episode[6], episode[7], message)
diff --git a/bazarr/main.py b/bazarr/main.py
index d27d87bfe..bef2a67ee 100644
--- a/bazarr/main.py
+++ b/bazarr/main.py
@@ -1088,12 +1088,6 @@ def wanted_search_missing_subtitles_list():
redirect(ref)
-@route(base_url + 'upgrade_subtitles')
-@custom_auth_basic(check_credentials)
-def upgrade_subtitles_route():
- return dict(data=upgrade_subtitles())
-
-
@route(base_url + 'settings')
@custom_auth_basic(check_credentials)
def _settings():
diff --git a/bazarr/scheduler.py b/bazarr/scheduler.py
index bc2cff442..a30ac2edf 100644
--- a/bazarr/scheduler.py
+++ b/bazarr/scheduler.py
@@ -4,7 +4,7 @@ from get_episodes import sync_episodes, update_all_episodes, update_all_movies
from get_movies import update_movies
from get_series import update_series
from config import settings
-from get_subtitle import wanted_search_missing_subtitles
+from get_subtitle import wanted_search_missing_subtitles, upgrade_subtitles
from get_args import args
if not args.no_update:
@@ -109,6 +109,9 @@ if settings.general.getboolean('use_sonarr') or settings.general.getboolean('use
scheduler.add_job(wanted_search_missing_subtitles, IntervalTrigger(hours=3), max_instances=1, coalesce=True,
misfire_grace_time=15, id='wanted_search_missing_subtitles', name='Search for wanted subtitles')
+scheduler.add_job(upgrade_subtitles, IntervalTrigger(hours=12), max_instances=1, coalesce=True,
+ misfire_grace_time=15, id='upgrade_subtitles', name='Upgrade subtitles')
+
sonarr_full_update()
radarr_full_update()
scheduler.start()
From 86da34c29213a9d4d4ea2e261db5db300ce6fc0e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Louis=20V=C3=A9zina?=
<5130500+morpheus65535@users.noreply.github.com>
Date: Sun, 17 Mar 2019 14:53:36 -0400
Subject: [PATCH 04/25] Continuing development.
---
bazarr/config.py | 1 +
bazarr/scheduler.py | 5 +++--
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/bazarr/config.py b/bazarr/config.py
index d73059752..87bd91119 100644
--- a/bazarr/config.py
+++ b/bazarr/config.py
@@ -38,6 +38,7 @@ defaults = {
'chmod': '0640',
'subfolder': 'current',
'subfolder_custom': '',
+ 'upgrade_subs': 'True',
'days_to_upgrade_subs': '7'
},
'auth': {
diff --git a/bazarr/scheduler.py b/bazarr/scheduler.py
index a30ac2edf..90d360252 100644
--- a/bazarr/scheduler.py
+++ b/bazarr/scheduler.py
@@ -109,8 +109,9 @@ if settings.general.getboolean('use_sonarr') or settings.general.getboolean('use
scheduler.add_job(wanted_search_missing_subtitles, IntervalTrigger(hours=3), max_instances=1, coalesce=True,
misfire_grace_time=15, id='wanted_search_missing_subtitles', name='Search for wanted subtitles')
-scheduler.add_job(upgrade_subtitles, IntervalTrigger(hours=12), max_instances=1, coalesce=True,
- misfire_grace_time=15, id='upgrade_subtitles', name='Upgrade subtitles')
+if settings.general.getboolean('upgrade_subs'):
+ scheduler.add_job(upgrade_subtitles, IntervalTrigger(hours=12), max_instances=1, coalesce=True,
+ misfire_grace_time=15, id='upgrade_subtitles', name='Upgrade subtitles')
sonarr_full_update()
radarr_full_update()
From 6a22d76611119c375408263f322dbee9e1127bb3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Louis=20V=C3=A9zina?=
<5130500+morpheus65535@users.noreply.github.com>
Date: Sun, 17 Mar 2019 17:44:40 -0400
Subject: [PATCH 05/25] Continuing development.
---
bazarr/get_subtitle.py | 35 +++++++++++++++++++++++++++++++++--
1 file changed, 33 insertions(+), 2 deletions(-)
diff --git a/bazarr/get_subtitle.py b/bazarr/get_subtitle.py
index b9dd844a6..4d9d6e158 100644
--- a/bazarr/get_subtitle.py
+++ b/bazarr/get_subtitle.py
@@ -725,7 +725,16 @@ def upgrade_subtitles():
INNER JOIN table_shows on table_shows.sonarrSeriesId = table_history.sonarrSeriesId
INNER JOIN table_episodes on table_episodes.sonarrEpisodeId = table_history.sonarrEpisodeId
WHERE action = 1 AND timestamp > ? AND score is not null AND score < "360"
- GROUP BY table_history.video_path""", (minimum_timestamp,)).fetchall()
+ GROUP BY table_history.video_path, table_history.language""",
+ (minimum_timestamp,)).fetchall()
+ movies_list = c.execute("""SELECT table_history_movie.video_path, table_history_movie.language,
+ table_history_movie.score, table_movies.hearing_impaired, table_movies.sceneName,
+ table_movies.title, table_movies.radarrId, MAX(table_history_movie.timestamp)
+ FROM table_history_movie
+ INNER JOIN table_movies on table_movies.radarrId = table_history_movie.radarrId
+ WHERE action = 1 AND timestamp > ? AND score is not null AND score < "120"
+ GROUP BY table_history_movie.video_path, table_history_movie.language""",
+ (minimum_timestamp,)).fetchall()
db.close()
episodes_to_upgrade = []
@@ -733,6 +742,11 @@ def upgrade_subtitles():
if os.path.exists(path_replace(episode[0])):
episodes_to_upgrade.append(episode)
+ movies_to_upgrade = []
+ for movie in movies_list:
+ if os.path.exists(path_replace_movie(movie[0])):
+ movies_to_upgrade.append(movie)
+
providers_list = get_providers()
providers_auth = get_providers_auth()
@@ -742,7 +756,7 @@ def upgrade_subtitles():
path_replace(episode[0]), queue='get_subtitle')
result = download_subtitle(path_replace(episode[0]), str(alpha3_from_alpha2(episode[1])),
episode[3], providers_list, providers_auth, str(episode[4]),
- episode[5], 'series', forced_minimum_score=int(episode[2]))
+ episode[5], 'episode', forced_minimum_score=int(episode[2]))
if result is not None:
message = result[0]
path = result[1]
@@ -752,3 +766,20 @@ def upgrade_subtitles():
store_subtitles(path_replace(episode[0]))
history_log(1, episode[6], episode[7], message, path, language_code, provider, score)
send_notifications(episode[6], episode[7], message)
+
+ for movie in movies_to_upgrade:
+ notifications.write(
+ msg='Searching to upgrade ' + str(language_from_alpha2(movie[1])) + ' subtitles for this movie: ' +
+ path_replace_movie(movie[0]), queue='get_subtitle')
+ result = download_subtitle(path_replace_movie(movie[0]), str(alpha3_from_alpha2(movie[1])),
+ movie[3], providers_list, providers_auth, str(movie[4]),
+ movie[5], 'movie', forced_minimum_score=int(movie[2]))
+ if result is not None:
+ message = result[0]
+ path = result[1]
+ language_code = result[2]
+ provider = result[3]
+ score = result[4]
+ store_subtitles_movie(path_replace_movie(movie[0]))
+ history_log_movie(1, movie[6], message, path, language_code, provider, score)
+ send_notifications_movie(movie[6], message)
From 8c7d658aa5c0289f67c478d73970c909a7e29e80 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Louis=20V=C3=A9zina?=
<5130500+morpheus65535@users.noreply.github.com>
Date: Sun, 17 Mar 2019 22:43:30 -0400
Subject: [PATCH 06/25] Ended development of upgrade subtitles.
---
bazarr/main.py | 22 +++++++++++++--
bazarr/scheduler.py | 2 +-
views/settings.tpl | 67 +++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 87 insertions(+), 4 deletions(-)
diff --git a/bazarr/main.py b/bazarr/main.py
index 051684245..73a7e26fa 100644
--- a/bazarr/main.py
+++ b/bazarr/main.py
@@ -278,7 +278,13 @@ def save_wizard():
settings_general_embedded = 'True'
settings_subfolder = request.forms.get('settings_subfolder')
settings_subfolder_custom = request.forms.get('settings_subfolder_custom')
-
+ settings_upgrade_subs = request.forms.get('settings_upgrade_subs')
+ if settings_upgrade_subs is None:
+ settings_upgrade_subs = 'False'
+ else:
+ settings_upgrade_subs = 'True'
+ settings_days_to_upgrade_subs = request.forms.get('settings_days_to_upgrade_subs')
+
settings.general.ip = text_type(settings_general_ip)
settings.general.port = text_type(settings_general_port)
settings.general.base_url = text_type(settings_general_baseurl)
@@ -290,7 +296,9 @@ def save_wizard():
settings.general.subfolder = text_type(settings_subfolder)
settings.general.subfolder_custom = text_type(settings_subfolder_custom)
settings.general.use_embedded_subs = text_type(settings_general_embedded)
-
+ settings.general.upgrade_subs = text_type(settings_upgrade_subs)
+ settings.general.days_to_upgrade_subs = text_type(settings_days_to_upgrade_subs)
+
settings_sonarr_ip = request.forms.get('settings_sonarr_ip')
settings_sonarr_port = request.forms.get('settings_sonarr_port')
settings_sonarr_baseurl = request.forms.get('settings_sonarr_baseurl')
@@ -1187,7 +1195,13 @@ def save_settings():
settings_page_size = request.forms.get('settings_page_size')
settings_subfolder = request.forms.get('settings_subfolder')
settings_subfolder_custom = request.forms.get('settings_subfolder_custom')
-
+ settings_upgrade_subs = request.forms.get('settings_upgrade_subs')
+ if settings_upgrade_subs is None:
+ settings_upgrade_subs = 'False'
+ else:
+ settings_upgrade_subs = 'True'
+ settings_days_to_upgrade_subs = request.forms.get('settings_days_to_upgrade_subs')
+
before = (unicode(settings.general.ip), int(settings.general.port), unicode(settings.general.base_url),
unicode(settings.general.path_mappings), unicode(settings.general.getboolean('use_sonarr')),
unicode(settings.general.getboolean('use_radarr')), unicode(settings.general.path_mappings_movie))
@@ -1214,6 +1228,8 @@ def save_settings():
settings.general.page_size = text_type(settings_page_size)
settings.general.subfolder = text_type(settings_subfolder)
settings.general.subfolder_custom = text_type(settings_subfolder_custom)
+ settings.general.upgrade_subs = text_type(settings_upgrade_subs)
+ settings.general.days_to_upgrade_subs = text_type(settings_days_to_upgrade_subs)
settings.general.minimum_score_movie = text_type(settings_general_minimum_score_movies)
settings.general.use_embedded_subs = text_type(settings_general_embedded)
settings.general.adaptive_searching = text_type(settings_general_adaptive_searching)
diff --git a/bazarr/scheduler.py b/bazarr/scheduler.py
index 90d360252..1cd9bb52a 100644
--- a/bazarr/scheduler.py
+++ b/bazarr/scheduler.py
@@ -111,7 +111,7 @@ if settings.general.getboolean('use_sonarr') or settings.general.getboolean('use
if settings.general.getboolean('upgrade_subs'):
scheduler.add_job(upgrade_subtitles, IntervalTrigger(hours=12), max_instances=1, coalesce=True,
- misfire_grace_time=15, id='upgrade_subtitles', name='Upgrade subtitles')
+ misfire_grace_time=15, id='upgrade_subtitles', name='Upgrade previously downloaded subtitles')
sonarr_full_update()
radarr_full_update()
diff --git a/views/settings.tpl b/views/settings.tpl
index 29be34839..93bd1810e 100644
--- a/views/settings.tpl
+++ b/views/settings.tpl
@@ -1081,6 +1081,7 @@
+
@@ -1101,6 +1102,41 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -2025,6 +2061,12 @@
$("#settings_scenename").checkbox('uncheck');
}
+ if ($('#settings_upgrade_subs').data("upgrade") === "True") {
+ $("#settings_upgrade_subs").checkbox('check');
+ } else {
+ $("#settings_upgrade_subs").checkbox('uncheck');
+ }
+
if ($('#settings_embedded').data("embedded") === "True") {
$("#settings_embedded").checkbox('check');
} else {
@@ -2148,6 +2190,21 @@
}
});
+ if ($('#settings_upgrade_subs').data("upgrade") === "True") {
+ $('.upgrade_subs').show();
+ } else {
+ $('.upgrade_subs').hide();
+ }
+
+ $('#settings_upgrade_subs').checkbox({
+ onChecked: function() {
+ $('.upgrade_subs').show();
+ },
+ onUnchecked: function() {
+ $('.upgrade_subs').hide();
+ }
+ });
+
if ($('#settings_auth_type').val() === "None") {
$('.auth_option').hide();
}
@@ -2482,6 +2539,16 @@
type : 'empty'
}
]
+ },
+ settings_days_to_upgrade_subs : {
+ rules : [
+ {
+ type : 'integer[1..30]'
+ },
+ {
+ type : 'empty'
+ }
+ ]
}
},
inline : true,
From 7e6ce238ce99e156b722097173c2258a7ecc1944 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Louis=20V=C3=A9zina?=
<5130500+morpheus65535@users.noreply.github.com>
Date: Mon, 18 Mar 2019 18:32:02 -0400
Subject: [PATCH 07/25] Continuing development.
---
bazarr/get_subtitle.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/bazarr/get_subtitle.py b/bazarr/get_subtitle.py
index 4d9d6e158..a24d9ce7d 100644
--- a/bazarr/get_subtitle.py
+++ b/bazarr/get_subtitle.py
@@ -756,7 +756,7 @@ def upgrade_subtitles():
path_replace(episode[0]), queue='get_subtitle')
result = download_subtitle(path_replace(episode[0]), str(alpha3_from_alpha2(episode[1])),
episode[3], providers_list, providers_auth, str(episode[4]),
- episode[5], 'episode', forced_minimum_score=int(episode[2]))
+ episode[5], 'series', forced_minimum_score=int(episode[2]))
if result is not None:
message = result[0]
path = result[1]
From 3cc39c08daa85732b23b745ce11b343deda23cc0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Louis=20V=C3=A9zina?=
<5130500+morpheus65535@users.noreply.github.com>
Date: Tue, 19 Mar 2019 00:08:53 -0400
Subject: [PATCH 08/25] Continuing development.
---
bazarr/config.py | 3 +-
bazarr/get_subtitle.py | 86 +++++++++++++++++++++++------------------
bazarr/main.py | 64 +++++++++++++++++++++++++++---
views/historymovies.tpl | 24 +++++++++++-
views/historyseries.tpl | 24 +++++++++++-
views/settings.tpl | 27 +++++++++++++
6 files changed, 181 insertions(+), 47 deletions(-)
diff --git a/bazarr/config.py b/bazarr/config.py
index 87bd91119..3b23f829e 100644
--- a/bazarr/config.py
+++ b/bazarr/config.py
@@ -39,7 +39,8 @@ defaults = {
'subfolder': 'current',
'subfolder_custom': '',
'upgrade_subs': 'True',
- 'days_to_upgrade_subs': '7'
+ 'days_to_upgrade_subs': '7',
+ 'upgrade_manual': 'True'
},
'auth': {
'type': 'None',
diff --git a/bazarr/get_subtitle.py b/bazarr/get_subtitle.py
index a24d9ce7d..17f29d6e9 100644
--- a/bazarr/get_subtitle.py
+++ b/bazarr/get_subtitle.py
@@ -111,7 +111,7 @@ def download_subtitle(path, language, hi, providers, providers_auth, sceneName,
else:
hi = False
language_set = set()
-
+ original_language = language
if not isinstance(language, types.ListType):
language = [language]
@@ -184,9 +184,9 @@ def download_subtitle(path, language, hi, providers, providers_auth, sceneName,
saved_any = True
for subtitle in saved_subtitles:
downloaded_provider = subtitle.provider_name
- downloaded_language = language_from_alpha3(subtitle.language.alpha3)
- downloaded_language_code2 = alpha2_from_alpha3(subtitle.language.alpha3)
- downloaded_language_code3 = subtitle.language.alpha3
+ downloaded_language = language_from_alpha3(original_language)
+ downloaded_language_code2 = alpha2_from_alpha3(original_language)
+ downloaded_language_code3 = original_language
downloaded_path = subtitle.storage_path
logging.debug('BAZARR Subtitles file saved to disk: ' + downloaded_path)
if video.used_scene_name:
@@ -715,24 +715,32 @@ def upgrade_subtitles():
minimum_timestamp = ((datetime.now() - timedelta(days=int(days_to_upgrade_subs))) -
datetime(1970, 1, 1)).total_seconds()
+ if settings.general.getboolean('upgrade_manual'):
+ query_actions = [1, 2, 3]
+ else:
+ query_actions = [1, 3]
+
db = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30)
c = db.cursor()
episodes_list = c.execute("""SELECT table_history.video_path, table_history.language, table_history.score,
table_shows.hearing_impaired, table_episodes.scene_name, table_episodes.title,
table_episodes.sonarrSeriesId, table_episodes.sonarrEpisodeId,
- MAX(table_history.timestamp)
+ MAX(table_history.timestamp), table_shows.languages
FROM table_history
INNER JOIN table_shows on table_shows.sonarrSeriesId = table_history.sonarrSeriesId
INNER JOIN table_episodes on table_episodes.sonarrEpisodeId = table_history.sonarrEpisodeId
- WHERE action = 1 AND timestamp > ? AND score is not null AND score < "360"
+ WHERE action IN (""" + ','.join(map(str, query_actions)) + """) AND timestamp > ? AND
+ score is not null AND score < "360"
GROUP BY table_history.video_path, table_history.language""",
(minimum_timestamp,)).fetchall()
movies_list = c.execute("""SELECT table_history_movie.video_path, table_history_movie.language,
table_history_movie.score, table_movies.hearing_impaired, table_movies.sceneName,
- table_movies.title, table_movies.radarrId, MAX(table_history_movie.timestamp)
+ table_movies.title, table_movies.radarrId, MAX(table_history_movie.timestamp),
+ table_movies.languages
FROM table_history_movie
INNER JOIN table_movies on table_movies.radarrId = table_history_movie.radarrId
- WHERE action = 1 AND timestamp > ? AND score is not null AND score < "120"
+ WHERE action IN (""" + ','.join(map(str, query_actions)) + """) AND timestamp > ? AND
+ score is not null AND score < "120"
GROUP BY table_history_movie.video_path, table_history_movie.language""",
(minimum_timestamp,)).fetchall()
db.close()
@@ -751,35 +759,37 @@ def upgrade_subtitles():
providers_auth = get_providers_auth()
for episode in episodes_to_upgrade:
- notifications.write(
- msg='Searching to upgrade ' + str(language_from_alpha2(episode[1])) + ' subtitles for this episode: ' +
- path_replace(episode[0]), queue='get_subtitle')
- result = download_subtitle(path_replace(episode[0]), str(alpha3_from_alpha2(episode[1])),
- episode[3], providers_list, providers_auth, str(episode[4]),
- episode[5], 'series', forced_minimum_score=int(episode[2]))
- if result is not None:
- message = result[0]
- path = result[1]
- language_code = result[2]
- provider = result[3]
- score = result[4]
- store_subtitles(path_replace(episode[0]))
- history_log(1, episode[6], episode[7], message, path, language_code, provider, score)
- send_notifications(episode[6], episode[7], message)
+ if episode[1] in ast.literal_eval(str(episode[9])):
+ notifications.write(
+ msg='Searching to upgrade ' + str(language_from_alpha2(episode[1])) + ' subtitles for this episode: ' +
+ path_replace(episode[0]), queue='get_subtitle')
+ result = download_subtitle(path_replace(episode[0]), str(alpha3_from_alpha2(episode[1])),
+ episode[3], providers_list, providers_auth, str(episode[4]),
+ episode[5], 'series', forced_minimum_score=int(episode[2]))
+ if result is not None:
+ message = result[0]
+ path = result[1]
+ language_code = result[2]
+ provider = result[3]
+ score = result[4]
+ store_subtitles(path_replace(episode[0]))
+ history_log(3, episode[6], episode[7], message, path, language_code, provider, score)
+ send_notifications(episode[6], episode[7], message)
for movie in movies_to_upgrade:
- notifications.write(
- msg='Searching to upgrade ' + str(language_from_alpha2(movie[1])) + ' subtitles for this movie: ' +
- path_replace_movie(movie[0]), queue='get_subtitle')
- result = download_subtitle(path_replace_movie(movie[0]), str(alpha3_from_alpha2(movie[1])),
- movie[3], providers_list, providers_auth, str(movie[4]),
- movie[5], 'movie', forced_minimum_score=int(movie[2]))
- if result is not None:
- message = result[0]
- path = result[1]
- language_code = result[2]
- provider = result[3]
- score = result[4]
- store_subtitles_movie(path_replace_movie(movie[0]))
- history_log_movie(1, movie[6], message, path, language_code, provider, score)
- send_notifications_movie(movie[6], message)
+ if movie[1] in ast.literal_eval(str(movie[8])):
+ notifications.write(
+ msg='Searching to upgrade ' + str(language_from_alpha2(movie[1])) + ' subtitles for this movie: ' +
+ path_replace_movie(movie[0]), queue='get_subtitle')
+ result = download_subtitle(path_replace_movie(movie[0]), str(alpha3_from_alpha2(movie[1])),
+ movie[3], providers_list, providers_auth, str(movie[4]),
+ movie[5], 'movie', forced_minimum_score=int(movie[2]))
+ if result is not None:
+ message = result[0]
+ path = result[1]
+ language_code = result[2]
+ provider = result[3]
+ score = result[4]
+ store_subtitles_movie(path_replace_movie(movie[0]))
+ history_log_movie(3, movie[6], message, path, language_code, provider, score)
+ send_notifications_movie(movie[6], message)
diff --git a/bazarr/main.py b/bazarr/main.py
index 73a7e26fa..52835c96b 100644
--- a/bazarr/main.py
+++ b/bazarr/main.py
@@ -284,6 +284,11 @@ def save_wizard():
else:
settings_upgrade_subs = 'True'
settings_days_to_upgrade_subs = request.forms.get('settings_days_to_upgrade_subs')
+ settings_upgrade_manual = request.forms.get('settings_upgrade_manual')
+ if settings_upgrade_manual is None:
+ settings_upgrade_manual = 'False'
+ else:
+ settings_upgrade_manual = 'True'
settings.general.ip = text_type(settings_general_ip)
settings.general.port = text_type(settings_general_port)
@@ -298,6 +303,7 @@ def save_wizard():
settings.general.use_embedded_subs = text_type(settings_general_embedded)
settings.general.upgrade_subs = text_type(settings_upgrade_subs)
settings.general.days_to_upgrade_subs = text_type(settings_days_to_upgrade_subs)
+ settings.general.upgrade_manual = text_type(settings_upgrade_manual)
settings_sonarr_ip = request.forms.get('settings_sonarr_ip')
settings_sonarr_port = request.forms.get('settings_sonarr_port')
@@ -959,14 +965,35 @@ def historyseries():
stats = [len(today), len(thisweek), len(thisyear), total]
c.execute(
- "SELECT table_history.action, table_shows.title, table_episodes.season || 'x' || table_episodes.episode, table_episodes.title, table_history.timestamp, table_history.description, table_history.sonarrSeriesId FROM table_history LEFT JOIN table_shows on table_shows.sonarrSeriesId = table_history.sonarrSeriesId LEFT JOIN table_episodes on table_episodes.sonarrEpisodeId = table_history.sonarrEpisodeId ORDER BY id DESC LIMIT ? OFFSET ?",
+ "SELECT table_history.action, table_shows.title, table_episodes.season || 'x' || table_episodes.episode, table_episodes.title, table_history.timestamp, table_history.description, table_history.sonarrSeriesId, table_episodes.path, table_shows.languages, table_history.language FROM table_history LEFT JOIN table_shows on table_shows.sonarrSeriesId = table_history.sonarrSeriesId LEFT JOIN table_episodes on table_episodes.sonarrEpisodeId = table_history.sonarrEpisodeId ORDER BY id DESC LIMIT ? OFFSET ?",
(page_size, offset,))
data = c.fetchall()
+
+ upgradable_episodes = []
+ if settings.general.getboolean('upgrade_subs'):
+ days_to_upgrade_subs = settings.general.days_to_upgrade_subs
+ minimum_timestamp = ((datetime.now() - timedelta(days=int(days_to_upgrade_subs))) -
+ datetime(1970, 1, 1)).total_seconds()
+
+ if settings.general.getboolean('upgrade_manual'):
+ query_actions = [1, 2, 3]
+ else:
+ query_actions = [1, 3]
+
+ upgradable_episodes = c.execute("""SELECT table_history.video_path, MAX(table_history.timestamp)
+ FROM table_history
+ WHERE action IN (""" + ','.join(map(str, query_actions)) + """) AND timestamp >
+ ? AND score is not null AND score < "360"
+ GROUP BY table_history.video_path, table_history.language""",
+ (minimum_timestamp,)).fetchall()
+
c.close()
+
data = reversed(sorted(data, key=operator.itemgetter(4)))
+
return template('historyseries', bazarr_version=bazarr_version, rows=data, row_count=row_count,
page=page, max_page=max_page, stats=stats, base_url=base_url, page_size=page_size,
- current_port=settings.general.port)
+ current_port=settings.general.port, upgradable_episodes=upgradable_episodes)
@route(base_url + 'historymovies')
@@ -1002,14 +1029,33 @@ def historymovies():
stats = [len(today), len(thisweek), len(thisyear), total]
c.execute(
- "SELECT table_history_movie.action, table_movies.title, table_history_movie.timestamp, table_history_movie.description, table_history_movie.radarrId FROM table_history_movie LEFT JOIN table_movies on table_movies.radarrId = table_history_movie.radarrId ORDER BY id DESC LIMIT ? OFFSET ?",
+ "SELECT table_history_movie.action, table_movies.title, table_history_movie.timestamp, table_history_movie.description, table_history_movie.radarrId, table_history_movie.video_path, table_movies.languages, table_history_movie.language FROM table_history_movie LEFT JOIN table_movies on table_movies.radarrId = table_history_movie.radarrId ORDER BY id DESC LIMIT ? OFFSET ?",
(page_size, offset,))
data = c.fetchall()
+
+ upgradable_movies = []
+ if settings.general.getboolean('upgrade_subs'):
+ days_to_upgrade_subs = settings.general.days_to_upgrade_subs
+ minimum_timestamp = ((datetime.now() - timedelta(days=int(days_to_upgrade_subs))) -
+ datetime(1970, 1, 1)).total_seconds()
+
+ if settings.general.getboolean('upgrade_manual'):
+ query_actions = [1, 2, 3]
+ else:
+ query_actions = [1, 3]
+
+ upgradable_movies = c.execute("""SELECT video_path, MAX(timestamp)
+ FROM table_history_movie
+ WHERE action IN (""" + ','.join(map(str, query_actions)) + """) AND timestamp
+ > ? AND score is not null AND score < "120"
+ GROUP BY video_path, language""",
+ (minimum_timestamp,)).fetchall()
+
c.close()
data = reversed(sorted(data, key=operator.itemgetter(2)))
return template('historymovies', bazarr_version=bazarr_version, rows=data, row_count=row_count,
page=page, max_page=max_page, stats=stats, base_url=base_url, page_size=page_size,
- current_port=settings.general.port)
+ current_port=settings.general.port, upgradable_movies=upgradable_movies)
@route(base_url + 'wanted')
@@ -1201,6 +1247,11 @@ def save_settings():
else:
settings_upgrade_subs = 'True'
settings_days_to_upgrade_subs = request.forms.get('settings_days_to_upgrade_subs')
+ settings_upgrade_manual = request.forms.get('settings_upgrade_manual')
+ if settings_upgrade_manual is None:
+ settings_upgrade_manual = 'False'
+ else:
+ settings_upgrade_manual = 'True'
before = (unicode(settings.general.ip), int(settings.general.port), unicode(settings.general.base_url),
unicode(settings.general.path_mappings), unicode(settings.general.getboolean('use_sonarr')),
@@ -1230,6 +1281,7 @@ def save_settings():
settings.general.subfolder_custom = text_type(settings_subfolder_custom)
settings.general.upgrade_subs = text_type(settings_upgrade_subs)
settings.general.days_to_upgrade_subs = text_type(settings_days_to_upgrade_subs)
+ settings.general.upgrade_manual = text_type(settings_upgrade_manual)
settings.general.minimum_score_movie = text_type(settings_general_minimum_score_movies)
settings.general.use_embedded_subs = text_type(settings_general_embedded)
settings.general.adaptive_searching = text_type(settings_general_adaptive_searching)
@@ -1759,7 +1811,7 @@ def manual_get_subtitle():
language_code = result[2]
provider = result[3]
score = result[4]
- history_log(1, sonarrSeriesId, sonarrEpisodeId, message, path, language_code, provider, score)
+ history_log(2, sonarrSeriesId, sonarrEpisodeId, message, path, language_code, provider, score)
send_notifications(sonarrSeriesId, sonarrEpisodeId, message)
store_subtitles(unicode(episodePath))
list_missing_subtitles(sonarrSeriesId)
@@ -1848,7 +1900,7 @@ def manual_get_subtitle_movie():
language_code = result[2]
provider = result[3]
score = result[4]
- history_log_movie(1, radarrId, message, path, language_code, provider, score)
+ history_log_movie(2, radarrId, message, path, language_code, provider, score)
send_notifications_movie(radarrId, message)
store_subtitles_movie(unicode(moviePath))
list_missing_subtitles_movies(radarrId)
diff --git a/views/historymovies.tpl b/views/historymovies.tpl
index baad469e4..01895b78e 100644
--- a/views/historymovies.tpl
+++ b/views/historymovies.tpl
@@ -52,6 +52,7 @@
+ %import ast
%import time
%import pretty
%for row in rows:
@@ -65,6 +66,14 @@
+ %elif row[0] == 2:
+
+
+
+ %elif row[0] == 3:
+
+
+
%end
@@ -75,7 +84,20 @@
{{pretty.date(int(row[2]))}}
|
- {{row[3]}} |
+
+ % upgradable_criteria = (row[5], row[2])
+ % if upgradable_criteria in upgradable_movies:
+ % if row[7] in ast.literal_eval(str(row[6])):
+
+ {{row[3]}}
+
+ % else:
+ {{row[3]}}
+ % end
+ % else:
+ {{row[3]}}
+ %end
+ |
%end
diff --git a/views/historyseries.tpl b/views/historyseries.tpl
index f29fea046..442793717 100644
--- a/views/historyseries.tpl
+++ b/views/historyseries.tpl
@@ -54,6 +54,7 @@
+ %import ast
%import time
%import pretty
%for row in rows:
@@ -67,6 +68,14 @@
+ %elif row[0] == 2:
+
+
+
+ %elif row[0] == 3:
+
+
+
%end
@@ -90,7 +99,20 @@
{{pretty.date(int(row[4]))}}
|
- {{row[5]}} |
+
+ % upgradable_criteria = (row[7], row[4])
+ % if upgradable_criteria in upgradable_episodes:
+ % if row[9] in ast.literal_eval(str(row[8])):
+
+ {{row[5]}}
+
+ % else:
+ {{row[5]}}
+ % end
+ % else:
+ {{row[5]}}
+ %end
+ |
%end
diff --git a/views/settings.tpl b/views/settings.tpl
index 93bd1810e..b8693264c 100644
--- a/views/settings.tpl
+++ b/views/settings.tpl
@@ -1137,6 +1137,27 @@
+
+
+
+
+
+
+
+
+
+
@@ -2067,6 +2088,12 @@
$("#settings_upgrade_subs").checkbox('uncheck');
}
+ if ($('#settings_upgrade_manual').data("upgrade-manual") === "True") {
+ $("#settings_upgrade_manual").checkbox('check');
+ } else {
+ $("#settings_upgrade_manual").checkbox('uncheck');
+ }
+
if ($('#settings_embedded').data("embedded") === "True") {
$("#settings_embedded").checkbox('check');
} else {
From dd17672593aff7dfff56335b6c0a699bc2cf0cad Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Louis=20V=C3=A9zina?=
<5130500+morpheus65535@users.noreply.github.com>
Date: Tue, 19 Mar 2019 20:16:19 -0400
Subject: [PATCH 09/25] Continuing development.
---
bazarr/get_subtitle.py | 20 +++++++++++++-------
views/episodes.tpl | 13 ++++++++++++-
views/movie.tpl | 13 ++++++++++++-
3 files changed, 37 insertions(+), 9 deletions(-)
diff --git a/bazarr/get_subtitle.py b/bazarr/get_subtitle.py
index 17f29d6e9..2aa83bd6d 100644
--- a/bazarr/get_subtitle.py
+++ b/bazarr/get_subtitle.py
@@ -111,7 +111,7 @@ def download_subtitle(path, language, hi, providers, providers_auth, sceneName,
else:
hi = False
language_set = set()
- original_language = language
+
if not isinstance(language, types.ListType):
language = [language]
@@ -184,9 +184,12 @@ def download_subtitle(path, language, hi, providers, providers_auth, sceneName,
saved_any = True
for subtitle in saved_subtitles:
downloaded_provider = subtitle.provider_name
- downloaded_language = language_from_alpha3(original_language)
- downloaded_language_code2 = alpha2_from_alpha3(original_language)
- downloaded_language_code3 = original_language
+ if subtitle.language == 'pt-BR':
+ downloaded_language_code3 = 'pob'
+ else:
+ downloaded_language_code3 = subtitle.language
+ downloaded_language = language_from_alpha3(downloaded_language_code3)
+ downloaded_language_code2 = alpha2_from_alpha3(downloaded_language_code3)
downloaded_path = subtitle.storage_path
logging.debug('BAZARR Subtitles file saved to disk: ' + downloaded_path)
if video.used_scene_name:
@@ -368,9 +371,12 @@ def manual_download_subtitle(path, language, hi, subtitle, provider, providers_a
if saved_subtitles:
for saved_subtitle in saved_subtitles:
downloaded_provider = saved_subtitle.provider_name
- downloaded_language = language_from_alpha3(saved_subtitle.language.alpha3)
- downloaded_language_code2 = alpha2_from_alpha3(saved_subtitle.language.alpha3)
- downloaded_language_code3 = saved_subtitle.language.alpha3
+ if saved_subtitle.language == 'pt-BR':
+ downloaded_language_code3 = 'pob'
+ else:
+ downloaded_language_code3 = subtitle.language
+ downloaded_language = language_from_alpha3(downloaded_language_code3)
+ downloaded_language_code2 = alpha2_from_alpha3(downloaded_language_code3)
downloaded_path = saved_subtitle.storage_path
logging.debug('BAZARR Subtitles file saved to disk: ' + downloaded_path)
message = downloaded_language + " subtitles downloaded from " + downloaded_provider + " with a score of " + unicode(
diff --git a/views/episodes.tpl b/views/episodes.tpl
index 586e36dec..e8c85f7bc 100644
--- a/views/episodes.tpl
+++ b/views/episodes.tpl
@@ -467,6 +467,9 @@
hi = $(this).attr("data-hi");
sonarrSeriesId = $(this).attr("data-sonarrSeriesId");
sonarrEpisodeId = $(this).attr("data-sonarrEpisodeId");
+ var languages = Array.from({{!subs_languages_list}});
+ var is_pb = languages.includes('pb');
+ var is_pt = languages.includes('pt');
const values = {
episodePath: episodePath,
@@ -505,7 +508,15 @@
return data +'%';
}
},
- { data: 'language' },
+ { data: null,
+ render: function ( data, type, row ) {
+ if ( data.language === "pt" && is_pb === true && is_pt === false) {
+ return 'pb'
+ } else {
+ return data.language
+ }
+ }
+ },
{ data: 'hearing_impaired' },
{ data: null,
render: function ( data, type, row ) {
diff --git a/views/movie.tpl b/views/movie.tpl
index 8f6b96664..9ec005589 100644
--- a/views/movie.tpl
+++ b/views/movie.tpl
@@ -416,6 +416,9 @@
language = $(this).attr("data-language");
hi = $(this).attr("data-hi");
radarrId = $(this).attr("data-radarrId");
+ var languages = Array.from({{!subs_languages_list}});
+ var is_pb = languages.includes('pb');
+ var is_pt = languages.includes('pt');
const values = {
moviePath: moviePath,
@@ -453,7 +456,15 @@
return data +'%';
}
},
- { data: 'language' },
+ { data: null,
+ render: function ( data, type, row ) {
+ if ( data.language === "pt" && is_pb === true && is_pt === false) {
+ return 'pb'
+ } else {
+ return data.language
+ }
+ }
+ },
{ data: 'hearing_impaired' },
{ data: null,
render: function ( data, type, row ) {
From f75f2150819cfd005bca047a719d6286c6daa83c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Louis=20V=C3=A9zina?=
<5130500+morpheus65535@users.noreply.github.com>
Date: Tue, 19 Mar 2019 23:44:50 -0400
Subject: [PATCH 10/25] Continuing development.
---
bazarr/get_subtitle.py | 12 ++++++------
bazarr/main.py | 28 ++++++++++++++++++----------
views/historymovies.tpl | 2 +-
views/historyseries.tpl | 2 +-
4 files changed, 26 insertions(+), 18 deletions(-)
diff --git a/bazarr/get_subtitle.py b/bazarr/get_subtitle.py
index 2aa83bd6d..6419692dc 100644
--- a/bazarr/get_subtitle.py
+++ b/bazarr/get_subtitle.py
@@ -187,7 +187,7 @@ def download_subtitle(path, language, hi, providers, providers_auth, sceneName,
if subtitle.language == 'pt-BR':
downloaded_language_code3 = 'pob'
else:
- downloaded_language_code3 = subtitle.language
+ downloaded_language_code3 = subtitle.language.alpha3
downloaded_language = language_from_alpha3(downloaded_language_code3)
downloaded_language_code2 = alpha2_from_alpha3(downloaded_language_code3)
downloaded_path = subtitle.storage_path
@@ -374,7 +374,7 @@ def manual_download_subtitle(path, language, hi, subtitle, provider, providers_a
if saved_subtitle.language == 'pt-BR':
downloaded_language_code3 = 'pob'
else:
- downloaded_language_code3 = subtitle.language
+ downloaded_language_code3 = subtitle.language.alpha3
downloaded_language = language_from_alpha3(downloaded_language_code3)
downloaded_language_code2 = alpha2_from_alpha3(downloaded_language_code3)
downloaded_path = saved_subtitle.storage_path
@@ -736,7 +736,7 @@ def upgrade_subtitles():
INNER JOIN table_shows on table_shows.sonarrSeriesId = table_history.sonarrSeriesId
INNER JOIN table_episodes on table_episodes.sonarrEpisodeId = table_history.sonarrEpisodeId
WHERE action IN (""" + ','.join(map(str, query_actions)) + """) AND timestamp > ? AND
- score is not null AND score < "360"
+ score is not null
GROUP BY table_history.video_path, table_history.language""",
(minimum_timestamp,)).fetchall()
movies_list = c.execute("""SELECT table_history_movie.video_path, table_history_movie.language,
@@ -746,19 +746,19 @@ def upgrade_subtitles():
FROM table_history_movie
INNER JOIN table_movies on table_movies.radarrId = table_history_movie.radarrId
WHERE action IN (""" + ','.join(map(str, query_actions)) + """) AND timestamp > ? AND
- score is not null AND score < "120"
+ score is not null
GROUP BY table_history_movie.video_path, table_history_movie.language""",
(minimum_timestamp,)).fetchall()
db.close()
episodes_to_upgrade = []
for episode in episodes_list:
- if os.path.exists(path_replace(episode[0])):
+ if os.path.exists(path_replace(episode[0])) and int(episode[2]) < 360:
episodes_to_upgrade.append(episode)
movies_to_upgrade = []
for movie in movies_list:
- if os.path.exists(path_replace_movie(movie[0])):
+ if os.path.exists(path_replace_movie(movie[0])) and int(movie[2]) < 120:
movies_to_upgrade.append(movie)
providers_list = get_providers()
diff --git a/bazarr/main.py b/bazarr/main.py
index 52835c96b..9a5c2b042 100644
--- a/bazarr/main.py
+++ b/bazarr/main.py
@@ -953,7 +953,7 @@ def historyseries():
today = []
thisweek = []
thisyear = []
- stats = c.execute("SELECT timestamp FROM table_history WHERE action LIKE '1'").fetchall()
+ stats = c.execute("SELECT timestamp FROM table_history WHERE action > 0").fetchall()
total = len(stats)
for stat in stats:
if now - timedelta(hours=24) <= datetime.fromtimestamp(stat[0]) <= now:
@@ -965,7 +965,7 @@ def historyseries():
stats = [len(today), len(thisweek), len(thisyear), total]
c.execute(
- "SELECT table_history.action, table_shows.title, table_episodes.season || 'x' || table_episodes.episode, table_episodes.title, table_history.timestamp, table_history.description, table_history.sonarrSeriesId, table_episodes.path, table_shows.languages, table_history.language FROM table_history LEFT JOIN table_shows on table_shows.sonarrSeriesId = table_history.sonarrSeriesId LEFT JOIN table_episodes on table_episodes.sonarrEpisodeId = table_history.sonarrEpisodeId ORDER BY id DESC LIMIT ? OFFSET ?",
+ "SELECT table_history.action, table_shows.title, table_episodes.season || 'x' || table_episodes.episode, table_episodes.title, table_history.timestamp, table_history.description, table_history.sonarrSeriesId, table_episodes.path, table_shows.languages, table_history.language, table_history.score FROM table_history LEFT JOIN table_shows on table_shows.sonarrSeriesId = table_history.sonarrSeriesId LEFT JOIN table_episodes on table_episodes.sonarrEpisodeId = table_history.sonarrEpisodeId ORDER BY id DESC LIMIT ? OFFSET ?",
(page_size, offset,))
data = c.fetchall()
@@ -980,12 +980,16 @@ def historyseries():
else:
query_actions = [1, 3]
- upgradable_episodes = c.execute("""SELECT table_history.video_path, MAX(table_history.timestamp)
+ upgradable_episodes = c.execute("""SELECT video_path, MAX(timestamp), score
FROM table_history
WHERE action IN (""" + ','.join(map(str, query_actions)) + """) AND timestamp >
- ? AND score is not null AND score < "360"
+ ? AND score is not null
GROUP BY table_history.video_path, table_history.language""",
(minimum_timestamp,)).fetchall()
+ upgradable_episodes_not_perfect = []
+ for upgradable_episode in upgradable_episodes:
+ if upgradable_episode[2] < "360":
+ upgradable_episodes_not_perfect.append(upgradable_episode)
c.close()
@@ -993,7 +997,7 @@ def historyseries():
return template('historyseries', bazarr_version=bazarr_version, rows=data, row_count=row_count,
page=page, max_page=max_page, stats=stats, base_url=base_url, page_size=page_size,
- current_port=settings.general.port, upgradable_episodes=upgradable_episodes)
+ current_port=settings.general.port, upgradable_episodes=upgradable_episodes_not_perfect)
@route(base_url + 'historymovies')
@@ -1017,7 +1021,7 @@ def historymovies():
today = []
thisweek = []
thisyear = []
- stats = c.execute("SELECT timestamp FROM table_history_movie WHERE action LIKE '1'").fetchall()
+ stats = c.execute("SELECT timestamp FROM table_history_movie WHERE action > 0").fetchall()
total = len(stats)
for stat in stats:
if now - timedelta(hours=24) <= datetime.fromtimestamp(stat[0]) <= now:
@@ -1029,7 +1033,7 @@ def historymovies():
stats = [len(today), len(thisweek), len(thisyear), total]
c.execute(
- "SELECT table_history_movie.action, table_movies.title, table_history_movie.timestamp, table_history_movie.description, table_history_movie.radarrId, table_history_movie.video_path, table_movies.languages, table_history_movie.language FROM table_history_movie LEFT JOIN table_movies on table_movies.radarrId = table_history_movie.radarrId ORDER BY id DESC LIMIT ? OFFSET ?",
+ "SELECT table_history_movie.action, table_movies.title, table_history_movie.timestamp, table_history_movie.description, table_history_movie.radarrId, table_history_movie.video_path, table_movies.languages, table_history_movie.language, table_history_movie.score FROM table_history_movie LEFT JOIN table_movies on table_movies.radarrId = table_history_movie.radarrId ORDER BY id DESC LIMIT ? OFFSET ?",
(page_size, offset,))
data = c.fetchall()
@@ -1044,18 +1048,22 @@ def historymovies():
else:
query_actions = [1, 3]
- upgradable_movies = c.execute("""SELECT video_path, MAX(timestamp)
+ upgradable_movies = c.execute("""SELECT video_path, MAX(timestamp), score
FROM table_history_movie
WHERE action IN (""" + ','.join(map(str, query_actions)) + """) AND timestamp
- > ? AND score is not null AND score < "120"
+ > ? AND score is not null
GROUP BY video_path, language""",
(minimum_timestamp,)).fetchall()
+ upgradable_movies_not_perfect = []
+ for upgradable_movie in upgradable_movies:
+ if upgradable_movie[2] < "120":
+ upgradable_movies_not_perfect.append(upgradable_movie)
c.close()
data = reversed(sorted(data, key=operator.itemgetter(2)))
return template('historymovies', bazarr_version=bazarr_version, rows=data, row_count=row_count,
page=page, max_page=max_page, stats=stats, base_url=base_url, page_size=page_size,
- current_port=settings.general.port, upgradable_movies=upgradable_movies)
+ current_port=settings.general.port, upgradable_movies=upgradable_movies_not_perfect)
@route(base_url + 'wanted')
diff --git a/views/historymovies.tpl b/views/historymovies.tpl
index 01895b78e..6e764ed5f 100644
--- a/views/historymovies.tpl
+++ b/views/historymovies.tpl
@@ -85,7 +85,7 @@
- % upgradable_criteria = (row[5], row[2])
+ % upgradable_criteria = (row[5], row[2], row[8])
% if upgradable_criteria in upgradable_movies:
% if row[7] in ast.literal_eval(str(row[6])):
diff --git a/views/historyseries.tpl b/views/historyseries.tpl
index 442793717..63a30bcda 100644
--- a/views/historyseries.tpl
+++ b/views/historyseries.tpl
@@ -100,7 +100,7 @@
|
- % upgradable_criteria = (row[7], row[4])
+ % upgradable_criteria = (row[7], row[4], row[10])
% if upgradable_criteria in upgradable_episodes:
% if row[9] in ast.literal_eval(str(row[8])):
From 91ac1ffc26761e1a3c059f1fdb2a87647eec4347 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Louis=20V=C3=A9zina?=
<5130500+morpheus65535@users.noreply.github.com>
Date: Wed, 20 Mar 2019 06:33:11 -0400
Subject: [PATCH 11/25] Continuing development.
---
bazarr/get_subtitle.py | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/bazarr/get_subtitle.py b/bazarr/get_subtitle.py
index 6419692dc..3e5c7aec6 100644
--- a/bazarr/get_subtitle.py
+++ b/bazarr/get_subtitle.py
@@ -101,7 +101,7 @@ def get_scores(video, media_type, min_score_movie_perc=60 * 100 / 120.0, min_sco
return min_score, max_score, set(scores)
-def download_subtitle(path, language, hi, providers, providers_auth, sceneName, title, media_type, forced_minimum_score=None):
+def download_subtitle(path, language, hi, providers, providers_auth, sceneName, title, media_type, forced_minimum_score=None, is_upgrade=False):
# fixme: supply all missing languages, not only one, to hit providers only once who support multiple languages in
# one query
@@ -192,11 +192,15 @@ def download_subtitle(path, language, hi, providers, providers_auth, sceneName,
downloaded_language_code2 = alpha2_from_alpha3(downloaded_language_code3)
downloaded_path = subtitle.storage_path
logging.debug('BAZARR Subtitles file saved to disk: ' + downloaded_path)
+ if is_upgrade:
+ action = "upgraded"
+ else:
+ action = "downloaded"
if video.used_scene_name:
- message = downloaded_language + " subtitles downloaded from " + downloaded_provider + " with a score of " + unicode(
+ message = downloaded_language + " subtitles " + action + " from " + downloaded_provider + " with a score of " + unicode(
round(subtitle.score * 100 / max_score, 2)) + "% using this scene name: " + sceneName
else:
- message = downloaded_language + " subtitles downloaded from " + downloaded_provider + " with a score of " + unicode(
+ message = downloaded_language + " subtitles " + action + " from " + downloaded_provider + " with a score of " + unicode(
round(subtitle.score * 100 / max_score, 2)) + "% using filename guessing."
if use_postprocessing is True:
@@ -771,7 +775,7 @@ def upgrade_subtitles():
path_replace(episode[0]), queue='get_subtitle')
result = download_subtitle(path_replace(episode[0]), str(alpha3_from_alpha2(episode[1])),
episode[3], providers_list, providers_auth, str(episode[4]),
- episode[5], 'series', forced_minimum_score=int(episode[2]))
+ episode[5], 'series', forced_minimum_score=int(episode[2]), is_upgrade=True)
if result is not None:
message = result[0]
path = result[1]
@@ -789,7 +793,7 @@ def upgrade_subtitles():
path_replace_movie(movie[0]), queue='get_subtitle')
result = download_subtitle(path_replace_movie(movie[0]), str(alpha3_from_alpha2(movie[1])),
movie[3], providers_list, providers_auth, str(movie[4]),
- movie[5], 'movie', forced_minimum_score=int(movie[2]))
+ movie[5], 'movie', forced_minimum_score=int(movie[2]), is_upgrade=True)
if result is not None:
message = result[0]
path = result[1]
From 5b32c6ed41b4e5c4cac802821702117be2750633 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Louis=20V=C3=A9zina?=
<5130500+morpheus65535@users.noreply.github.com>
Date: Wed, 20 Mar 2019 15:16:33 -0400
Subject: [PATCH 12/25] Continuing development.
---
bazarr/main.py | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/bazarr/main.py b/bazarr/main.py
index 9a5c2b042..e099af273 100644
--- a/bazarr/main.py
+++ b/bazarr/main.py
@@ -982,13 +982,13 @@ def historyseries():
upgradable_episodes = c.execute("""SELECT video_path, MAX(timestamp), score
FROM table_history
- WHERE action IN (""" + ','.join(map(str, query_actions)) + """) AND timestamp >
- ? AND score is not null
+ WHERE action IN (""" + ','.join(map(str, query_actions)) + """) AND
+ timestamp > ? AND score is not null
GROUP BY table_history.video_path, table_history.language""",
(minimum_timestamp,)).fetchall()
upgradable_episodes_not_perfect = []
for upgradable_episode in upgradable_episodes:
- if upgradable_episode[2] < "360":
+ if int(upgradable_episode[2]) < 360:
upgradable_episodes_not_perfect.append(upgradable_episode)
c.close()
@@ -1050,13 +1050,13 @@ def historymovies():
upgradable_movies = c.execute("""SELECT video_path, MAX(timestamp), score
FROM table_history_movie
- WHERE action IN (""" + ','.join(map(str, query_actions)) + """) AND timestamp
- > ? AND score is not null
+ WHERE action IN (""" + ','.join(map(str, query_actions)) + """) AND
+ timestamp > ? AND score is not null
GROUP BY video_path, language""",
(minimum_timestamp,)).fetchall()
upgradable_movies_not_perfect = []
for upgradable_movie in upgradable_movies:
- if upgradable_movie[2] < "120":
+ if int(upgradable_movie[2]) < 120:
upgradable_movies_not_perfect.append(upgradable_movie)
c.close()
From 1e62365b9a35377a116407583524ae3d7b878efd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Louis=20V=C3=A9zina?=
<5130500+morpheus65535@users.noreply.github.com>
Date: Wed, 20 Mar 2019 19:57:45 -0400
Subject: [PATCH 13/25] Continuing development.
---
bazarr/main.py | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/bazarr/main.py b/bazarr/main.py
index e099af273..25bb6beb3 100644
--- a/bazarr/main.py
+++ b/bazarr/main.py
@@ -988,8 +988,13 @@ def historyseries():
(minimum_timestamp,)).fetchall()
upgradable_episodes_not_perfect = []
for upgradable_episode in upgradable_episodes:
- if int(upgradable_episode[2]) < 360:
- upgradable_episodes_not_perfect.append(upgradable_episode)
+ try:
+ int(upgradable_episode[2])
+ except ValueError:
+ pass
+ else:
+ if int(upgradable_episode[2]) < 360:
+ upgradable_episodes_not_perfect.append(upgradable_episode)
c.close()
@@ -1056,8 +1061,13 @@ def historymovies():
(minimum_timestamp,)).fetchall()
upgradable_movies_not_perfect = []
for upgradable_movie in upgradable_movies:
- if int(upgradable_movie[2]) < 120:
- upgradable_movies_not_perfect.append(upgradable_movie)
+ try:
+ int(upgradable_movie[2])
+ except ValueError:
+ pass
+ else:
+ if int(upgradable_movie[2]) < 120:
+ upgradable_movies_not_perfect.append(upgradable_movie)
c.close()
data = reversed(sorted(data, key=operator.itemgetter(2)))
From af438d1236bf799006aef7e99a89b87e350502ab Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Louis=20V=C3=A9zina?=
<5130500+morpheus65535@users.noreply.github.com>
Date: Thu, 21 Mar 2019 11:32:58 -0400
Subject: [PATCH 14/25] Continuing development.
---
bazarr/config.py | 2 +-
bazarr/get_providers.py | 31 +++++++++++++++++++++++++++++++
bazarr/main.py | 6 ++++--
views/menu.tpl | 15 +++++++++++++--
views/system.tpl | 33 ++++++++++++++++++++++++++++++++-
5 files changed, 81 insertions(+), 6 deletions(-)
diff --git a/bazarr/config.py b/bazarr/config.py
index 3b23f829e..19e885839 100644
--- a/bazarr/config.py
+++ b/bazarr/config.py
@@ -33,7 +33,7 @@ defaults = {
'use_embedded_subs': 'True',
'adaptive_searching': 'False',
'enabled_providers': '',
- 'throtteled_providers': '',
+ 'throtteled_providers': '{}',
'multithreading': 'True',
'chmod': '0640',
'subfolder': 'current',
diff --git a/bazarr/get_providers.py b/bazarr/get_providers.py
index 3511f628d..39ba91b67 100644
--- a/bazarr/get_providers.py
+++ b/bazarr/get_providers.py
@@ -3,6 +3,7 @@ import os
import datetime
import logging
import subliminal_patch
+import pretty
from get_args import args
from config import settings
@@ -139,3 +140,33 @@ def provider_throttle(name, exception):
logging.info("Throttling %s for %s, until %s, because of: %s. Exception info: %r", name, throttle_description,
throttle_until.strftime("%y/%m/%d %H:%M"), cls_name, exception.message)
+
+def update_throttled_provider():
+ changed = False
+ if settings.general.enabled_providers:
+ for provider in settings.general.enabled_providers.lower().split(','):
+ reason, until, throttle_desc = tp.get(provider, (None, None, None))
+
+ if reason:
+ now = datetime.datetime.now()
+ if now < until:
+ pass
+ else:
+ logging.info("Using %s again after %s, (disabled because: %s)", provider, throttle_desc, reason)
+ del tp[provider]
+ settings.general.throtteled_providers = str(tp)
+ changed = True
+
+ if changed:
+ with open(os.path.join(args.config_dir, 'config', 'config.ini'), 'w+') as handle:
+ settings.write(handle)
+
+
+def list_throttled_providers():
+ update_throttled_provider()
+ throttled_providers = []
+ if settings.general.enabled_providers:
+ for provider in settings.general.enabled_providers.lower().split(','):
+ reason, until, throttle_desc = tp.get(provider, (None, None, None))
+ throttled_providers.append([provider, reason, pretty.date(until)])
+ return throttled_providers
diff --git a/bazarr/main.py b/bazarr/main.py
index 25bb6beb3..663bdfcfa 100644
--- a/bazarr/main.py
+++ b/bazarr/main.py
@@ -53,7 +53,7 @@ from cork import Cork
from bottle import route, run, template, static_file, request, redirect, response, HTTPError, app, hook, abort
from datetime import datetime, timedelta
from get_languages import load_language_in_db, language_from_alpha3
-from get_providers import get_providers, get_providers_auth
+from get_providers import get_providers, get_providers_auth, list_throttled_providers
from get_series import *
from get_episodes import *
@@ -1642,6 +1642,8 @@ def system():
elif job.trigger.__str__().startswith('cron'):
task_list.append([job.name, get_time_from_cron(job.trigger.fields), next_run, job.id])
+ throttled_providers = list_throttled_providers()
+
i = 0
with open(os.path.join(args.config_dir, 'log', 'bazarr.log')) as f:
for i, l in enumerate(f, 1):
@@ -1678,7 +1680,7 @@ def system():
operating_system=platform.platform(), python_version=platform.python_version(),
config_dir=args.config_dir, bazarr_dir=os.path.normcase(os.getcwd()),
base_url=base_url, task_list=task_list, row_count=row_count, max_page=max_page, page_size=page_size,
- releases=releases, current_port=settings.general.port)
+ releases=releases, current_port=settings.general.port, throttled_providers=throttled_providers)
@route(base_url + 'logs/ ')
diff --git a/views/menu.tpl b/views/menu.tpl
index 9bea9b648..4dfdc9f1b 100644
--- a/views/menu.tpl
+++ b/views/menu.tpl
@@ -25,7 +25,11 @@
% from get_args import args
+ % from get_providers import update_throttled_provider
+ % update_throttled_provider()
+ % import ast
+ % import datetime
% import os
% import sqlite3
% from config import settings
@@ -46,7 +50,8 @@
% c = conn.cursor()
% wanted_series = c.execute("SELECT COUNT(*) FROM table_episodes WHERE missing_subtitles != '[]'" + monitored_only_query_string_sonarr).fetchone()
% wanted_movies = c.execute("SELECT COUNT(*) FROM table_movies WHERE missing_subtitles != '[]'" + monitored_only_query_string_radarr).fetchone()
-
+ % from get_providers import list_throttled_providers
+ % throttled_providers_count = len(eval(str(settings.general.throtteled_providers)))
+
@@ -599,7 +610,7 @@
-
+
@@ -610,7 +621,7 @@
-
+
@@ -2032,6 +2043,7 @@
% import sys
% if sys.platform.startswith('win'):
$("#chmod").hide();
+ $("#chmod_enabled").hide();
% end
$('.menu .item')
@@ -2070,6 +2082,12 @@
$("#settings_debug").checkbox('uncheck');
}
+ if ($('#settings_chmod_enabled').data("chmod") === "True") {
+ $("#settings_chmod_enabled").checkbox('check');
+ } else {
+ $("#settings_chmod_enabled").checkbox('uncheck');
+ }
+
if ($('#settings_single_language').data("single-language") === "True") {
$("#settings_single_language").checkbox('check');
} else {
@@ -2247,6 +2265,21 @@
}
});
+ if ($('#settings_chmod_enabled').data("chmod") === "True") {
+ $('#chmod').show();
+ } else {
+ $('#chmod').hide();
+ }
+
+ $('#settings_chmod_enabled').checkbox({
+ onChecked: function() {
+ $('#chmod').show();
+ },
+ onUnchecked: function() {
+ $('#chmod').hide();
+ }
+ });
+
if ($('#settings_auth_type').val() === "None") {
$('.auth_option').hide();
}
@@ -2467,7 +2500,7 @@
}
]
},
- % if not sys.platform.startswith('win'):
+ % if not sys.platform.startswith('win') and settings.general.getboolean('chmod_enabled'):
settings_general_chmod: {
rules: [
{
|