Update imports and clean up

pull/123/head
Halali 6 years ago
parent 5a1ffdad7c
commit ef8f474cfa

@ -7,7 +7,7 @@ import os
import sys import sys
reload(sys) reload(sys)
sys.setdefaultencoding('utf8') sys.setdefaultencoding('utf8')
sys.path.insert(0,os.path.join(os.path.dirname(__file__), 'libs/')) sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'libs/'))
import sqlite3 import sqlite3
from init_db import * from init_db import *
@ -61,7 +61,7 @@ from update_modules import *
from bottle import route, run, template, static_file, request, redirect, response, HTTPError from bottle import route, run, template, static_file, request, redirect, response, HTTPError
import bottle import bottle
bottle.TEMPLATE_PATH.insert(0,os.path.join(os.path.dirname(__file__), 'views/')) bottle.TEMPLATE_PATH.insert(0, os.path.join(os.path.dirname(__file__), 'views/'))
bottle.debug(True) bottle.debug(True)
bottle.TEMPLATES.clear() bottle.TEMPLATES.clear()
@ -79,19 +79,19 @@ import math
import ast import ast
import hashlib import hashlib
from get_languages import * from get_languages import load_language_in_db, language_from_alpha3
from get_providers import * from get_providers import *
from get_series import * from get_series import *
from get_episodes import * from get_episodes import *
from get_general_settings import * from get_general_settings import base_url, ip, port, path_replace, path_replace_movie
from get_sonarr_settings import * from get_sonarr_settings import get_sonarr_settings
from check_update import * from check_update import check_and_apply_update
from list_subtitles import * from list_subtitles import store_subtitles, store_subtitles_movie, series_scan_subtitles, movies_scan_subtitles, list_missing_subtitles, list_missing_subtitles_movies
from get_subtitle import * from get_subtitle import download_subtitle, series_download_subtitles, movies_download_subtitles, wanted_download_subtitles, wanted_search_missing_subtitles
from utils import * from utils import history_log, history_log_movie
from scheduler import * from scheduler import *
from notifier import send_notifications from notifier import send_notifications, send_notifications_movie
# Reset restart required warning on start # Reset restart required warning on start
conn = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30) conn = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30)
@ -216,7 +216,6 @@ def redirect_root():
@route(base_url + 'series') @route(base_url + 'series')
@custom_auth_basic(check_credentials) @custom_auth_basic(check_credentials)
def series(): def series():
import update_db
single_language = get_general_settings()[7] single_language = get_general_settings()[7]
db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30) db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30)
@ -361,7 +360,7 @@ def edit_serieseditor():
@route(base_url + 'episodes/<no:int>', method='GET') @route(base_url + 'episodes/<no:int>', method='GET')
@custom_auth_basic(check_credentials) @custom_auth_basic(check_credentials)
def episodes(no): def episodes(no):
single_language = get_general_settings()[7] # single_language = get_general_settings()[7]
url_sonarr_short = get_sonarr_settings()[1] url_sonarr_short = get_sonarr_settings()[1]
conn = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30) conn = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30)
@ -378,7 +377,7 @@ def episodes(no):
c.close() c.close()
episodes = reversed(sorted(episodes, key=operator.itemgetter(2))) episodes = reversed(sorted(episodes, key=operator.itemgetter(2)))
seasons_list = [] seasons_list = []
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)
@ -386,7 +385,6 @@ def episodes(no):
@route(base_url + 'movies') @route(base_url + 'movies')
@custom_auth_basic(check_credentials) @custom_auth_basic(check_credentials)
def movies(): def movies():
import update_db
single_language = get_general_settings()[7] single_language = get_general_settings()[7]
db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30) db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30)
@ -498,7 +496,7 @@ def edit_movie(no):
@custom_auth_basic(check_credentials) @custom_auth_basic(check_credentials)
def movie(no): def movie(no):
from get_radarr_settings import get_radarr_settings from get_radarr_settings import get_radarr_settings
single_language = get_general_settings()[7] # single_language = get_general_settings()[7]
url_radarr_short = get_radarr_settings()[1] url_radarr_short = get_radarr_settings()[1]
conn = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30) conn = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30)
@ -1235,132 +1233,132 @@ def execute_task(taskid):
@route(base_url + 'remove_subtitles', method='POST') @route(base_url + 'remove_subtitles', method='POST')
@custom_auth_basic(check_credentials) @custom_auth_basic(check_credentials)
def remove_subtitles(): def remove_subtitles():
episodePath = request.forms.get('episodePath') episodePath = request.forms.get('episodePath')
language = request.forms.get('language') language = request.forms.get('language')
subtitlesPath = request.forms.get('subtitlesPath') subtitlesPath = request.forms.get('subtitlesPath')
sonarrSeriesId = request.forms.get('sonarrSeriesId') sonarrSeriesId = request.forms.get('sonarrSeriesId')
sonarrEpisodeId = request.forms.get('sonarrEpisodeId') sonarrEpisodeId = request.forms.get('sonarrEpisodeId')
try: try:
os.remove(subtitlesPath) os.remove(subtitlesPath)
result = language_from_alpha3(language) + " subtitles deleted from disk." result = language_from_alpha3(language) + " subtitles deleted from disk."
history_log(0, sonarrSeriesId, sonarrEpisodeId, result) history_log(0, sonarrSeriesId, sonarrEpisodeId, result)
except OSError: except OSError:
pass pass
store_subtitles(unicode(episodePath)) store_subtitles(unicode(episodePath))
list_missing_subtitles(sonarrSeriesId) list_missing_subtitles(sonarrSeriesId)
@route(base_url + 'remove_subtitles_movie', method='POST') @route(base_url + 'remove_subtitles_movie', method='POST')
@custom_auth_basic(check_credentials) @custom_auth_basic(check_credentials)
def remove_subtitles_movie(): def remove_subtitles_movie():
moviePath = request.forms.get('moviePath') moviePath = request.forms.get('moviePath')
language = request.forms.get('language') language = request.forms.get('language')
subtitlesPath = request.forms.get('subtitlesPath') subtitlesPath = request.forms.get('subtitlesPath')
radarrId = request.forms.get('radarrId') radarrId = request.forms.get('radarrId')
try: try:
os.remove(subtitlesPath) os.remove(subtitlesPath)
result = language_from_alpha3(language) + " subtitles deleted from disk." result = language_from_alpha3(language) + " subtitles deleted from disk."
history_log_movie(0, radarrId, result) history_log_movie(0, radarrId, result)
except OSError: except OSError:
pass pass
store_subtitles_movie(unicode(moviePath)) store_subtitles_movie(unicode(moviePath))
list_missing_subtitles_movies(radarrId) list_missing_subtitles_movies(radarrId)
@route(base_url + 'get_subtitle', method='POST') @route(base_url + 'get_subtitle', method='POST')
@custom_auth_basic(check_credentials) @custom_auth_basic(check_credentials)
def get_subtitle(): def get_subtitle():
ref = request.environ['HTTP_REFERER'] ref = request.environ['HTTP_REFERER']
episodePath = request.forms.get('episodePath') episodePath = request.forms.get('episodePath')
sceneName = request.forms.get('sceneName') sceneName = request.forms.get('sceneName')
language = request.forms.get('language') language = request.forms.get('language')
hi = request.forms.get('hi') hi = request.forms.get('hi')
sonarrSeriesId = request.forms.get('sonarrSeriesId') sonarrSeriesId = request.forms.get('sonarrSeriesId')
sonarrEpisodeId = request.forms.get('sonarrEpisodeId') sonarrEpisodeId = request.forms.get('sonarrEpisodeId')
tvdbid = request.forms.get('tvdbid') # tvdbid = request.forms.get('tvdbid')
db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30) db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30)
c = db.cursor() c = db.cursor()
c.execute("SELECT * FROM table_settings_providers WHERE enabled = 1") c.execute("SELECT * FROM table_settings_providers WHERE enabled = 1")
enabled_providers = c.fetchall() enabled_providers = c.fetchall()
c.close() c.close()
providers_list = [] providers_list = []
providers_auth = {} providers_auth = {}
if len(enabled_providers) > 0: if len(enabled_providers) > 0:
for provider in enabled_providers: for provider in enabled_providers:
providers_list.append(provider[0]) providers_list.append(provider[0])
try: try:
if provider[2] is not '' and provider[3] is not '': if provider[2] is not '' and provider[3] is not '':
provider_auth = providers_auth.append(provider[0]) provider_auth = providers_auth.append(provider[0])
provider_auth.update({'username':providers[2], 'password':providers[3]}) provider_auth.update({'username':providers[2], 'password':providers[3]})
else: else:
providers_auth = None
except:
providers_auth = None providers_auth = None
else: except:
providers_list = None providers_auth = None
providers_auth = None else:
providers_list = None
try: providers_auth = None
result = download_subtitle(episodePath, language, hi, providers_list, providers_auth, sceneName, 'series')
if result is not None: try:
history_log(1, sonarrSeriesId, sonarrEpisodeId, result) result = download_subtitle(episodePath, language, hi, providers_list, providers_auth, sceneName, 'series')
send_notifications(sonarrSeriesId, sonarrEpisodeId, result) if result is not None:
store_subtitles(unicode(episodePath)) history_log(1, sonarrSeriesId, sonarrEpisodeId, result)
list_missing_subtitles(sonarrSeriesId) send_notifications(sonarrSeriesId, sonarrEpisodeId, result)
redirect(ref) store_subtitles(unicode(episodePath))
except OSError: list_missing_subtitles(sonarrSeriesId)
pass redirect(ref)
except OSError:
pass
@route(base_url + 'get_subtitle_movie', method='POST') @route(base_url + 'get_subtitle_movie', method='POST')
@custom_auth_basic(check_credentials) @custom_auth_basic(check_credentials)
def get_subtitle_movie(): def get_subtitle_movie():
ref = request.environ['HTTP_REFERER'] ref = request.environ['HTTP_REFERER']
moviePath = request.forms.get('moviePath') moviePath = request.forms.get('moviePath')
sceneName = request.forms.get('sceneName') sceneName = request.forms.get('sceneName')
language = request.forms.get('language') language = request.forms.get('language')
hi = request.forms.get('hi') hi = request.forms.get('hi')
radarrId = request.forms.get('radarrId') radarrId = request.forms.get('radarrId')
tmdbid = request.forms.get('tmdbid') # tmdbid = request.forms.get('tmdbid')
db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30) db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30)
c = db.cursor() c = db.cursor()
c.execute("SELECT * FROM table_settings_providers WHERE enabled = 1") c.execute("SELECT * FROM table_settings_providers WHERE enabled = 1")
enabled_providers = c.fetchall() enabled_providers = c.fetchall()
c.close() c.close()
providers_list = [] providers_list = []
providers_auth = {} providers_auth = {}
if len(enabled_providers) > 0: if len(enabled_providers) > 0:
for provider in enabled_providers: for provider in enabled_providers:
providers_list.append(provider[0]) providers_list.append(provider[0])
try: try:
if provider[2] is not '' and provider[3] is not '': if provider[2] is not '' and provider[3] is not '':
provider_auth = providers_auth.append(provider[0]) provider_auth = providers_auth.append(provider[0])
provider_auth.update({'username':providers[2], 'password':providers[3]}) provider_auth.update({'username':providers[2], 'password':providers[3]})
else: else:
providers_auth = None
except:
providers_auth = None providers_auth = None
else: except:
providers_list = None providers_auth = None
providers_auth = None else:
providers_list = None
try: providers_auth = None
result = download_subtitle(moviePath, language, hi, providers_list, providers_auth, sceneName, 'movies')
if result is not None: try:
history_log_movie(1, radarrId, result) result = download_subtitle(moviePath, language, hi, providers_list, providers_auth, sceneName, 'movies')
send_notifications_movie(radarrId, result) if result is not None:
store_subtitles_movie(unicode(moviePath)) history_log_movie(1, radarrId, result)
list_missing_subtitles_movies(radarrId) send_notifications_movie(radarrId, result)
redirect(ref) store_subtitles_movie(unicode(moviePath))
except OSError: list_missing_subtitles_movies(radarrId)
pass redirect(ref)
except OSError:
pass
def configured(): def configured():
conn = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30) conn = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30)

