Merge branch 'development' into debug_logging

This commit is contained in:
Louis Vézina 2018-10-18 20:10:33 -04:00
commit ab0f5d80e7
15 changed files with 93 additions and 42 deletions

View File

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

View File

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

View File

@ -87,6 +87,7 @@ import math
import ast
import hashlib
import time
import urllib
from get_languages import load_language_in_db, language_from_alpha3
from get_providers import load_providers, get_providers, get_providers_auth
@ -199,7 +200,7 @@ def redirect_root():
@route(base_url + 'shutdown')
def shutdown():
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:
logging.error('Cannot create bazarr.stop file.')
else:
@ -215,7 +216,7 @@ def restart():
logging.error('Cannot stop CherryPy.')
else:
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:
logging.error('Cannot create bazarr.restart file.')
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")
total_subtitles_list = c.fetchall()
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
@route(base_url + 'serieseditor')
@ -346,7 +347,7 @@ def serieseditor():
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, 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
@ -471,7 +472,7 @@ def episodes(no):
for key, season in itertools.groupby(episodes,operator.itemgetter(2)):
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')
@custom_auth_basic(check_credentials)
@ -498,7 +499,7 @@ def movies():
c.execute("SELECT code2, name FROM table_settings_languages WHERE enabled = 1")
languages = c.fetchall()
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
@route(base_url + 'movieseditor')
@ -520,7 +521,7 @@ def movieseditor():
c.execute("SELECT code2, name FROM table_settings_languages WHERE enabled = 1")
languages = c.fetchall()
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
@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()
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')
@custom_auth_basic(check_credentials)
@ -651,7 +652,7 @@ def search_missing_subtitles_movie(no):
@custom_auth_basic(check_credentials)
def history():
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')
@custom_auth_basic(check_credentials)
@ -689,7 +690,7 @@ def historyseries():
data = c.fetchall()
c.close()
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')
@custom_auth_basic(check_credentials)
@ -727,13 +728,13 @@ def historymovies():
data = c.fetchall()
c.close()
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')
@custom_auth_basic(check_credentials)
def wanted():
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')
@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,))
data = c.fetchall()
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')
@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,))
data = c.fetchall()
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')
@custom_auth_basic(check_credentials)
@ -822,7 +823,7 @@ def settings():
settings_sonarr = get_sonarr_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')
@custom_auth_basic(check_credentials)
@ -1435,7 +1436,7 @@ def system():
for release in r.json():
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>')
@custom_auth_basic(check_credentials)
@ -1449,7 +1450,7 @@ def get_logs(page):
logs_complete.append(line.rstrip())
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>')
@custom_auth_basic(check_credentials)
@ -1689,6 +1690,7 @@ def api_history():
@route(base_url + 'test_url/<protocol>/<url:path>', method='GET')
@custom_auth_basic(check_credentials)
def test_url(protocol, url):
url = urllib.unquote(url)
try:
result = requests.get(protocol + "://" + url, allow_redirects=False).json()['version']
except:

View File

@ -6,6 +6,8 @@ import os
import chardet
import pysrt
import types
from .score import get_equivalent_release_groups
from .video import Episode, Movie
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):
matches.add('title')
# release_group
if (video.release_group and 'release_group' in guess and
sanitize_release_group(guess['release_group']) in
get_equivalent_release_groups(sanitize_release_group(video.release_group))):
matches.add('release_group')
if 'release_group' in guess:
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))):
matches.add('release_group')
break
# resolution
if video.resolution and 'screen_size' in guess and guess['screen_size'] == video.resolution:
matches.add('resolution')
# format
# Guessit may return a list for `format`, which indicates a conflict in the guessing.
# We should match `format` only when it returns single value to avoid false `format` matches
if video.format and guess.get('format') and not isinstance(guess['format'], list) \
and guess['format'].lower() == video.format.lower():
matches.add('format')
if 'format' in guess:
formats = guess["format"]
if not isinstance(formats, types.ListType):
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')
break
# video_codec
if video.video_codec and 'video_codec' in guess and guess['video_codec'] == video.video_codec:
matches.add('video_codec')

View File

@ -46,7 +46,7 @@
</head>
<body>
<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>
% include('menu.tpl')

View File

@ -47,7 +47,7 @@
</head>
<body>
<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 class="ui container">

View File

@ -47,7 +47,7 @@
</head>
<body>
<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 class="ui container">

View File

@ -14,7 +14,7 @@
</head>
<body>
<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 class="content">
<table class="ui very basic selectable table">

View File

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

View File

@ -45,7 +45,7 @@
</head>
<body>
<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>
% include('menu.tpl')

View File

@ -49,7 +49,7 @@
</head>
<body>
<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>
% include('menu.tpl')

View File

@ -45,7 +45,7 @@
</head>
<body>
<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>
% include('menu.tpl')

View File

@ -49,7 +49,7 @@
</head>
<body>
<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>
% include('menu.tpl')

View File

@ -37,7 +37,7 @@
</head>
<body>
<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>
% include('menu.tpl')

View File

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