Merge branch 'development' into debug_logging

pull/222/head
Louis Vézina 6 years ago
commit ab0f5d80e7

@ -5,6 +5,9 @@ import os
import sys import sys
import getopt import getopt
config_dir = os.path.join(os.path.dirname(__file__), 'data/')
no_update = False
arguments = [] arguments = []
try: try:
opts, args = getopt.getopt(sys.argv[1:],"h:",["no-update", "config="]) opts, args = getopt.getopt(sys.argv[1:],"h:",["no-update", "config="])
@ -16,6 +19,14 @@ for opt, arg in opts:
if arg != '': if arg != '':
arguments.append(arg) arguments.append(arg)
if opt == '-h':
print 'bazarr.py -h --no-update --config <config_directory>'
sys.exit()
elif opt in ("--no-update"):
no_update = True
elif opt in ("--config"):
config_dir = arg
dir_name = os.path.dirname(__file__) dir_name = os.path.dirname(__file__)
@ -32,8 +43,8 @@ def start_bazarr():
if __name__ == '__main__': if __name__ == '__main__':
restartfile = os.path.normcase(os.path.join(globals()['dir_name'], 'bazarr.restart')) restartfile = os.path.normcase(os.path.join(config_dir, 'bazarr.restart'))
stopfile = os.path.normcase(os.path.join(globals()['dir_name'], 'bazarr.stop')) stopfile = os.path.normcase(os.path.join(config_dir, 'bazarr.stop'))
try: try:
os.remove(restartfile) os.remove(restartfile)

@ -8,7 +8,7 @@ import sqlite3
import git import git
current_working_directory = os.path.dirname(__file__) current_working_directory = os.path.dirname(os.path.dirname(__file__))
def gitconfig(): def gitconfig():
g = git.Repo.init(current_working_directory) g = git.Repo.init(current_working_directory)