@ -1,4 +1,4 @@
from get_general_settings import * from get_general_settings import get_general_settings
import os import os
import logging import logging

@ -3,8 +3,8 @@ import sqlite3
import requests import requests
import logging import logging
from get_general_settings import * from get_general_settings import path_replace
from list_subtitles import * from list_subtitles import list_missing_subtitles, store_subtitles, series_full_scan_subtitles, movies_full_scan_subtitles
def update_all_episodes(): def update_all_episodes():
series_full_scan_subtitles() series_full_scan_subtitles()

@ -3,13 +3,13 @@ import sqlite3
import requests import requests
import logging import logging
from get_general_settings import * from get_general_settings import get_general_settings, path_replace_movie
from list_subtitles import * from list_subtitles import store_subtitles_movie, list_missing_subtitles_movies
def update_movies(): def update_movies():
from get_radarr_settings import get_radarr_settings from get_radarr_settings import get_radarr_settings
url_radarr = get_radarr_settings()[0] url_radarr = get_radarr_settings()[0]
url_radarr_short = get_radarr_settings()[1] # url_radarr_short = get_radarr_settings()[1]
apikey_radarr = get_radarr_settings()[2] apikey_radarr = get_radarr_settings()[2]
movie_default_enabled = get_general_settings()[18] movie_default_enabled = get_general_settings()[18]
movie_default_language = get_general_settings()[19] movie_default_language = get_general_settings()[19]
@ -108,7 +108,7 @@ def update_movies():
def get_profile_list(): def get_profile_list():
from get_radarr_settings import get_radarr_settings from get_radarr_settings import get_radarr_settings
url_radarr = get_radarr_settings()[0] url_radarr = get_radarr_settings()[0]
url_radarr_short = get_radarr_settings()[1] # url_radarr_short = get_radarr_settings()[1]
apikey_radarr = get_radarr_settings()[2] apikey_radarr = get_radarr_settings()[2]
# Get profiles data from radarr # Get profiles data from radarr

