From 7f563449c82ff7a4e7afb3771f15f257a9a181a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Louis=20V=C3=A9zina?= <5130500+morpheus65535@users.noreply.github.com> Date: Tue, 12 Feb 2019 06:28:09 -0500 Subject: [PATCH 1/8] Catch sooner if gevent is not installed. --- bazarr/main.py | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/bazarr/main.py b/bazarr/main.py index 79b883afb..d2d3e67a9 100644 --- a/bazarr/main.py +++ b/bazarr/main.py @@ -2,7 +2,20 @@ bazarr_version = '0.7.2' -from gevent import monkey +# Try to import gevent and exit if it's not available. This one is required to use websocket. +try: + from gevent import monkey +except ImportError as e: + logging.exception('BAZARR require gevent Python module to be installed using pip.') + try: + stop_file = open(os.path.join(args.config_dir, "bazarr.stop"), "w") + except Exception as e: + logging.error('BAZARR Cannot create bazarr.stop file.') + else: + stop_file.write('') + stop_file.close() + os._exit(0) + monkey.patch_all() import gc @@ -26,10 +39,10 @@ from init import * from update_db import * from notifier import update_notifier from logger import configure_logging, empty_log +import gevent from gevent.pywsgi import WSGIServer from geventwebsocket import WebSocketError from geventwebsocket.handler import WebSocketHandler -# from cherrypy.wsgiserver import CherryPyWSGIServer from io import BytesIO from six import text_type from beaker.middleware import SessionMiddleware @@ -80,20 +93,6 @@ if "PYCHARM_HOSTED" in os.environ: else: bottle.ERROR_PAGE_TEMPLATE = bottle.ERROR_PAGE_TEMPLATE.replace('if DEBUG and', 'if') -# Install gevent under user directory if it'S not already available. This one is required to use websocket. -try: - import gevent -except ImportError as e: - logging.exception('BAZARR require gevent Python module to be installed using pip.') - try: - stop_file = open(os.path.join(args.config_dir, "bazarr.stop"), "w") - except Exception as e: - logging.error('BAZARR Cannot create bazarr.stop file.') - else: - stop_file.write('') - stop_file.close() - os._exit(0) - # Reset restart required warning on start conn = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30) c = conn.cursor() From 1cdec282029cd6870f45e51401ac1d6200ddcaf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Louis=20V=C3=A9zina?= <5130500+morpheus65535@users.noreply.github.com> Date: Tue, 12 Feb 2019 07:19:48 -0500 Subject: [PATCH 2/8] Catch sooner if gevent is not installed. --- bazarr/main.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bazarr/main.py b/bazarr/main.py index d2d3e67a9..07be4b7ec 100644 --- a/bazarr/main.py +++ b/bazarr/main.py @@ -5,9 +5,12 @@ bazarr_version = '0.7.2' # Try to import gevent and exit if it's not available. This one is required to use websocket. try: from gevent import monkey -except ImportError as e: +except ImportError: + import logging logging.exception('BAZARR require gevent Python module to be installed using pip.') try: + import os + from get_args import args stop_file = open(os.path.join(args.config_dir, "bazarr.stop"), "w") except Exception as e: logging.error('BAZARR Cannot create bazarr.stop file.') From 752e4d931e3869d3e619941c3e8890a77c032c0d Mon Sep 17 00:00:00 2001 From: Halali Date: Tue, 12 Feb 2019 22:57:04 +0100 Subject: [PATCH 3/8] Fix missing arguments in init file --- bazarr/init.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bazarr/init.py b/bazarr/init.py index 1875c09a6..6f384c8b0 100644 --- a/bazarr/init.py +++ b/bazarr/init.py @@ -98,7 +98,7 @@ if cfg.has_section('general'): # Move providers settings from DB to config file try: - db = sqlite3.connect(os.path.join(config_dir, 'db', 'bazarr.db'), timeout=30) + db = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30) c = db.cursor() enabled_providers = c.execute("SELECT * FROM table_settings_providers WHERE enabled = 1").fetchall() settings_providers = c.execute("SELECT * FROM table_settings_providers").fetchall() @@ -125,7 +125,7 @@ try: settings.legendastv.password = provider[3] settings.general.enabled_providers = u'' if not providers_list else ','.join(providers_list) - with open(os.path.join(config_dir, 'config', 'config.ini'), 'w+') as handle: + with open(os.path.join(args.config_dir, 'config', 'config.ini'), 'w+') as handle: settings.write(handle) except: @@ -186,4 +186,4 @@ def init_binaries(): return unrar -init_binaries() \ No newline at end of file +init_binaries() From 4d9e7b0cd14334c877f271425e49ad6ceff50de5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Louis=20V=C3=A9zina?= <5130500+morpheus65535@users.noreply.github.com> Date: Wed, 13 Feb 2019 08:58:18 -0500 Subject: [PATCH 4/8] Fix for refiner when mediaInfo isn'T available from API because Sonarr and Radarr do not analyse video file. --- bazarr/get_episodes.py | 12 ++++++++---- bazarr/get_movies.py | 24 ++++++++++++++---------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/bazarr/get_episodes.py b/bazarr/get_episodes.py index 4f80a2953..aceb74307 100644 --- a/bazarr/get_episodes.py +++ b/bazarr/get_episodes.py @@ -83,11 +83,15 @@ def sync_episodes(): format = episode['episodeFile']['quality']['quality']['name'] resolution = str(episode['episodeFile']['quality']['quality']['resolution']) + 'p' - videoCodec = episode['episodeFile']['mediaInfo']['videoCodec'] - videoCodec = SonarrFormatVideoCodec(videoCodec) + if 'mediaInfo' in episode['episodeFile']: + videoCodec = episode['episodeFile']['mediaInfo']['videoCodec'] + videoCodec = SonarrFormatVideoCodec(videoCodec) - audioCodec = episode['episodeFile']['mediaInfo']['audioCodec'] - audioCodec = SonarrFormatAudioCodec(audioCodec) + audioCodec = episode['episodeFile']['mediaInfo']['audioCodec'] + audioCodec = SonarrFormatAudioCodec(audioCodec) + else: + videoCodec = None + audioCodec = None # Add episodes in sonarr to current episode list current_episodes_sonarr.append(episode['id']) diff --git a/bazarr/get_movies.py b/bazarr/get_movies.py index 695322758..3403b749b 100644 --- a/bazarr/get_movies.py +++ b/bazarr/get_movies.py @@ -86,17 +86,21 @@ def update_movies(): format = movie['movieFile']['quality']['quality']['name'] resolution = movie['movieFile']['quality']['quality']['resolution'].lstrip('r').lower() - videoFormat = movie['movieFile']['mediaInfo']['videoFormat'] - videoCodecID = movie['movieFile']['mediaInfo']['videoCodecID'] - videoProfile = movie['movieFile']['mediaInfo']['videoProfile'] - videoCodecLibrary = movie['movieFile']['mediaInfo']['videoCodecLibrary'] - videoCodec = RadarrFormatVideoCodec(videoFormat, videoCodecID, videoProfile, videoCodecLibrary) + if 'mediaInfo' in movie['movieFile']: + videoFormat = movie['movieFile']['mediaInfo']['videoFormat'] + videoCodecID = movie['movieFile']['mediaInfo']['videoCodecID'] + videoProfile = movie['movieFile']['mediaInfo']['videoProfile'] + videoCodecLibrary = movie['movieFile']['mediaInfo']['videoCodecLibrary'] + videoCodec = RadarrFormatVideoCodec(videoFormat, videoCodecID, videoProfile, videoCodecLibrary) - audioFormat = movie['movieFile']['mediaInfo']['audioFormat'] - audioCodecID = movie['movieFile']['mediaInfo']['audioCodecID'] - audioProfile = movie['movieFile']['mediaInfo']['audioProfile'] - audioAdditionalFeatures = movie['movieFile']['mediaInfo']['audioAdditionalFeatures'] - audioCodec = RadarrFormatAudioCodec(audioFormat, audioCodecID, audioProfile, audioAdditionalFeatures) + audioFormat = movie['movieFile']['mediaInfo']['audioFormat'] + audioCodecID = movie['movieFile']['mediaInfo']['audioCodecID'] + audioProfile = movie['movieFile']['mediaInfo']['audioProfile'] + audioAdditionalFeatures = movie['movieFile']['mediaInfo']['audioAdditionalFeatures'] + audioCodec = RadarrFormatAudioCodec(audioFormat, audioCodecID, audioProfile, audioAdditionalFeatures) + else: + videoCodec = None + audioCodec = None # Add movies in radarr to current movies list current_movies_radarr.append(unicode(movie['tmdbId'])) From 7e6e1ca99fca6593ce5885c493f09103c4e3babe Mon Sep 17 00:00:00 2001 From: Halali Date: Wed, 13 Feb 2019 20:18:25 +0100 Subject: [PATCH 5/8] Remove minimal score filter for manual search --- bazarr/get_subtitle.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bazarr/get_subtitle.py b/bazarr/get_subtitle.py index f1fe7ca11..b5e095ac1 100644 --- a/bazarr/get_subtitle.py +++ b/bazarr/get_subtitle.py @@ -377,8 +377,8 @@ def manual_search(path, language, hi, providers, providers_auth, sceneName, titl score = compute_score(matches, s, video, hearing_impaired=hi) not_matched = scores - matches s.score = score - if score < min_score: - continue + # if score < min_score: + # continue subtitles_list.append( dict(score=round((score / max_score * 100), 2), From 5e11f195eb874c68a846eb6a8139e53ce9fb389e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Louis=20V=C3=A9zina?= <5130500+morpheus65535@users.noreply.github.com> Date: Fri, 15 Feb 2019 12:51:18 -0500 Subject: [PATCH 6/8] Fix for refiner when the API doesn't have all the required information. --- bazarr/get_episodes.py | 14 +++++++++----- bazarr/get_movies.py | 18 ++++++++++-------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/bazarr/get_episodes.py b/bazarr/get_episodes.py index aceb74307..367e57f6c 100644 --- a/bazarr/get_episodes.py +++ b/bazarr/get_episodes.py @@ -84,11 +84,15 @@ def sync_episodes(): resolution = str(episode['episodeFile']['quality']['quality']['resolution']) + 'p' if 'mediaInfo' in episode['episodeFile']: - videoCodec = episode['episodeFile']['mediaInfo']['videoCodec'] - videoCodec = SonarrFormatVideoCodec(videoCodec) - - audioCodec = episode['episodeFile']['mediaInfo']['audioCodec'] - audioCodec = SonarrFormatAudioCodec(audioCodec) + if 'videoCodec' in episode['episodeFile']['mediaInfo']: + videoCodec = episode['episodeFile']['mediaInfo']['videoCodec'] + videoCodec = SonarrFormatVideoCodec(videoCodec) + else: videoCodec = None + + if 'audioCodec' in episode['episodeFile']['mediaInfo']: + audioCodec = episode['episodeFile']['mediaInfo']['audioCodec'] + audioCodec = SonarrFormatAudioCodec(audioCodec) + else: audioCodec = None else: videoCodec = None audioCodec = None diff --git a/bazarr/get_movies.py b/bazarr/get_movies.py index 3403b749b..db56ad768 100644 --- a/bazarr/get_movies.py +++ b/bazarr/get_movies.py @@ -87,16 +87,18 @@ def update_movies(): resolution = movie['movieFile']['quality']['quality']['resolution'].lstrip('r').lower() if 'mediaInfo' in movie['movieFile']: - videoFormat = movie['movieFile']['mediaInfo']['videoFormat'] - videoCodecID = movie['movieFile']['mediaInfo']['videoCodecID'] - videoProfile = movie['movieFile']['mediaInfo']['videoProfile'] - videoCodecLibrary = movie['movieFile']['mediaInfo']['videoCodecLibrary'] + videoFormat = videoCodecID = videoProfile = videoCodecLibrary = None + if 'videoFormat' in movie['movieFile']['mediaInfo']: videoFormat = movie['movieFile']['mediaInfo']['videoFormat'] + if 'videoCodecID' in movie['movieFile']['mediaInfo']: videoCodecID = movie['movieFile']['mediaInfo']['videoCodecID'] + if 'videoProfile' in movie['movieFile']['mediaInfo']: videoProfile = movie['movieFile']['mediaInfo']['videoProfile'] + if 'videoCodecLibrary' in movie['movieFile']['mediaInfo']: videoCodecLibrary = movie['movieFile']['mediaInfo']['videoCodecLibrary'] videoCodec = RadarrFormatVideoCodec(videoFormat, videoCodecID, videoProfile, videoCodecLibrary) - audioFormat = movie['movieFile']['mediaInfo']['audioFormat'] - audioCodecID = movie['movieFile']['mediaInfo']['audioCodecID'] - audioProfile = movie['movieFile']['mediaInfo']['audioProfile'] - audioAdditionalFeatures = movie['movieFile']['mediaInfo']['audioAdditionalFeatures'] + audioFormat = audioCodec = audioProfile = audioAdditionalFeatures = None + if 'audioFormat' in movie['movieFile']['mediaInfo']: audioFormat = movie['movieFile']['mediaInfo']['audioFormat'] + if 'audioCodecID' in movie['movieFile']['mediaInfo']: audioCodecID = movie['movieFile']['mediaInfo']['audioCodecID'] + if 'audioProfile' in movie['movieFile']['mediaInfo']: audioProfile = movie['movieFile']['mediaInfo']['audioProfile'] + if 'audioAdditionalFeatures' in movie['movieFile']['mediaInfo']: audioAdditionalFeatures = movie['movieFile']['mediaInfo']['audioAdditionalFeatures'] audioCodec = RadarrFormatAudioCodec(audioFormat, audioCodecID, audioProfile, audioAdditionalFeatures) else: videoCodec = None From fa1ec9513e0856c73c9d72bae1a0c0abdbe4e516 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Louis=20V=C3=A9zina?= <5130500+morpheus65535@users.noreply.github.com> Date: Fri, 15 Feb 2019 13:24:16 -0500 Subject: [PATCH 7/8] Fix for refiner when the API doesn't have all the required information. --- bazarr/get_movies.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bazarr/get_movies.py b/bazarr/get_movies.py index db56ad768..faba187f1 100644 --- a/bazarr/get_movies.py +++ b/bazarr/get_movies.py @@ -94,7 +94,7 @@ def update_movies(): if 'videoCodecLibrary' in movie['movieFile']['mediaInfo']: videoCodecLibrary = movie['movieFile']['mediaInfo']['videoCodecLibrary'] videoCodec = RadarrFormatVideoCodec(videoFormat, videoCodecID, videoProfile, videoCodecLibrary) - audioFormat = audioCodec = audioProfile = audioAdditionalFeatures = None + audioFormat = audioCodecID = audioProfile = audioAdditionalFeatures = None if 'audioFormat' in movie['movieFile']['mediaInfo']: audioFormat = movie['movieFile']['mediaInfo']['audioFormat'] if 'audioCodecID' in movie['movieFile']['mediaInfo']: audioCodecID = movie['movieFile']['mediaInfo']['audioCodecID'] if 'audioProfile' in movie['movieFile']['mediaInfo']: audioProfile = movie['movieFile']['mediaInfo']['audioProfile'] From 5bbaae54421e219f79f089c4dde6550c1ba7abcc Mon Sep 17 00:00:00 2001 From: Halali Date: Sun, 17 Feb 2019 10:38:45 +0100 Subject: [PATCH 8/8] Add port argument --- bazarr/get_args.py | 2 ++ bazarr/main.py | 8 +++----- views/menu.tpl | 3 ++- views/system.tpl | 3 ++- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/bazarr/get_args.py b/bazarr/get_args.py index 74b68955f..b55a2cf49 100644 --- a/bazarr/get_args.py +++ b/bazarr/get_args.py @@ -13,6 +13,8 @@ def get_args(): config_dir = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', 'data')) parser.add_argument('-c', '--config', default=config_dir, type=str, metavar="DIR", dest="config_dir", help="Directory containing the configuration (default: %s)" % config_dir) + parser.add_argument('-p', '--port', type=int, metavar="PORT", dest="port", + help="Port number (default: 6767)") parser.add_argument('--no-update', default=False, type=bool, const=True, metavar="BOOL", nargs="?", help="Disable update functionality (default: False)") parser.add_argument('--debug', default=False, type=bool, const=True, metavar="BOOL", nargs="?", diff --git a/bazarr/main.py b/bazarr/main.py index 07be4b7ec..a9e88c9ff 100644 --- a/bazarr/main.py +++ b/bazarr/main.py @@ -1887,12 +1887,10 @@ def handle_websocket(): # Mute DeprecationWarning warnings.simplefilter("ignore", DeprecationWarning) - -server = WSGIServer((str(settings.general.ip), int(settings.general.port)), app, handler_class=WebSocketHandler) +server = WSGIServer((str(settings.general.ip), (int(args.port) if args.port else int(settings.general.port))), app, handler_class=WebSocketHandler) try: - logging.info('BAZARR is started and waiting for request on http://' + str(settings.general.ip) + ':' + str( - settings.general.port) + str(base_url)) - # print 'Bazarr is started and waiting for request on http://' + str(ip) + ':' + str(port) + str(base_url) + logging.info('BAZARR is started and waiting for request on http://' + str(settings.general.ip) + ':' + (str( + args.port) if args.port else str(settings.general.port)) + str(base_url)) server.serve_forever() except KeyboardInterrupt: shutdown() diff --git a/views/menu.tpl b/views/menu.tpl index 039f75d15..f30e97fe6 100644 --- a/views/menu.tpl +++ b/views/menu.tpl @@ -192,8 +192,9 @@ }); % from config import settings + % from get_args import args % ip = settings.general.ip - % port = settings.general.port + % port = args.port if args.port else settings.general.port % base_url = settings.general.base_url if ("{{ip}}" === "0.0.0.0") { diff --git a/views/system.tpl b/views/system.tpl index 06b344f7a..40c9482d2 100644 --- a/views/system.tpl +++ b/views/system.tpl @@ -385,8 +385,9 @@ }); % from config import settings + % from get_args import args % ip = settings.general.ip - % port = settings.general.port + % port = args.port if args.port else settings.general.port % base_url = settings.general.base_url if ("{{ip}}" === "0.0.0.0") {