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/get_episodes.py b/bazarr/get_episodes.py index 4f80a2953..367e57f6c 100644 --- a/bazarr/get_episodes.py +++ b/bazarr/get_episodes.py @@ -83,11 +83,19 @@ 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) - - audioCodec = episode['episodeFile']['mediaInfo']['audioCodec'] - audioCodec = SonarrFormatAudioCodec(audioCodec) + if 'mediaInfo' in episode['episodeFile']: + 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 # 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..faba187f1 100644 --- a/bazarr/get_movies.py +++ b/bazarr/get_movies.py @@ -86,17 +86,23 @@ 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 = 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'] - audioCodec = RadarrFormatAudioCodec(audioFormat, audioCodecID, audioProfile, audioAdditionalFeatures) + 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'] + if 'audioAdditionalFeatures' in movie['movieFile']['mediaInfo']: 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'])) diff --git a/bazarr/get_subtitle.py b/bazarr/get_subtitle.py index f823b3704..89bddb557 100644 --- a/bazarr/get_subtitle.py +++ b/bazarr/get_subtitle.py @@ -297,8 +297,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), 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() diff --git a/bazarr/main.py b/bazarr/main.py index e8e2f2460..f88a671b4 100644 --- a/bazarr/main.py +++ b/bazarr/main.py @@ -2,7 +2,23 @@ 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: + 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.') + else: + stop_file.write('') + stop_file.close() + os._exit(0) + monkey.patch_all() import gc @@ -26,10 +42,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 +96,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() @@ -1911,12 +1913,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") {