@ -1,6 +1,6 @@
import sqlite3 import sqlite3
import os import os
from subliminal import * from subliminal import provider_manager
# Get providers list from subliminal # Get providers list from subliminal
providers_list = sorted(provider_manager.names()) providers_list = sorted(provider_manager.names())

@ -3,13 +3,12 @@ import sqlite3
import requests import requests
import logging import logging
from get_general_settings import * from get_general_settings import get_general_settings
from list_subtitles import * from list_subtitles import list_missing_subtitles
def update_series(): def update_series():
from get_sonarr_settings import get_sonarr_settings from get_sonarr_settings import get_sonarr_settings
url_sonarr = get_sonarr_settings()[0] url_sonarr = get_sonarr_settings()[0]
url_sonarr_short = get_sonarr_settings()[1]
apikey_sonarr = get_sonarr_settings()[2] apikey_sonarr = get_sonarr_settings()[2]
serie_default_enabled = get_general_settings()[15] serie_default_enabled = get_general_settings()[15]
serie_default_language = get_general_settings()[16] serie_default_language = get_general_settings()[16]
@ -87,7 +86,7 @@ def update_series():
def get_profile_list(): def get_profile_list():
from get_sonarr_settings import get_sonarr_settings from get_sonarr_settings import get_sonarr_settings
url_sonarr = get_sonarr_settings()[0] url_sonarr = get_sonarr_settings()[0]
url_sonarr_short = get_sonarr_settings()[1] # url_sonarr_short = get_sonarr_settings()[1]
apikey_sonarr = get_sonarr_settings()[2] apikey_sonarr = get_sonarr_settings()[2]
# Get profiles data from Sonarr # Get profiles data from Sonarr

