@ -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 *
@ -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
@ -278,7 +278,18 @@ 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_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 )
settings . general . base_url = text_type ( settings_general_baseurl )
@ -290,7 +301,10 @@ 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 . 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 ' )
settings_sonarr_baseurl = request . forms . get ( ' settings_sonarr_baseurl ' )
@ -939,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 :
@ -951,14 +965,44 @@ 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, 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 ( )
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 video_path, MAX(timestamp), score
FROM table_history
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 :
try :
int ( upgradable_episode [ 2 ] )
except ValueError :
pass
else :
if int ( upgradable_episode [ 2 ] ) < 360 :
upgradable_episodes_not_perfect . append ( upgradable_episode )
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_not_perfect )
@route ( base_url + ' historymovies ' )
@ -982,7 +1026,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 :
@ -994,14 +1038,42 @@ 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, 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 ( )
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), score
FROM table_history_movie
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 :
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 ) ) )
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_not_perfect )
@route ( base_url + ' wanted ' )
@ -1187,7 +1259,18 @@ 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 ' )
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 ' ) ) ,
unicode ( settings . general . getboolean ( ' use_radarr ' ) ) , unicode ( settings . general . path_mappings_movie ) )
@ -1214,6 +1297,9 @@ 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 . 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 )
@ -1556,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 ) :
@ -1592,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/<page:int> ' )
@ -1743,7 +1831,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 )
@ -1832,7 +1920,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 )