@ -87,6 +87,7 @@ import math
import ast import ast
import hashlib import hashlib
import time import time
import urllib
from get_languages import load_language_in_db, language_from_alpha3 from get_languages import load_language_in_db, language_from_alpha3
from get_providers import load_providers, get_providers, get_providers_auth from get_providers import load_providers, get_providers, get_providers_auth
@ -199,7 +200,7 @@ def redirect_root():
@route(base_url + 'shutdown') @route(base_url + 'shutdown')
def shutdown(): def shutdown():
try: try:
stop_file = open(os.path.join(os.path.dirname(os.path.dirname(__file__)), "bazarr.stop"), "w") stop_file = open(os.path.join(config_dir, "bazarr.stop"), "w")
except Exception as e: except Exception as e:
logging.error('Cannot create bazarr.stop file.') logging.error('Cannot create bazarr.stop file.')
else: else:
@ -215,7 +216,7 @@ def restart():
logging.error('Cannot stop CherryPy.') logging.error('Cannot stop CherryPy.')
else: else:
try: try:
restart_file = open(os.path.join(os.path.dirname(os.path.dirname(__file__)), "bazarr.restart"), "w") restart_file = open(os.path.join(config_dir, "bazarr.restart"), "w")
except Exception as e: except Exception as e:
logging.error('Cannot create bazarr.restart file.') logging.error('Cannot create bazarr.restart file.')
else: else:
@ -324,7 +325,7 @@ def series():
c.execute("SELECT table_shows.sonarrSeriesId, COUNT(table_episodes.missing_subtitles) FROM table_shows LEFT JOIN table_episodes ON table_shows.sonarrSeriesId=table_episodes.sonarrSeriesId WHERE table_shows.languages IS NOT 'None' GROUP BY table_shows.sonarrSeriesId") c.execute("SELECT table_shows.sonarrSeriesId, COUNT(table_episodes.missing_subtitles) FROM table_shows LEFT JOIN table_episodes ON table_shows.sonarrSeriesId=table_episodes.sonarrSeriesId WHERE table_shows.languages IS NOT 'None' GROUP BY table_shows.sonarrSeriesId")
total_subtitles_list = c.fetchall() total_subtitles_list = c.fetchall()
c.close() c.close()
output = template('series', __file__=__file__, bazarr_version=bazarr_version, rows=data, missing_subtitles_list=missing_subtitles_list, total_subtitles_list=total_subtitles_list, languages=languages, missing_count=missing_count, page=page, max_page=max_page, base_url=base_url, single_language=single_language, page_size=page_size) output = template('series', __file__=__file__, bazarr_version=bazarr_version, rows=data, missing_subtitles_list=missing_subtitles_list, total_subtitles_list=total_subtitles_list, languages=languages, missing_count=missing_count, page=page, max_page=max_page, base_url=base_url, single_language=single_language, page_size=page_size, current_port=port)
return output return output
@route(base_url + 'serieseditor') @route(base_url + 'serieseditor')
@ -346,7 +347,7 @@ def serieseditor():
c.execute("SELECT code2, name FROM table_settings_languages WHERE enabled = 1") c.execute("SELECT code2, name FROM table_settings_languages WHERE enabled = 1")
languages = c.fetchall() languages = c.fetchall()
c.close() c.close()
output = template('serieseditor', __file__=__file__, bazarr_version=bazarr_version, rows=data, languages=languages, missing_count=missing_count, base_url=base_url, single_language=single_language) output = template('serieseditor', __file__=__file__, bazarr_version=bazarr_version, rows=data, languages=languages, missing_count=missing_count, base_url=base_url, single_language=single_language, current_port=port)
return output return output
@ -471,7 +472,7 @@ def episodes(no):
for key, season in itertools.groupby(episodes,operator.itemgetter(2)): for key, season in itertools.groupby(episodes,operator.itemgetter(2)):
seasons_list.append(list(season)) seasons_list.append(list(season))
return template('episodes', __file__=__file__, bazarr_version=bazarr_version, no=no, details=series_details, languages=languages, seasons=seasons_list, url_sonarr_short=url_sonarr_short, base_url=base_url, tvdbid=tvdbid, number=number) return template('episodes', __file__=__file__, bazarr_version=bazarr_version, no=no, details=series_details, languages=languages, seasons=seasons_list, url_sonarr_short=url_sonarr_short, base_url=base_url, tvdbid=tvdbid, number=number, current_port=port)
@route(base_url + 'movies') @route(base_url + 'movies')
@custom_auth_basic(check_credentials) @custom_auth_basic(check_credentials)
@ -498,7 +499,7 @@ def movies():
c.execute("SELECT code2, name FROM table_settings_languages WHERE enabled = 1") c.execute("SELECT code2, name FROM table_settings_languages WHERE enabled = 1")
languages = c.fetchall() languages = c.fetchall()
c.close() c.close()
output = template('movies', __file__=__file__, bazarr_version=bazarr_version, rows=data, languages=languages, missing_count=missing_count, page=page, max_page=max_page, base_url=base_url, single_language=single_language, page_size=page_size) output = template('movies', __file__=__file__, bazarr_version=bazarr_version, rows=data, languages=languages, missing_count=missing_count, page=page, max_page=max_page, base_url=base_url, single_language=single_language, page_size=page_size, current_port=port)
return output return output
@route(base_url + 'movieseditor') @route(base_url + 'movieseditor')
@ -520,7 +521,7 @@ def movieseditor():
c.execute("SELECT code2, name FROM table_settings_languages WHERE enabled = 1") c.execute("SELECT code2, name FROM table_settings_languages WHERE enabled = 1")
languages = c.fetchall() languages = c.fetchall()
c.close() c.close()
output = template('movieseditor', __file__=__file__, bazarr_version=bazarr_version, rows=data, languages=languages, missing_count=missing_count, base_url=base_url, single_language=single_language) output = template('movieseditor', __file__=__file__, bazarr_version=bazarr_version, rows=data, languages=languages, missing_count=missing_count, base_url=base_url, single_language=single_language, current_port=port)
return output return output
@route(base_url + 'edit_movieseditor', method='POST') @route(base_url + 'edit_movieseditor', method='POST')
@ -605,7 +606,7 @@ def movie(no):
languages = c.execute("SELECT code2, name FROM table_settings_languages WHERE enabled = 1").fetchall() languages = c.execute("SELECT code2, name FROM table_settings_languages WHERE enabled = 1").fetchall()
c.close() c.close()
return template('movie', __file__=__file__, bazarr_version=bazarr_version, no=no, details=movies_details, languages=languages, url_radarr_short=url_radarr_short, base_url=base_url, tmdbid=tmdbid) return template('movie', __file__=__file__, bazarr_version=bazarr_version, no=no, details=movies_details, languages=languages, url_radarr_short=url_radarr_short, base_url=base_url, tmdbid=tmdbid, current_port=port)
@route(base_url + 'scan_disk/<no:int>', method='GET') @route(base_url + 'scan_disk/<no:int>', method='GET')
@custom_auth_basic(check_credentials) @custom_auth_basic(check_credentials)
@ -651,7 +652,7 @@ def search_missing_subtitles_movie(no):
@custom_auth_basic(check_credentials) @custom_auth_basic(check_credentials)
def history(): def history():
authorize() authorize()
return template('history', __file__=__file__, bazarr_version=bazarr_version, base_url=base_url) return template('history', __file__=__file__, bazarr_version=bazarr_version, base_url=base_url, current_port=port)
@route(base_url + 'historyseries') @route(base_url + 'historyseries')
@custom_auth_basic(check_credentials) @custom_auth_basic(check_credentials)
@ -689,7 +690,7 @@ def historyseries():
data = c.fetchall() data = c.fetchall()
c.close() c.close()
data = reversed(sorted(data, key=operator.itemgetter(4))) data = reversed(sorted(data, key=operator.itemgetter(4)))
return template('historyseries', __file__=__file__, 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) return template('historyseries', __file__=__file__, 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=port)
@route(base_url + 'historymovies') @route(base_url + 'historymovies')
@custom_auth_basic(check_credentials) @custom_auth_basic(check_credentials)
@ -727,13 +728,13 @@ def historymovies():
data = c.fetchall() data = c.fetchall()
c.close() c.close()
data = reversed(sorted(data, key=operator.itemgetter(2))) data = reversed(sorted(data, key=operator.itemgetter(2)))
return template('historymovies', __file__=__file__, 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) return template('historymovies', __file__=__file__, 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=port)
@route(base_url + 'wanted') @route(base_url + 'wanted')
@custom_auth_basic(check_credentials) @custom_auth_basic(check_credentials)
def wanted(): def wanted():
authorize() authorize()
return template('wanted', __file__=__file__, bazarr_version=bazarr_version, base_url=base_url) return template('wanted', __file__=__file__, bazarr_version=bazarr_version, base_url=base_url, current_port=port)
@route(base_url + 'wantedseries') @route(base_url + 'wantedseries')
@custom_auth_basic(check_credentials) @custom_auth_basic(check_credentials)
@ -761,7 +762,7 @@ def wantedseries():
c.execute("SELECT table_shows.title, table_episodes.season || 'x' || table_episodes.episode, table_episodes.title, table_episodes.missing_subtitles, table_episodes.sonarrSeriesId, path_substitution(table_episodes.path), table_shows.hearing_impaired, table_episodes.sonarrEpisodeId, table_episodes.scene_name FROM table_episodes INNER JOIN table_shows on table_shows.sonarrSeriesId = table_episodes.sonarrSeriesId WHERE table_episodes.missing_subtitles != '[]'" + monitored_only_query_string + " ORDER BY table_episodes._rowid_ DESC LIMIT ? OFFSET ?", (page_size, offset,)) c.execute("SELECT table_shows.title, table_episodes.season || 'x' || table_episodes.episode, table_episodes.title, table_episodes.missing_subtitles, table_episodes.sonarrSeriesId, path_substitution(table_episodes.path), table_shows.hearing_impaired, table_episodes.sonarrEpisodeId, table_episodes.scene_name FROM table_episodes INNER JOIN table_shows on table_shows.sonarrSeriesId = table_episodes.sonarrSeriesId WHERE table_episodes.missing_subtitles != '[]'" + monitored_only_query_string + " ORDER BY table_episodes._rowid_ DESC LIMIT ? OFFSET ?", (page_size, offset,))
data = c.fetchall() data = c.fetchall()
c.close() c.close()
return template('wantedseries', __file__=__file__, bazarr_version=bazarr_version, rows=data, missing_count=missing_count, page=page, max_page=max_page, base_url=base_url, page_size=page_size) return template('wantedseries', __file__=__file__, bazarr_version=bazarr_version, rows=data, missing_count=missing_count, page=page, max_page=max_page, base_url=base_url, page_size=page_size, current_port=port)
@route(base_url + 'wantedmovies') @route(base_url + 'wantedmovies')
@custom_auth_basic(check_credentials) @custom_auth_basic(check_credentials)
@ -789,7 +790,7 @@ def wantedmovies():
c.execute("SELECT title, missing_subtitles, radarrId, path_substitution(path), hearing_impaired, sceneName FROM table_movies WHERE missing_subtitles != '[]'" + monitored_only_query_string + " ORDER BY _rowid_ DESC LIMIT ? OFFSET ?", (page_size, offset,)) c.execute("SELECT title, missing_subtitles, radarrId, path_substitution(path), hearing_impaired, sceneName FROM table_movies WHERE missing_subtitles != '[]'" + monitored_only_query_string + " ORDER BY _rowid_ DESC LIMIT ? OFFSET ?", (page_size, offset,))
data = c.fetchall() data = c.fetchall()
c.close() c.close()
return template('wantedmovies', __file__=__file__, bazarr_version=bazarr_version, rows=data, missing_count=missing_count, page=page, max_page=max_page, base_url=base_url, page_size=page_size) return template('wantedmovies', __file__=__file__, bazarr_version=bazarr_version, rows=data, missing_count=missing_count, page=page, max_page=max_page, base_url=base_url, page_size=page_size, current_port=port)
@route(base_url + 'wanted_search_missing_subtitles') @route(base_url + 'wanted_search_missing_subtitles')
@custom_auth_basic(check_credentials) @custom_auth_basic(check_credentials)
@ -822,7 +823,7 @@ def settings():
settings_sonarr = get_sonarr_settings() settings_sonarr = get_sonarr_settings()
settings_radarr = get_radarr_settings() settings_radarr = get_radarr_settings()
return template('settings', __file__=__file__, bazarr_version=bazarr_version, settings_general=settings_general, settings_proxy=settings_proxy, settings_auth=settings_auth, settings_languages=settings_languages, settings_providers=settings_providers, settings_sonarr=settings_sonarr, settings_radarr=settings_radarr, settings_notifier=settings_notifier, base_url=base_url) return template('settings', __file__=__file__, bazarr_version=bazarr_version, settings_general=settings_general, settings_proxy=settings_proxy, settings_auth=settings_auth, settings_languages=settings_languages, settings_providers=settings_providers, settings_sonarr=settings_sonarr, settings_radarr=settings_radarr, settings_notifier=settings_notifier, base_url=base_url, current_port=port)
@route(base_url + 'save_settings', method='POST') @route(base_url + 'save_settings', method='POST')
@custom_auth_basic(check_credentials) @custom_auth_basic(check_credentials)
@ -1435,7 +1436,7 @@ def system():
for release in r.json(): for release in r.json():
releases.append([release['name'],release['body']]) releases.append([release['name'],release['body']])
return template('system', __file__=__file__, bazarr_version=bazarr_version, base_url=base_url, task_list=task_list, row_count=row_count, max_page=max_page, page_size=page_size, releases=releases) return template('system', __file__=__file__, bazarr_version=bazarr_version, base_url=base_url, task_list=task_list, row_count=row_count, max_page=max_page, page_size=page_size, releases=releases, current_port=port)
@route(base_url + 'logs/<page:int>') @route(base_url + 'logs/<page:int>')
@custom_auth_basic(check_credentials) @custom_auth_basic(check_credentials)
@ -1449,7 +1450,7 @@ def get_logs(page):
logs_complete.append(line.rstrip()) logs_complete.append(line.rstrip())
logs = logs_complete[begin:end] logs = logs_complete[begin:end]
return template('logs', logs=logs, base_url=base_url) return template('logs', logs=logs, base_url=base_url, current_port=port)
@route(base_url + 'execute/<taskid>') @route(base_url + 'execute/<taskid>')
@custom_auth_basic(check_credentials) @custom_auth_basic(check_credentials)
@ -1689,6 +1690,7 @@ def api_history():
@route(base_url + 'test_url/<protocol>/<url:path>', method='GET') @route(base_url + 'test_url/<protocol>/<url:path>', method='GET')
@custom_auth_basic(check_credentials) @custom_auth_basic(check_credentials)
def test_url(protocol, url): def test_url(protocol, url):
url = urllib.unquote(url)
try: try:
result = requests.get(protocol + "://" + url, allow_redirects=False).json()['version'] result = requests.get(protocol + "://" + url, allow_redirects=False).json()['version']
except: except:

@ -6,6 +6,8 @@ import os
import chardet import chardet
import pysrt import pysrt
import types
from .score import get_equivalent_release_groups from .score import get_equivalent_release_groups
from .video import Episode, Movie from .video import Episode, Movie
from .utils import sanitize, sanitize_release_group from .utils import sanitize, sanitize_release_group
@ -230,19 +232,39 @@ def guess_matches(video, guess, partial=False):
if video.title and 'title' in guess and sanitize(guess['title']) == sanitize(video.title): if video.title and 'title' in guess and sanitize(guess['title']) == sanitize(video.title):
matches.add('title') matches.add('title')
# release_group # release_group
if (video.release_group and 'release_group' in guess and if 'release_group' in guess:
sanitize_release_group(guess['release_group']) in release_groups = guess["release_group"]
if not isinstance(release_groups, types.ListType):
release_groups = [release_groups]
if video.release_group:
for release_group in release_groups:
if (sanitize_release_group(release_group) in
get_equivalent_release_groups(sanitize_release_group(video.release_group))): get_equivalent_release_groups(sanitize_release_group(video.release_group))):
matches.add('release_group') matches.add('release_group')
break
# resolution # resolution
if video.resolution and 'screen_size' in guess and guess['screen_size'] == video.resolution: if video.resolution and 'screen_size' in guess and guess['screen_size'] == video.resolution:
matches.add('resolution') matches.add('resolution')
# format # format
# Guessit may return a list for `format`, which indicates a conflict in the guessing. if 'format' in guess:
# We should match `format` only when it returns single value to avoid false `format` matches formats = guess["format"]
if video.format and guess.get('format') and not isinstance(guess['format'], list) \ if not isinstance(formats, types.ListType):
and guess['format'].lower() == video.format.lower(): formats = [formats]
if video.format:
video_format = video.format
if video_format in ("HDTV", "SDTV", "TV"):
video_format = "TV"
logger.debug("Treating HDTV/SDTV the same")
for frmt in formats:
if frmt in ("HDTV", "SDTV"):
frmt = "TV"
if frmt.lower() == video_format.lower():
matches.add('format') matches.add('format')
break
# video_codec # video_codec
if video.video_codec and 'video_codec' in guess and guess['video_codec'] == video.video_codec: if video.video_codec and 'video_codec' in guess and guess['video_codec'] == video.video_codec:
matches.add('video_codec') matches.add('video_codec')

