Implement series editor #6

This commit is contained in:
morpheus65535 2018-01-07 12:29:11 -05:00
parent aeda900052
commit 1ce9b5c9ef
3 changed files with 236 additions and 6 deletions

View File

@ -21,6 +21,7 @@ from io import BytesIO
from fdsend import send_file
import urllib
import math
import ast
from init_db import *
from update_db import *
@ -149,6 +150,24 @@ def series():
output = template('series', __file__=__file__, bazarr_version=bazarr_version, rows=data, languages=languages, missing_count=missing_count, page=page, max_page=max_page, base_url=base_url)
return output
@route(base_url + 'serieseditor')
def serieseditor():
db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30)
db.create_function("path_substitution", 1, path_replace)
c = db.cursor()
c.execute("SELECT COUNT(*) FROM table_shows")
missing_count = c.fetchone()
missing_count = missing_count[0]
c.execute("SELECT tvdbId, title, path_substitution(path), languages, hearing_impaired, sonarrSeriesId, poster, audio_language FROM table_shows ORDER BY title ASC")
data = c.fetchall()
c.execute("SELECT code2, name FROM table_settings_languages WHERE enabled = 1")
languages = c.fetchall()
c.close()
output = template('serieseditor', __file__=__file__, bazarr_version=bazarr_version, rows=data, languages=languages, missing_count=missing_count, base_url=base_url)
return output
@route(base_url + 'series_json/<query>', method='GET')
def series_json(query):
db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30)
@ -171,12 +190,10 @@ def edit_series(no):
lang = request.forms.getall('languages')
if len(lang) > 0:
if lang[0] == '':
lang = None
else:
pass
pass
else:
lang = None
lang = 'None'
hi = request.forms.get('hearing_impaired')
if hi == "on":
@ -186,7 +203,7 @@ def edit_series(no):
conn = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30)
c = conn.cursor()
c.execute("UPDATE table_shows SET languages = ?, hearing_impaired = ? WHERE tvdbId LIKE ?", (str(lang), hi, no))
c.execute("UPDATE table_shows SET languages = ?, hearing_impaired = ? WHERE sonarrSeriesId LIKE ?", (str(lang), hi, no))
conn.commit()
c.close()
@ -194,6 +211,36 @@ def edit_series(no):
redirect(ref)
@route(base_url + 'edit_serieseditor', method='POST')
def edit_serieseditor():
ref = request.environ['HTTP_REFERER']
series = request.forms.get('series')
series = ast.literal_eval(str('[' + series + ']'))
lang = request.forms.getall('languages')
hi = request.forms.get('hearing_impaired')
conn = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30)
c = conn.cursor()
for serie in series:
if len(lang) > 0:
if str(lang) == "['None']":
lang = 'None'
else:
lang = str(lang)
c.execute("UPDATE table_shows SET languages = ? WHERE sonarrSeriesId LIKE ?", (lang, serie))
if hi != '':
c.execute("UPDATE table_shows SET hearing_impaired = ? WHERE sonarrSeriesId LIKE ?", (hi, serie))
conn.commit()
c.close()
for serie in series:
list_missing_subtitles(serie)
redirect(ref)
@route(base_url + 'episodes/<no:int>', method='GET')
def episodes(no):
from get_sonarr_settings import get_sonarr_settings

View File

