Initial release of radarr integration for testing

This commit is contained in:
morpheus65535 2018-05-26 23:01:57 -04:00
parent c2d0d54fab
commit 757024f747
13 changed files with 195 additions and 57 deletions

View File

@ -157,7 +157,23 @@ def image_proxy_movies(url):
img_buffer.seek(0)
return send_file(img_buffer, ctype=img_pil.format)
@route(base_url)
def redirect_root():
conn = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30)
c = conn.cursor()
integration = c.execute("SELECT use_sonarr, use_radarr FROM table_settings_general").fetchone()
c.close()
if integration[0] == "True":
redirect(base_url + 'series')
elif integration[1] == "True":
redirect(base_url + 'movies')
else:
redirect(base_url + 'settings')
@route(base_url + 'series')
def series():
import update_db
single_language = get_general_settings()[7]
@ -653,22 +669,19 @@ def save_settings():
else:
settings_general_use_postprocessing = 'True'
settings_general_postprocessing_cmd = request.forms.get('settings_general_postprocessing_cmd')
print "toto"
settings_general_use_sonarr = request.forms.get('settings_general_use_sonarr')
print settings_general_use_sonarr
if settings_general_use_sonarr is None:
settings_general_use_sonarr = 'False'
else:
settings_general_use_sonarr = 'True'
settings_general_use_radarr = request.forms.get('settings_general_use_radarr')
print settings_general_use_radarr
if settings_general_use_radarr is None:
settings_general_use_radarr = 'False'
else:
settings_general_use_radarr = 'True'
before = c.execute("SELECT ip, port, base_url, log_level, path_mapping FROM table_settings_general").fetchone()
after = (unicode(settings_general_ip), int(settings_general_port), unicode(settings_general_baseurl), unicode(settings_general_loglevel), unicode(settings_general_pathmapping))
before = c.execute("SELECT ip, port, base_url, log_level, path_mapping, use_sonarr, use_radarr FROM table_settings_general").fetchone()
after = (unicode(settings_general_ip), int(settings_general_port), unicode(settings_general_baseurl), unicode(settings_general_loglevel), unicode(settings_general_pathmapping), unicode(settings_general_use_sonarr), unicode(settings_general_use_radarr))
c.execute("UPDATE table_settings_general SET ip = ?, port = ?, base_url = ?, path_mapping = ?, log_level = ?, branch=?, auto_update=?, single_language=?, minimum_score=?, use_scenename=?, use_postprocessing=?, postprocessing_cmd=?, use_sonarr=?, use_radarr=?", (unicode(settings_general_ip), int(settings_general_port), unicode(settings_general_baseurl), unicode(settings_general_pathmapping), unicode(settings_general_loglevel), unicode(settings_general_branch), unicode(settings_general_automatic), unicode(settings_general_single_language), unicode(settings_general_minimum_score), unicode(settings_general_scenename), unicode(settings_general_use_postprocessing), unicode(settings_general_postprocessing_cmd), unicode(settings_general_use_sonarr), unicode(settings_general_use_radarr)))
conn.commit()
if after != before:

View File