@ -46,7 +46,7 @@
</head> </head>
<body> <body>
<div id='loader' class="ui page dimmer"> <div id='loader' class="ui page dimmer">
<div class="ui indeterminate text loader">Loading...</div> <div id="loader_text" class="ui indeterminate text loader">Loading...</div>
</div> </div>
% include('menu.tpl') % include('menu.tpl')

@ -47,7 +47,7 @@
</head> </head>
<body> <body>
<div id='loader' class="ui page dimmer"> <div id='loader' class="ui page dimmer">
<div class="ui indeterminate text loader">Loading...</div> <div id="loader_text" class="ui indeterminate text loader">Loading...</div>
</div> </div>
<div class="ui container"> <div class="ui container">

@ -47,7 +47,7 @@
</head> </head>
<body> <body>
<div id='loader' class="ui page dimmer"> <div id='loader' class="ui page dimmer">
<div class="ui indeterminate text loader">Loading...</div> <div id="loader_text" class="ui indeterminate text loader">Loading...</div>
</div> </div>
<div class="ui container"> <div class="ui container">

@ -14,7 +14,7 @@
</head> </head>
<body> <body>
<div id='logs_loader' class="ui page dimmer"> <div id='logs_loader' class="ui page dimmer">
<div class="ui indeterminate text loader">Loading...</div> <div id="loader_text" class="ui indeterminate text loader">Loading...</div>
</div> </div>
<div class="content"> <div class="content">
<table class="ui very basic selectable table"> <table class="ui very basic selectable table">