@ -3,13 +3,13 @@ import sqlite3
import ast import ast
import logging import logging
import subprocess import subprocess
from babelfish import * from babelfish import Language
from subliminal import * from subliminal import region, scan_video, Video, download_best_subtitles, compute_score, save_subtitles
from get_languages import * from get_languages import language_from_alpha3, alpha2_from_alpha3, alpha3_from_alpha2
from bs4 import UnicodeDammit from bs4 import UnicodeDammit
from get_general_settings import * from get_general_settings import get_general_settings, pp_replace, path_replace, path_replace_movie, path_replace_reverse, path_replace_reverse_movie
from list_subtitles import * from list_subtitles import store_subtitles, list_missing_subtitles, store_subtitles_movie, list_missing_subtitles_movies
from utils import * from utils import history_log, history_log_movie
from notifier import send_notifications, send_notifications_movie from notifier import send_notifications, send_notifications_movie
# configure the cache # configure the cache

@ -2,20 +2,21 @@ import gc
import os import os
import enzyme import enzyme
import babelfish import babelfish
from subliminal import * import logging
from subliminal import core
import sqlite3 import sqlite3
import ast import ast
import langdetect import langdetect
from bs4 import UnicodeDammit from bs4 import UnicodeDammit
from itertools import islice from itertools import islice
from get_general_settings import * from get_general_settings import path_replace_reverse, path_replace, path_replace_reverse_movie, path_replace_movie, get_general_settings
from get_languages import * from get_languages import alpha2_from_alpha3
gc.enable() gc.enable()
def store_subtitles(file): def store_subtitles(file):
languages = [] # languages = []
actual_subtitles = [] actual_subtitles = []
if os.path.exists(file): if os.path.exists(file):
if os.path.splitext(file)[1] == '.mkv': if os.path.splitext(file)[1] == '.mkv':
@ -70,7 +71,7 @@ def store_subtitles(file):
def store_subtitles_movie(file): def store_subtitles_movie(file):
languages = [] # languages = []
actual_subtitles = [] actual_subtitles = []
if os.path.exists(file): if os.path.exists(file):
if os.path.splitext(file)[1] == '.mkv': if os.path.splitext(file)[1] == '.mkv':

@ -1,13 +1,13 @@
from get_general_settings import * from get_general_settings import automatic
from get_sonarr_settings import get_sonarr_settings from get_sonarr_settings import get_sonarr_settings
from get_radarr_settings import get_radarr_settings from get_radarr_settings import get_radarr_settings
from get_general_settings import get_general_settings from get_general_settings import get_general_settings
from get_series import * from get_series import update_series
from get_episodes import * from get_episodes import update_all_episodes, update_all_movies, sync_episodes
from get_movies import * from get_movies import update_movies
from list_subtitles import * from list_subtitles import store_subtitles
from get_subtitle import * from get_subtitle import download_best_subtitles, wanted_search_missing_subtitles
from check_update import * from check_update import check_and_apply_update
from apscheduler.schedulers.background import BackgroundScheduler from apscheduler.schedulers.background import BackgroundScheduler
from datetime import datetime from datetime import datetime

Loading…
Cancel
Save