Merge remote-tracking branch 'origin/development' into morpheus

# Conflicts:
#	bazarr/main.py
This commit is contained in:
Louis Vézina 2019-03-27 15:11:46 -04:00
commit f1ba4ca8dd
9 changed files with 127 additions and 59 deletions

View File

@ -26,7 +26,7 @@ defaults = {
'serie_default_language': '[]',
'serie_default_hi': 'False',
'movie_default_enabled': 'False',
'movie_default_language': [],
'movie_default_language': '[]',
'movie_default_hi': 'False',
'page_size': '25',
'minimum_score_movie': '70',
@ -35,6 +35,7 @@ defaults = {
'enabled_providers': '',
'throtteled_providers': '{}',
'multithreading': 'True',
'chmod_enabled': 'False',
'chmod': '0640',
'subfolder': 'current',
'subfolder_custom': '',

View File

@ -81,7 +81,10 @@ def sync_episodes():
format, resolution = episode['episodeFile']['quality']['quality']['name'].split('-')
except:
format = episode['episodeFile']['quality']['quality']['name']
resolution = str(episode['episodeFile']['quality']['quality']['resolution']) + 'p'
try:
resolution = str(episode['episodeFile']['quality']['quality']['resolution']) + 'p'
except:
resolution = None
if 'mediaInfo' in episode['episodeFile']:
if 'videoCodec' in episode['episodeFile']['mediaInfo']:

View File

@ -84,7 +84,10 @@ def update_movies():
format, resolution = movie['movieFile']['quality']['quality']['name'].split('-')
except:
format = movie['movieFile']['quality']['quality']['name']
try:
resolution = movie['movieFile']['quality']['quality']['resolution'].lstrip('r').lower()
except:
resolution = None
if 'mediaInfo' in movie['movieFile']:
videoFormat = videoCodecID = videoProfile = videoCodecLibrary = None

View File

@ -167,7 +167,7 @@ def download_subtitle(path, language, hi, providers, providers_auth, sceneName,
try:
fld = get_target_folder(path)
chmod = int(settings.general.chmod, 8) if not sys.platform.startswith('win') else None
chmod = int(settings.general.chmod, 8) if not sys.platform.startswith('win') and settings.general.getboolean('chmod_enabled') else None
saved_subtitles = save_subtitles(video.original_path, subtitles, single=single,
tags=None, # fixme
directory=fld,
@ -358,7 +358,7 @@ def manual_download_subtitle(path, language, hi, subtitle, provider, providers_a
try:
score = round(subtitle.score / max_score * 100, 2)
fld = get_target_folder(path)
chmod = int(settings.general.chmod, 8) if not sys.platform.startswith('win') else None
chmod = int(settings.general.chmod, 8) if not sys.platform.startswith('win') and settings.general.getboolean('chmod_enabled') else None
saved_subtitles = save_subtitles(video.original_path, [subtitle], single=single,
tags=None, # fixme
directory=fld,

View File

@ -127,10 +127,14 @@ try:
settings.general.enabled_providers = u'' if not providers_list else ','.join(providers_list)
with open(os.path.join(args.config_dir, 'config', 'config.ini'), 'w+') as handle:
settings.write(handle)
except:
pass
if settings.general.throtteled_providers == '' or None:
settings.general.throtteled_providers = '{}'
with open(os.path.join(args.config_dir, 'config', 'config.ini'), 'w+') as handle:
settings.write(handle)
if not os.path.exists(os.path.normpath(os.path.join(args.config_dir, 'config', 'users.json'))):
cork = Cork(os.path.normpath(os.path.join(args.config_dir, 'config')), initialize=True)

View File

@ -1197,6 +1197,11 @@ def save_settings():
settings_general_debug = 'False'
else:
settings_general_debug = 'True'
settings_general_chmod_enabled = request.forms.get('settings_general_chmod_enabled')
if settings_general_chmod_enabled is None:
settings_general_chmod_enabled = 'False'
else:
settings_general_chmod_enabled = 'True'
settings_general_chmod = request.forms.get('settings_general_chmod')
settings_general_sourcepath = request.forms.getall('settings_general_sourcepath')
settings_general_destpath = request.forms.getall('settings_general_destpath')
@ -1283,6 +1288,7 @@ def save_settings():
settings.general.base_url = text_type(settings_general_baseurl)
settings.general.path_mappings = text_type(settings_general_pathmapping)
settings.general.debug = text_type(settings_general_debug)
settings.general.chmod_enabled = text_type(settings_general_chmod_enabled)
settings.general.chmod = text_type(settings_general_chmod)
settings.general.branch = text_type(settings_general_branch)
settings.general.auto_update = text_type(settings_general_automatic)
@ -1552,57 +1558,42 @@ def check_update():
def system():
authorize()
def get_time_from_interval(interval):
interval_clean = interval.split('[')
interval_clean = interval_clean[1][:-1]
interval_split = interval_clean.split(':')
def get_time_from_interval(td_object):
seconds = int(td_object.total_seconds())
periods = [
('year', 60 * 60 * 24 * 365),
('month', 60 * 60 * 24 * 30),
('day', 60 * 60 * 24),
('hour', 60 * 60),
('minute', 60),
('second', 1)
]
hour = interval_split[0]
minute = interval_split[1].lstrip("0")
second = interval_split[2].lstrip("0")
strings = []
for period_name, period_seconds in periods:
if seconds > period_seconds:
period_value, seconds = divmod(seconds, period_seconds)
has_s = 's' if period_value > 1 else ''
strings.append("%s %s%s" % (period_value, period_name, has_s))
text = "every "
if hour != "0":
text = text + hour
if hour == "1":
text = text + " hour"
else:
text = text + " hours"
if minute != "" and second != "":
text = text + ", "
elif minute == "" and second != "":
text = text + " and "
elif minute != "" and second == "":
text = text + " and "
if minute != "":
text = text + minute
if minute == "1":
text = text + " minute"
else:
text = text + " minutes"
if second != "":
text = text + " and "
if second != "":
text = text + second
if second == "1":
text = text + " second"
else:
text = text + " seconds"
return text
return ", ".join(strings)
def get_time_from_cron(cron):
text = "at "
text = ""
sun = str(cron[4])
hour = str(cron[5])
minute = str(cron[6])
second = str(cron[7])
if sun != "*":
text = "Sunday at "
if hour != "0" and hour != "*":
text = text + hour
if hour == "0" or hour == "1":
text = text + " hour"
elif sun != "*" or hour == "4" or hour == "5":
text = text + "am"
else:
text = text + " hours"
@ -1627,25 +1618,43 @@ def system():
text = text + " second"
else:
text = text + " seconds"
if text != "" and sun == "*":
text = "everyday at " + text
elif text == "":
text = "Never"
return text
task_list = []
for job in scheduler.get_jobs():
if job.next_run_time is not None:
next_run = pretty.date(job.next_run_time.replace(tzinfo=None))
if isinstance(job.trigger, CronTrigger):
if str(job.trigger.__getstate__()['fields'][0]) == "2100":
next_run = 'Never'
else:
next_run = "Never"
next_run = pretty.date(job.next_run_time.replace(tzinfo=None))
if job.trigger.__str__().startswith('interval'):
task_list.append([job.name, get_time_from_interval(str(job.trigger)), next_run, job.id])
elif job.trigger.__str__().startswith('cron'):
if isinstance(job.trigger, IntervalTrigger):
interval = "every " + get_time_from_interval(job.trigger.__getstate__()['interval'])
task_list.append([job.name, interval, next_run, job.id])
elif isinstance(job.trigger, CronTrigger):
task_list.append([job.name, get_time_from_cron(job.trigger.fields), next_run, job.id])
throttled_providers = list_throttled_providers()
with open(os.path.join(args.config_dir, 'config', 'releases.txt'), 'r') as f:
releases = ast.literal_eval(f.read())
i = 0
with open(os.path.join(args.config_dir, 'log', 'bazarr.log')) as f:
for i, l in enumerate(f, 1):
pass
row_count = i
page_size = int(settings.general.page_size)
max_page = int(math.ceil(row_count / (page_size + 0.0)))
try:
with open(os.path.join(args.config_dir, 'config', 'releases.txt'), 'r') as f:
releases = ast.literal_eval(f.read())
except Exception as e:
releases = []
logging.exception('BAZARR cannot parse releases caching file: ' + os.path.join(args.config_dir, 'config', 'releases.txt'))
use_sonarr = settings.general.getboolean('use_sonarr')
apikey_sonarr = settings.sonarr.apikey

View File

@ -29,12 +29,12 @@ def sonarr_full_update():
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, CronTrigger(day_of_week='sun'), hour=4, max_instances=1,
scheduler.add_job(update_all_episodes, CronTrigger(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, CronTrigger(year='2100'), hour=4, max_instances=1, coalesce=True,
scheduler.add_job(update_all_episodes, CronTrigger(year='2100'), max_instances=1, coalesce=True,
misfire_grace_time=15, id='update_all_episodes',
name='Update all episodes subtitles from disk', replace_existing=True)
@ -48,7 +48,7 @@ def radarr_full_update():
id='update_all_movies', name='Update all movies subtitles from disk',
replace_existing=True)
elif full_update == "Weekly":
scheduler.add_job(update_all_movies, CronTrigger(day_of_week='sun'), hour=5, max_instances=1, coalesce=True,
scheduler.add_job(update_all_movies, CronTrigger(day_of_week='sun', hour=5), max_instances=1, coalesce=True,
misfire_grace_time=15, id='update_all_movies',
name='Update all movies subtitles from disk',
replace_existing=True)

View File

@ -87,7 +87,7 @@
<td>
% upgradable_criteria = (row[5], row[2], row[8])
% if upgradable_criteria in upgradable_movies:
% if row[7] in ast.literal_eval(str(row[6])):
% if row[7] and row[7] in ast.literal_eval(str(row[6])):
<div class="ui inverted basic compact icon" data-tooltip="This subtitles is eligible to an upgrade." data-inverted="" data-position="top left">
<i class="ui green recycle icon upgrade"></i>{{row[3]}}
</div>

View File

@ -152,6 +152,17 @@
</div>
</div>
</div>
<div id="chmod_enabled" class="middle aligned row">
<div class="right aligned four wide column">
<label>Enable chmod</label>
</div>
<div class="five wide column">
<div id="settings_chmod_enabled" class="ui toggle checkbox" data-chmod={{settings.general.getboolean('chmod_enabled')}}>
<input name="settings_general_chmod_enabled" type="checkbox">
<label></label>
</div>
</div>
</div>
<div id="chmod" class="middle aligned row">
<div class="right aligned four wide column">
<label>Set subtitle file permissions to</label>
@ -599,7 +610,7 @@
</div>
</div>
<div class="middle aligned row">
<div class="middle aligned row postprocessing">
<div class="right aligned four wide column">
<label>Post-processing command</label>
</div>
@ -610,7 +621,7 @@
</div>
</div>
<div class="middle aligned row">
<div class="middle aligned row postprocessing">
<div class="right aligned four wide column">
<label>Variables you can use in your command (include the double curly brace):</label>
</div>
@ -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 {
@ -2217,6 +2235,21 @@
}
});
if ($('#settings_use_postprocessing').data("postprocessing") === "True") {
$('.postprocessing').show();
} else {
$('.postprocessing').hide();
}
$('#settings_use_postprocessing').checkbox({
onChecked: function() {
$('.postprocessing').show();
},
onUnchecked: function() {
$('.postprocessing').hide();
}
});
if ($('#settings_upgrade_subs').data("upgrade") === "True") {
$('.upgrade_subs').show();
} else {
@ -2232,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();
}
@ -2452,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: [
{