@ -190,11 +190,19 @@
public_ip = "{{ip}}"; public_ip = "{{ip}}";
} }
protocol = window.location.protocol;
if (window.location.port == '{{current_port}}') {
public_port = '{{port}}';
} else {
public_port = window.location.port;
}
function ping() { function ping() {
$.ajax({ $.ajax({
url: 'http://' + public_ip + ':{{port}}{{base_url}}', url: protocol + '//' + public_ip + ':' + public_port + '{{base_url}}',
success: function(result) { success: function(result) {
window.location.href= 'http://' + public_ip + ':{{port}}{{base_url}}'; window.location.href= protocol + '//' + public_ip + ':' + public_port + '{{base_url}}';
} }
}); });
} }

@ -45,7 +45,7 @@
</head> </head>
<body> <body>
<div id='loader' class="ui page dimmer"> <div id='loader' class="ui page dimmer">
<div class="ui indeterminate text loader">Loading...</div> <div id="loader_text" class="ui indeterminate text loader">Loading...</div>
</div> </div>
% include('menu.tpl') % include('menu.tpl')

@ -49,7 +49,7 @@
</head> </head>
<body> <body>
<div id='loader' class="ui page dimmer"> <div id='loader' class="ui page dimmer">
<div class="ui indeterminate text loader">Loading...</div> <div id="loader_text" class="ui indeterminate text loader">Loading...</div>
</div> </div>
% include('menu.tpl') % include('menu.tpl')