@ -49,6 +49,9 @@
% include('menu.tpl')
<div id="fondblanc" class="ui container">
<div class="ui basic buttons">
<button id="serieseditor" class="ui button"><i class="configure icon"></i>Series Editor</button>
</div>
<table id="tableseries" class="ui very basic selectable sortable table">
<thead>
<tr>
@ -213,6 +216,10 @@
location.href="?page={{int(max_page)}}";
})
$('#serieseditor').click(function(){
window.location = '{{base_url}}serieseditor';
})
$('.modal')
.modal({
autofocus: false

176
views/serieseditor.tpl Normal file
View File

@ -0,0 +1,176 @@
<html>
<head>
<!DOCTYPE html>
<script src="{{base_url}}static/jquery/jquery-latest.min.js"></script>
<script src="{{base_url}}static/semantic/semantic.min.js"></script>
<script src="{{base_url}}static/jquery/tablesort.js"></script>
<link rel="stylesheet" href="{{base_url}}static/semantic/semantic.min.css">
<link rel="apple-touch-icon" sizes="120x120" href="{{base_url}}static/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="{{base_url}}static/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="{{base_url}}static/favicon-16x16.png">
<link rel="manifest" href="{{base_url}}static/manifest.json">
<link rel="mask-icon" href="{{base_url}}static/safari-pinned-tab.svg" color="#5bbad5">
<link rel="shortcut icon" href="{{base_url}}static/favicon.ico">
<meta name="msapplication-config" content="{{base_url}}static/browserconfig.xml">
<meta name="theme-color" content="#ffffff">
<title>Series Editor - Bazarr</title>
<style>
body {
background-color: #272727;
}
#fondblanc {
background-color: #ffffff;
border-radius: 0px;
box-shadow: 0px 0px 5px 5px #ffffff;
margin-top: 32px;
margin-bottom: 3em;
padding: 2em 3em 2em 3em;
}
#tableseries {
padding-top: 1em;
}
#divdetails {
min-height: 250px;
}
#bottommenu {
background-color: #333333;
box-shadow: 0 0 10px 1px #333;
padding: 10px;
}
</style>
</head>
<body>
<div id='loader' class="ui page dimmer">
<div class="ui indeterminate text loader">Loading...</div>
</div>
% include('menu.tpl')
<div id="fondblanc" class="ui container">
<table id="tableseries" class="ui very basic selectable sortable table">
<thead>
<tr>
<th class="no-sort collapsing">
<div class="ui checkbox">
<input id='selectall' type="checkbox">
<label></label>
</div>
</th>
<th class="sorted ascending">Name</th>
<th>Audio language</th>
<th>Subtitles languages</th>
<th>Hearing-impaired</th>
</tr>
</thead>
<tbody>
%import ast
%import os
%for row in rows:
<tr class="selectable">
<td class="collapsing">
<div class="ui checkbox">
<input id='{{row[5]}}' type="checkbox" class="selected">
<label></label>
</div>
</td>
<td><a href="{{base_url}}episodes/{{row[5]}}">{{row[1]}}</a></td>
<td>{{row[7]}}</td>
<td>
%subs_languages = ast.literal_eval(str(row[3]))
%if subs_languages is not None:
%for subs_language in subs_languages:
<div class="ui tiny label">{{subs_language}}</div>
%end
%end
</td>
<td>{{!"" if row[4] == None else row[4]}}</td>
</tr>
%end
</tbody>
</table>
</div>
<div id='bottommenu' class="ui inverted bottom fixed menu">
<form style='width: 100%; padding-left: 8em;' action="{{base_url}}edit_serieseditor" method="POST" class="ui form">
<input type="hidden" name="series" id="checked" />
<div class="fields">
<div class="eight wide field">
<label style='color: white;'>Subtitles languages</label>
<select name="languages" multiple="" class="select ui disabled selection dropdown">
<option value="">No change</option>
<option value="None">None</option>
%for language in languages:
<option value="{{language[0]}}">{{language[1]}}</option>
%end
</select>
</div>
<div class="field">
<label style='color: white;'>Hearing-impaired</label>
<select name="hearing_impaired" class="select ui disabled selection dropdown">
<option value="">No change</option>
<option value="True">True</option>
<option value="False">False</option>
</select>
</div>
<div class='field'>
<label style='color: white;'><span id='count'>0</span> series selected</label>
<button type="submit" id="save" name="save" value="save" class="ui disabled blue approve button">Save</button>
</div>
</div>
</form>
</div>
% include('footer.tpl')
<br><br><br><br>
</body>
</html>
<script>
if (sessionStorage.scrolly) {
$(window).scrollTop(sessionStorage.scrolly);
sessionStorage.clear();
}
$('table').tablesort();
$('a, button').click(function(){
$('#loader').addClass('active');
})
$('.modal')
.modal({
autofocus: false
})
;
$('.selected').change(function() {
$("#count").text($('.selected:checked').length);
if ( $('.selected:checked').length > 0 ) {
$('.select').removeClass('disabled');
$('#save').removeClass('disabled');
}
else {
$('.select').addClass('disabled');
$('#save').addClass('disabled');
}
var result = [];
$('.selected:checked').each(function(i){
result.push($(this).attr('id'));
});
$("#checked").val(result);
});
$('#selectall').change(function() {
if ( $('#selectall').is(":checked") ) {
$('.selected').prop('checked', true).change();
}
else {
$('.selected').prop('checked', false).change();
}
});
$('.select').dropdown();
</script>