@ -49,7 +49,7 @@ CREATE TABLE "table_settings_general" (
`use_sonarr` TEXT,
`use_radarr` TEXT
);
INSERT INTO `table_settings_general` (ip,port,base_url,path_mapping,log_level, branch, auto_update, configured, updated, single_language, minimum_score, use_scenename, use_postprocessing, postprocessing_cmd, use_sonarr, use_radarr) VALUES ('0.0.0.0',6767,'/',Null,'INFO','master','True',0,0,'False','0','False','False',Null);
INSERT INTO `table_settings_general` (ip,port,base_url,path_mapping,log_level, branch, auto_update, configured, updated, single_language, minimum_score, use_scenename, use_postprocessing, postprocessing_cmd, use_sonarr, use_radarr) VALUES ('0.0.0.0',6767,'/',Null,'INFO','master','True',0,0,'False','0','False','False',Null,'False','False');
CREATE TABLE "table_history" (
`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
`action` INTEGER NOT NULL,

View File

@ -6,8 +6,14 @@ import logging
from get_general_settings import *
from list_subtitles import *
def update_all_episodes_and_movies():
full_scan_subtitles()
def update_all_episodes():
series_full_scan_subtitles()
logging.info('All existing subtitles indexed from disk.')
list_missing_subtitles()
logging.info('All missing subtitles updated in database.')
def update_all_movies():
movies_full_scan_subtitles()
logging.info('All existing subtitles indexed from disk.')
list_missing_subtitles()
logging.info('All missing subtitles updated in database.')

View File

@ -1,6 +1,7 @@
import sqlite3
import os
import ast
import re
def get_general_settings():
# Open database connection
@ -40,7 +41,7 @@ def path_replace(path):
for path_mapping in path_mappings:
if path_mapping[0] in path:
path = path.replace(path_mapping[0], path_mapping[1])
if path.startswith('\\\\'):
if path.startswith('\\\\') or re.match(r'^[a-zA-Z]:\\', path):
path = path.replace('/', '\\')
elif path.startswith('/'):
path = path.replace('\\', '/')
@ -51,7 +52,7 @@ def path_replace_reverse(path):
for path_mapping in path_mappings:
if path_mapping[1] in path:
path = path.replace(path_mapping[1], path_mapping[0])
if path.startswith('\\\\'):
if path.startswith('\\\\') or re.match(r'^[a-zA-Z]:\\', path):
path = path.replace('/', '\\')
elif path.startswith('/'):
path = path.replace('\\', '/')

View File

@ -182,7 +182,7 @@ def list_missing_subtitles_movies(*no):
conn_db.commit()
c_db.close()
def full_scan_subtitles():
def series_full_scan_subtitles():
conn_db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30)
c_db = conn_db.cursor()
episodes = c_db.execute("SELECT path FROM table_episodes").fetchall()
@ -191,6 +191,10 @@ def full_scan_subtitles():
for episode in episodes:
store_subtitles(path_replace(episode[0]))
gc.collect()
def movies_full_scan_subtitles():
conn_db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30)
c_db = conn_db.cursor()
movies = c_db.execute("SELECT path FROM table_movies").fetchall()
c_db.close()
@ -221,17 +225,4 @@ def movies_scan_subtitles(no):
for movie in movies:
store_subtitles_movie(path_replace(movie[0]))
list_missing_subtitles_movies(no)
def new_scan_subtitles():
conn_db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30)
c_db = conn_db.cursor()
episodes = c_db.execute("SELECT path FROM table_episodes WHERE subtitles is null").fetchall()
c_db.close()
for episode in episodes:
store_subtitles(path_replace(episode[0]))
if __name__ == '__main__':
full_scan_subtitles()
list_missing_subtitles_movies(no)

View File

@ -1,5 +1,7 @@
from get_general_settings import *
from get_sonarr_settings import get_sonarr_settings
from get_radarr_settings import get_radarr_settings
from get_general_settings import get_general_settings
from get_series import *
from get_episodes import *
from get_movies import *
@ -12,18 +14,29 @@ from datetime import datetime
import pytz
from tzlocal import get_localzone
integration = get_general_settings()
def sonarr_full_update():
full_update = get_sonarr_settings()[3]
if full_update == "Daily":
scheduler.add_job(update_all_episodes_and_movies, 'cron', hour=4, max_instances=1, coalesce=True, misfire_grace_time=15, id='update_all_episodes_and_movies', name='Update all subtitles from disk', replace_existing=True)
scheduler.add_job(update_all_episodes, 'cron', hour=4, max_instances=1, coalesce=True, misfire_grace_time=15, id='update_all_episodes', name='Update all episodes subtitles from disk', replace_existing=True)
elif full_update == "Weekly":
scheduler.add_job(update_all_episodes_and_movies, 'cron', day_of_week='sun', hour=4, max_instances=1, coalesce=True, misfire_grace_time=15, id='update_all_episodes_and_movies', name='Update all subtitles from disk', replace_existing=True)
scheduler.add_job(update_all_episodes, 'cron', day_of_week='sun', hour=4, max_instances=1, coalesce=True, misfire_grace_time=15, id='update_all_episodes', name='Update all episodes subtitles from disk', replace_existing=True)
elif full_update == "Manually":
scheduler.add_job(update_all_episodes_and_movies, 'cron', year='2100', hour=4, max_instances=1, coalesce=True, misfire_grace_time=15, id='update_all_episodes_and_movies', name='Update all subtitles from disk', replace_existing=True)
scheduler.add_job(update_all_episodes, 'cron', year='2100', hour=4, max_instances=1, coalesce=True, misfire_grace_time=15, id='update_all_episodes', name='Update all episodes subtitles from disk', replace_existing=True)
def radarr_full_update():
full_update = get_radarr_settings()[3]
if full_update == "Daily":
scheduler.add_job(update_all_movies, 'cron', hour=4, max_instances=1, coalesce=True, misfire_grace_time=15, id='update_all_movies', name='Update all movies subtitles from disk', replace_existing=True)
elif full_update == "Weekly":
scheduler.add_job(update_all_movies, 'cron', day_of_week='sun', hour=4, max_instances=1, coalesce=True, misfire_grace_time=15, id='update_all_movies', name='Update all movies subtitles from disk', replace_existing=True)
elif full_update == "Manually":
scheduler.add_job(update_all_movies, 'cron', year='2100', hour=4, max_instances=1, coalesce=True, misfire_grace_time=15, id='update_all_movies', name='Update all movies subtitles from disk', replace_existing=True)
def execute_now(taskid):
scheduler.modify_job(taskid, jobstore=None, next_run_time=datetime.now())
scheduler.modify_job(taskid, next_run_time=datetime.now())
if str(get_localzone()) == "local":
@ -35,9 +48,15 @@ if automatic == 'True':
scheduler.add_job(check_and_apply_update, 'interval', hours=6, max_instances=1, coalesce=True, misfire_grace_time=15, id='update_bazarr', name='Update bazarr from source on Github')
else:
scheduler.add_job(check_and_apply_update, 'cron', year='2100', hour=4, id='update_bazarr', name='Update bazarr from source on Github')
scheduler.add_job(update_series, 'interval', minutes=1, max_instances=1, coalesce=True, misfire_grace_time=15, id='update_series', name='Update series list from Sonarr')
scheduler.add_job(sync_episodes, 'interval', minutes=5, max_instances=1, coalesce=True, misfire_grace_time=15, id='sync_episodes', name='Sync episodes with Sonarr')
scheduler.add_job(update_movies, 'interval', minutes=1, max_instances=1, coalesce=True, misfire_grace_time=15, id='update_movies', name='Update movies list from Radarr')
scheduler.add_job(wanted_search_missing_subtitles, 'interval', hours=3, max_instances=1, coalesce=True, misfire_grace_time=15, id='wanted_search_missing_subtitles', name='Search for wanted subtitles')
sonarr_full_update()
if integration[12] == "True":
scheduler.add_job(update_series, 'interval', minutes=1, max_instances=1, coalesce=True, misfire_grace_time=15, id='update_series', name='Update series list from Sonarr')
scheduler.add_job(sync_episodes, 'interval', minutes=5, max_instances=1, coalesce=True, misfire_grace_time=15, id='sync_episodes', name='Sync episodes with Sonarr')
if integration[13] == "True":
scheduler.add_job(update_movies, 'interval', minutes=1, max_instances=1, coalesce=True, misfire_grace_time=15, id='update_movies', name='Update movies list from Radarr')
if integration[12] == "True" or integration[13] == "True":
scheduler.add_job(wanted_search_missing_subtitles, 'interval', hours=3, max_instances=1, coalesce=True, misfire_grace_time=15, id='wanted_search_missing_subtitles', name='Search for wanted subtitles')
scheduler.start()

View File

@ -87,6 +87,13 @@ if os.path.exists(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'))
except:
pass
try:
c.execute('CREATE TABLE "table_settings_radarr" ( `ip` TEXT NOT NULL, `port` INTEGER NOT NULL, `base_url` TEXT, `ssl` INTEGER, `apikey` TEXT , "full_update" TEXT)')
except:
pass
else:
c.execute('INSERT INTO `table_settings_radarr` (ip, port, base_url, ssl, apikey, full_update) VALUES ("0.0.0.0", "7878", "/", "False", Null, "Daily")')
try:
c.execute('CREATE TABLE "table_movies" ( `tmdbId` TEXT NOT NULL UNIQUE, `title` TEXT NOT NULL, `path` TEXT NOT NULL UNIQUE, `languages` TEXT, `subtitles` TEXT, `missing_subtitles` TEXT, `hearing_impaired` TEXT, `radarrId` INTEGER NOT NULL UNIQUE, `overview` TEXT, `poster` TEXT, `fanart` TEXT, "audio_language" "text", `sceneName` TEXT, PRIMARY KEY(`tmdbId`) )')
except:
@ -118,10 +125,14 @@ if os.path.exists(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'))
c.execute('alter table table_episodes add column "scene_name" TEXT')
db.commit()
except:
db.close()
pass
else:
db.close()
from scheduler import execute_now
execute_now('update_all_episodes_and_movies')
# Close database connection
db.close()
from get_general_settings import get_general_settings
integration = get_general_settings()
if integration[12] == "True":
execute_now('update_all_episodes')
if integration[13] == "True":
execute_now('update_all_movies')

View File

@ -37,6 +37,10 @@
}
.fast.backward, .backward, .forward, .fast.forward { pointer-events: auto; }
.fast.backward.disabled, .backward.disabled, .forward.disabled, .fast.forward.disabled { pointer-events: none; }
.ui.tabular.menu > .disabled.item {
opacity: 0.45 !important;
pointer-events: none !important;
}
</style>
</head>
<body>
@ -44,11 +48,20 @@
<div class="ui indeterminate text loader">Loading...</div>
</div>
% include('menu.tpl')
% import os
% import sqlite3
% conn = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30)
% c = conn.cursor()
% integration = c.execute("SELECT use_sonarr, use_radarr FROM table_settings_general").fetchone()
% c.close()
<div id="fondblanc" class="ui container">
<div class="ui top attached tabular menu">
<a id="series_tab" class="tabs item active" data-tab="series">Series</a>
<a id="movies_tab" class="tabs item" data-tab="movies">Movies</a>
<a id="series_tab" class="tabs item active" data-enabled="{{integration[0]}}" data-tab="series">Series</a>
<a id="movies_tab" class="tabs item" data-enabled="{{integration[1]}}" data-tab="movies">Movies</a>
</div>
<div class="ui bottom attached tab segment" data-tab="series">
<div class="content">
@ -105,5 +118,21 @@
$('#loader').addClass('active');
})
$( "#series_tab" ).trigger( "click" );
if ($('#series_tab').data("enabled") == "True") {
$("#series_tab").removeClass('disabled');
} else {
$("#series_tab").addClass('disabled');
}
if ($('#movies_tab').data("enabled") == "True") {
$("#movies_tab").removeClass('disabled');
} else {
$("#movies_tab").addClass('disabled');
}
if ($('#series_tab').data("enabled") == "True") {
$( "#series_tab" ).trigger( "click" );
}
if ($('#series_tab').data("enabled") == "False" && $('#movies_tab').data("enabled") == "True") {
$( "#movies_tab" ).trigger( "click" );
}
</script>

View File

@ -28,6 +28,7 @@
% c = conn.cursor()
% wanted_series = c.execute("SELECT COUNT(*) FROM table_episodes WHERE missing_subtitles != '[]'").fetchone()
% wanted_movies = c.execute("SELECT COUNT(*) FROM table_movies WHERE missing_subtitles != '[]'").fetchone()
% integration = c.execute("SELECT use_sonarr, use_radarr FROM table_settings_general").fetchone()
<div id="divmenu" class="ui container">
<div class="ui grid">
@ -42,26 +43,34 @@
<div class="sixteen wide column">
<div class="ui inverted borderless labeled icon massive menu six item">
<div class="ui container">
<a class="item" href="{{base_url}}">
% if integration[0] == "True":
<a class="item" href="{{base_url}}series">
<i class="play icon"></i>
Series
</a>
% end
% if integration[1] == "True":
<a class="item" href="{{base_url}}movies">
<i class="film icon"></i>
Movies
</a>
% end
<a class="item" href="{{base_url}}history">
<i class="wait icon"></i>
History
</a>
<a class="item" href="{{base_url}}wanted">
<i class="warning sign icon">
% if integration[0] == "True":
<div class="floating ui tiny yellow label" style="left:90% !important;top:0.5em !important;">
{{wanted_series[0]}}
</div>
% end
% if integration[1] == "True":
<div class="floating ui tiny green label" style="left:90% !important;top:3em !important;">
{{wanted_movies[0]}}
</div>
% end
</i>
Wanted
</a>
@ -99,7 +108,6 @@
</div>
% restart_required = c.execute("SELECT updated, configured FROM table_settings_general").fetchone()
% conn.commit()
% c.close()
% if restart_required[0] == 1 and restart_required[1] == 1:

View File

@ -29,6 +29,10 @@
margin-bottom: 3em;
padding: 1em;
}
.ui.tabular.menu > .disabled.item {
opacity: 0.45 !important;
pointer-events: none !important;
}
</style>
</head>
<body>
@ -40,12 +44,12 @@
<div id="fondblanc" class="ui container">
<form name="settings_form" id="settings_form" action="{{base_url}}save_settings" method="post" class="ui form">
<div id="form_validation_error" class="ui error message">
<p>Some fields are in error and you can't save settings until you have corrected them.</p>
<p>Some fields are in error and you can't save settings until you have corrected them. Be sure to check in every tabs.</p>
</div>
<div class="ui top attached tabular menu">
<a class="tabs item active" data-tab="general">General</a>
<a class="tabs item" data-tab="sonarr">Sonarr</a>
<a class="tabs item" data-tab="radarr">Radarr</a>
<a class="tabs item" id="sonarr_tab" data-tab="sonarr">Sonarr</a>
<a class="tabs item" id="radarr_tab" data-tab="radarr">Radarr</a>
<a class="tabs item" data-tab="subliminal">Subliminal</a>
<a class="tabs item" data-tab="notifier">Notifications</a>
</div>
@ -604,8 +608,8 @@
<div class='field'>
<select name="settings_radarr_sync" id="settings_radarr_sync" class="ui fluid selection dropdown">
<option value="Manually">Manually</option>
<option value="Daily">Daily (at 4am)</option>
<option value="Weekly">Weekly (sunday at 4am)</option>
<option value="Daily">Daily (at 5am)</option>
<option value="Weekly">Weekly (sunday at 5am)</option>
</select>
</div>
</div>
@ -920,16 +924,38 @@
if ($('#settings_use_sonarr').data("enabled") == "True") {
$("#settings_use_sonarr").checkbox('check');
$("#sonarr_tab").removeClass('disabled');
} else {
$("#settings_use_sonarr").checkbox('uncheck');
$("#sonarr_tab").addClass('disabled');
}
$('#settings_use_sonarr').checkbox({
onChecked: function() {
$("#sonarr_tab").removeClass('disabled');
},
onUnchecked: function() {
$("#sonarr_tab").addClass('disabled');
}
});
if ($('#settings_use_radarr').data("enabled") == "True") {
$("#settings_use_radarr").checkbox('check');
$("#radarr_tab").removeClass('disabled');
} else {
$("#settings_use_radarr").checkbox('uncheck');
$("#radarr_tab").addClass('disabled');
}
$('#settings_use_radarr').checkbox({
onChecked: function() {
$("#radarr_tab").removeClass('disabled');
},
onUnchecked: function() {
$("#radarr_tab").addClass('disabled');
}
});
$('.notifier_enabled').each(function(i, obj) {
if ($(this).data("enabled") == 1) {
$(this).checkbox('check');
@ -996,6 +1022,7 @@
]
},
settings_sonarr_ip : {
depends: 'settings_general_use_sonarr',
rules : [
{
type : 'empty'
@ -1003,6 +1030,7 @@
]
},
settings_sonarr_port : {
depends: 'settings_general_use_sonarr',
rules : [
{
type : 'integer[1..65535]'
@ -1013,6 +1041,7 @@
]
},
settings_sonarr_apikey : {
depends: 'settings_general_use_sonarr',
rules : [
{
type : 'exactLength[32]'
@ -1023,6 +1052,7 @@
]
},
settings_radarr_ip : {
depends: 'settings_general_use_radarr',
rules : [
{
type : 'empty'
@ -1030,6 +1060,7 @@
]
},
settings_radarr_port : {
depends: 'settings_general_use_radarr',
rules : [
{
type : 'integer[1..65535]'
@ -1040,6 +1071,7 @@
]
},
settings_radarr_apikey : {
depends: 'settings_general_use_radarr',
rules : [
{
type : 'exactLength[32]'
@ -1081,7 +1113,6 @@
$('#form_validation_error').hide();
$('.submit').removeClass('disabled');
$('#loader').addClass('active');
return false;
}
})
;

View File

@ -37,6 +37,10 @@
}
.fast.backward, .backward, .forward, .fast.forward { pointer-events: auto; }
.fast.backward.disabled, .backward.disabled, .forward.disabled, .fast.forward.disabled { pointer-events: none; }
.ui.tabular.menu > .disabled.item {
opacity: 0.45 !important;
pointer-events: none !important;
}
</style>
</head>
<body>
@ -54,14 +58,23 @@
</div>
% include('menu.tpl')
% import os
% import sqlite3
% conn = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30)
% c = conn.cursor()
% integration = c.execute("SELECT use_sonarr, use_radarr FROM table_settings_general").fetchone()
% c.close()
<div id="fondblanc" class="ui container">
<div class="ui top attached tabular menu">
<a id="series_tab" class="tabs item active" data-tab="series">Series
<a id="series_tab" class="tabs item active" data-enabled="{{integration[0]}}" data-tab="series">Series
<div class="ui tiny yellow label">
{{wanted_series[0]}}
</div>
</a>
<a id="movies_tab" class="tabs item" data-tab="movies">Movies
<a id="movies_tab" class="tabs item" data-enabled="{{integration[1]}}" data-tab="movies">Movies
<div class="ui tiny green label">
{{wanted_movies[0]}}
</div>
@ -122,5 +135,21 @@
$('#loader').addClass('active');
})
$( "#series_tab" ).trigger( "click" );
if ($('#series_tab').data("enabled") == "True") {
$("#series_tab").removeClass('disabled');
} else {
$("#series_tab").addClass('disabled');
}
if ($('#movies_tab').data("enabled") == "True") {
$("#movies_tab").removeClass('disabled');
} else {
$("#movies_tab").addClass('disabled');
}
if ($('#series_tab').data("enabled") == "True") {
$( "#series_tab" ).trigger( "click" );
}
if ($('#series_tab').data("enabled") == "False" && $('#movies_tab').data("enabled") == "True") {
$( "#movies_tab" ).trigger( "click" );
}
</script>

View File

@ -48,7 +48,7 @@
<div class="ui container">
<div class="ui right floated basic buttons">
<button id="wanted_search_missing_subtitles" class="ui button"><i class="download icon"></i>Download wanted movies subtitles</button>
<button id="wanted_search_missing_subtitles_movies" class="ui button"><i class="download icon"></i>Download wanted subtitles</button>
</div>
<table id="tablehistory" class="ui very basic selectable table">
<thead>
@ -135,8 +135,8 @@
loadURLmovies({{int(max_page)}});
})
$('#wanted_search_missing_subtitles').click(function(){
window.location = '{{base_url}}wanted_search_missing_subtitles_movies';
$('#wanted_search_missing_subtitles_movies').click(function(){
window.location = '{{base_url}}wanted_search_missing_subtitles';
})
$('.get_subtitle').click(function(){

View File

@ -48,7 +48,7 @@
<div class="ui container">
<div class="ui right floated basic buttons">
<button id="wanted_search_missing_subtitles" class="ui button"><i class="download icon"></i>Download wanted series subtitles</button>
<button id="wanted_search_missing_subtitles" class="ui button"><i class="download icon"></i>Download wanted subtitles</button>
</div>
<table id="tablehistory" class="ui very basic selectable table">
<thead>