@ -45,7 +45,7 @@
</head> </head>
<body> <body>
<div id='loader' class="ui page dimmer"> <div id='loader' class="ui page dimmer">
<div class="ui indeterminate text loader">Loading...</div> <div id="loader_text" class="ui indeterminate text loader">Loading...</div>
</div> </div>
% include('menu.tpl') % include('menu.tpl')

@ -49,7 +49,7 @@
</head> </head>
<body> <body>
<div id='loader' class="ui page dimmer"> <div id='loader' class="ui page dimmer">
<div class="ui indeterminate text loader">Loading...</div> <div id="loader_text" class="ui indeterminate text loader">Loading...</div>
</div> </div>
% include('menu.tpl') % include('menu.tpl')

@ -37,7 +37,7 @@
</head> </head>
<body> <body>
<div id='loader' class="ui page dimmer"> <div id='loader' class="ui page dimmer">
<div class="ui indeterminate text loader">Loading...</div> <div id="loader_text" class="ui indeterminate text loader">Loading...</div>
</div> </div>
% include('menu.tpl') % include('menu.tpl')

@ -246,11 +246,19 @@
public_ip = "{{ip}}"; public_ip = "{{ip}}";
} }
protocol = window.location.protocol;
if (window.location.port == '{{current_port}}') {
public_port = '{{port}}';
} else {
public_port = window.location.port;
}
function ping() { function ping() {
$.ajax({ $.ajax({
url: 'http://' + public_ip + ':{{port}}{{base_url}}', url: protocol + '//' + public_ip + ':' + public_port + '{{base_url}}',
success: function(result) { success: function(result) {
window.location.href= 'http://' + public_ip + ':{{port}}{{base_url}}'; window.location.href= protocol + '//' + public_ip + ':' + public_port + '{{base_url}}';
} }
}); });
} }

Loading…
Cancel
Save