mirror of
https://github.com/morpheus65535/bazarr.git
synced 2025-04-24 06:37:16 -04:00
rewrite get_argv to get_args; use in daemon and bazarr; fix os.path.join usage; PEPify most
This commit is contained in:
parent
1d1029fa2a
commit
f692930e26
21 changed files with 741 additions and 425 deletions
13
bazarr.py
13
bazarr.py
|
@ -1,16 +1,19 @@
|
|||
# coding=utf-8
|
||||
|
||||
import subprocess as sp
|
||||
import threading
|
||||
import time
|
||||
import os
|
||||
import sys
|
||||
|
||||
from bazarr.get_argv import config_dir, arguments
|
||||
from bazarr import libs
|
||||
from bazarr.get_args import args
|
||||
|
||||
dir_name = os.path.dirname(__file__)
|
||||
|
||||
|
||||
def start_bazarr():
|
||||
script = [sys.executable, "-u", os.path.normcase(os.path.join(globals()['dir_name'], 'bazarr/main.py'))] + arguments
|
||||
script = [sys.executable, "-u", os.path.normcase(os.path.join(dir_name, 'bazarr', 'main.py'))] + sys.argv[1:]
|
||||
|
||||
ep = sp.Popen(script, stdout=sp.PIPE, stderr=sp.STDOUT, stdin=sp.PIPE)
|
||||
print "Bazarr starting..."
|
||||
|
@ -22,8 +25,8 @@ def start_bazarr():
|
|||
|
||||
|
||||
if __name__ == '__main__':
|
||||
restartfile = os.path.normcase(os.path.join(config_dir, 'bazarr.restart'))
|
||||
stopfile = os.path.normcase(os.path.join(config_dir, 'bazarr.stop'))
|
||||
restartfile = os.path.normcase(os.path.join(args.config_dir, 'bazarr.restart'))
|
||||
stopfile = os.path.normcase(os.path.join(args.config_dir, 'bazarr.stop'))
|
||||
|
||||
try:
|
||||
os.remove(restartfile)
|
||||
|
@ -62,4 +65,4 @@ if __name__ == '__main__':
|
|||
|
||||
# Keep the script running forever.
|
||||
while True:
|
||||
time.sleep(0.001)
|
||||
time.sleep(0.001)
|
||||
|
|
|
@ -1,32 +1,34 @@
|
|||
from get_argv import config_dir
|
||||
|
||||
from get_settings import get_general_settings
|
||||
# coding=utf-8
|
||||
|
||||
import os
|
||||
import logging
|
||||
import sqlite3
|
||||
|
||||
import git
|
||||
|
||||
from get_args import args
|
||||
from get_settings import get_general_settings
|
||||
|
||||
current_working_directory = os.path.dirname(os.path.dirname(__file__))
|
||||
|
||||
|
||||
def gitconfig():
|
||||
g = git.Repo.init(current_working_directory)
|
||||
config_read = g.config_reader()
|
||||
config_write = g.config_writer()
|
||||
|
||||
|
||||
try:
|
||||
username = config_read.get_value("user", "name")
|
||||
except:
|
||||
logging.debug('BAZARR Settings git username')
|
||||
config_write.set_value("user", "name", "Bazarr")
|
||||
|
||||
|
||||
try:
|
||||
email = config_read.get_value("user", "email")
|
||||
except:
|
||||
logging.debug('BAZARR Settings git email')
|
||||
config_write.set_value("user", "email", "bazarr@fake.email")
|
||||
|
||||
|
||||
def check_and_apply_update():
|
||||
gitconfig()
|
||||
branch = get_general_settings()[5]
|
||||
|
@ -38,14 +40,15 @@ def check_and_apply_update():
|
|||
else:
|
||||
g.reset('--hard', 'HEAD')
|
||||
g.checkout(branch)
|
||||
g.reset('--hard','origin/' + branch)
|
||||
g.reset('--hard', 'origin/' + branch)
|
||||
g.pull()
|
||||
logging.info('BAZARR Updated to latest version. Restart required. ' + result)
|
||||
updated()
|
||||
|
||||
|
||||
def updated():
|
||||
conn = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
||||
conn = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30)
|
||||
c = conn.cursor()
|
||||
c.execute("UPDATE system SET updated = 1")
|
||||
conn.commit()
|
||||
c.close()
|
||||
c.close()
|
||||
|
|
25
bazarr/get_args.py
Normal file
25
bazarr/get_args.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
# coding=utf-8
|
||||
import os
|
||||
import argparse
|
||||
import arghelper
|
||||
|
||||
from distutils.util import strtobool
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
|
||||
|
||||
def get_args():
|
||||
parser.register('type', bool, strtobool)
|
||||
|
||||
config_dir = os.path.join(os.path.dirname(__file__), '../data/')
|
||||
parser.add_argument('-c', '--config', default=config_dir, type=arghelper.extant_dir, metavar="DIR",
|
||||
dest="config_dir", help="Directory containing the configuration (default: %s)" % config_dir)
|
||||
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="?",
|
||||
help="Enable console debugging (default: False)")
|
||||
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
args = get_args()
|
|
@ -1,29 +0,0 @@
|
|||
import os
|
||||
import sys
|
||||
import getopt
|
||||
|
||||
config_dir = os.path.join(os.path.dirname(__file__), '../data/')
|
||||
no_update = False
|
||||
console_debug = False
|
||||
arguments = []
|
||||
|
||||
|
||||
try:
|
||||
opts, args = getopt.getopt(sys.argv[1:],"h:",["no-update", "config=", "debug"])
|
||||
except getopt.GetoptError:
|
||||
print 'bazarr.py -h --no-update --config <config_directory>'
|
||||
sys.exit(2)
|
||||
|
||||
for opt, arg in opts:
|
||||
arguments.append(opt)
|
||||
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
|
||||
elif opt in "--debug":
|
||||
console_debug = True
|
|
@ -1,33 +1,38 @@
|
|||
from get_argv import config_dir
|
||||
# coding=utf-8
|
||||
|
||||
import os
|
||||
import sqlite3
|
||||
import requests
|
||||
import logging
|
||||
|
||||
from get_args import args
|
||||
from get_settings import path_replace
|
||||
from list_subtitles import list_missing_subtitles, store_subtitles, series_full_scan_subtitles, movies_full_scan_subtitles
|
||||
|
||||
from list_subtitles import list_missing_subtitles, store_subtitles, series_full_scan_subtitles, \
|
||||
movies_full_scan_subtitles
|
||||
|
||||
|
||||
def update_all_episodes():
|
||||
series_full_scan_subtitles()
|
||||
logging.info('BAZARR All existing episode subtitles indexed from disk.')
|
||||
list_missing_subtitles()
|
||||
logging.info('BAZARR All missing episode subtitles updated in database.')
|
||||
|
||||
|
||||
def update_all_movies():
|
||||
movies_full_scan_subtitles()
|
||||
logging.info('BAZARR All existing movie subtitles indexed from disk.')
|
||||
list_missing_subtitles()
|
||||
logging.info('BAZARR All missing movie subtitles updated in database.')
|
||||
|
||||
|
||||
def sync_episodes():
|
||||
logging.debug('BAZARR Starting episode sync from Sonarr.')
|
||||
from get_settings import get_sonarr_settings
|
||||
url_sonarr = get_sonarr_settings()[6]
|
||||
apikey_sonarr = get_sonarr_settings()[4]
|
||||
|
||||
|
||||
# Open database connection
|
||||
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()
|
||||
|
||||
# Get current episodes id in DB
|
||||
|
@ -74,20 +79,30 @@ def sync_episodes():
|
|||
current_episodes_sonarr.append(episode['id'])
|
||||
|
||||
if episode['id'] in current_episodes_db_list:
|
||||
episodes_to_update.append((episode['title'], episode['episodeFile']['path'], episode['seasonNumber'], episode['episodeNumber'], sceneName, str(bool(episode['monitored'])), episode['id']))
|
||||
episodes_to_update.append((episode['title'], episode['episodeFile']['path'],
|
||||
episode['seasonNumber'], episode['episodeNumber'],
|
||||
sceneName, str(bool(episode['monitored'])),
|
||||
episode['id']))
|
||||
else:
|
||||
episodes_to_add.append((episode['seriesId'], episode['id'], episode['title'], episode['episodeFile']['path'], episode['seasonNumber'], episode['episodeNumber'], sceneName, str(bool(episode['monitored']))))
|
||||
episodes_to_add.append((episode['seriesId'], episode['id'], episode['title'],
|
||||
episode['episodeFile']['path'], episode['seasonNumber'],
|
||||
episode['episodeNumber'], sceneName,
|
||||
str(bool(episode['monitored']))))
|
||||
|
||||
removed_episodes = list(set(current_episodes_db_list) - set(current_episodes_sonarr))
|
||||
|
||||
# Update or insert movies in DB
|
||||
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()
|
||||
|
||||
updated_result = c.executemany('''UPDATE table_episodes SET title = ?, path = ?, season = ?, episode = ?, scene_name = ?, monitored = ? WHERE sonarrEpisodeId = ?''', episodes_to_update)
|
||||
updated_result = c.executemany(
|
||||
'''UPDATE table_episodes SET title = ?, path = ?, season = ?, episode = ?, scene_name = ?, monitored = ? WHERE sonarrEpisodeId = ?''',
|
||||
episodes_to_update)
|
||||
db.commit()
|
||||
|
||||
added_result = c.executemany('''INSERT OR IGNORE INTO table_episodes(sonarrSeriesId, sonarrEpisodeId, title, path, season, episode, scene_name, monitored) VALUES (?, ?, ?, ?, ?, ?, ?, ?)''', episodes_to_add)
|
||||
added_result = c.executemany(
|
||||
'''INSERT OR IGNORE INTO table_episodes(sonarrSeriesId, sonarrEpisodeId, title, path, season, episode, scene_name, monitored) VALUES (?, ?, ?, ?, ?, ?, ?, ?)''',
|
||||
episodes_to_add)
|
||||
db.commit()
|
||||
|
||||
for removed_episode in removed_episodes:
|
||||
|
@ -103,4 +118,4 @@ def sync_episodes():
|
|||
logging.debug('BAZARR All episodes synced from Sonarr into database.')
|
||||
|
||||
list_missing_subtitles()
|
||||
logging.debug('BAZARR All missing subtitles updated in database.')
|
||||
logging.debug('BAZARR All missing subtitles updated in database.')
|
||||
|
|
|
@ -1,26 +1,30 @@
|
|||
from get_argv import config_dir
|
||||
# coding=utf-8
|
||||
|
||||
import sqlite3
|
||||
import pycountry
|
||||
import os
|
||||
|
||||
from get_args import args
|
||||
|
||||
|
||||
def load_language_in_db():
|
||||
# Get languages list in langs tuple
|
||||
langs = [[lang.alpha_3,lang.alpha_2,lang.name]
|
||||
for lang in pycountry.languages
|
||||
if hasattr(lang, 'alpha_2')]
|
||||
langs = [[lang.alpha_3, lang.alpha_2, lang.name]
|
||||
for lang in pycountry.languages
|
||||
if hasattr(lang, 'alpha_2')]
|
||||
|
||||
# Open database connection
|
||||
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()
|
||||
|
||||
# Insert languages in database table
|
||||
c.executemany('''INSERT OR IGNORE INTO table_settings_languages(code3, code2, name) VALUES(?, ?, ?)''', langs)
|
||||
c.execute('''INSERT OR IGNORE INTO table_settings_languages(code3, code2, name) VALUES(?, ?, ?)''', ('pob','pb','Brazilian Portuguese'))
|
||||
c.execute('''INSERT OR IGNORE INTO table_settings_languages(code3, code2, name) VALUES(?, ?, ?)''',
|
||||
('pob', 'pb', 'Brazilian Portuguese'))
|
||||
|
||||
langs = [[lang.bibliographic,lang.alpha_3]
|
||||
for lang in pycountry.languages
|
||||
if hasattr(lang, 'alpha_2') and hasattr(lang, 'bibliographic')]
|
||||
langs = [[lang.bibliographic, lang.alpha_3]
|
||||
for lang in pycountry.languages
|
||||
if hasattr(lang, 'alpha_2') and hasattr(lang, 'bibliographic')]
|
||||
|
||||
# Update languages in database table
|
||||
c.executemany('''UPDATE table_settings_languages SET code3b = ? WHERE code3 = ?''', langs)
|
||||
|
@ -31,8 +35,9 @@ def load_language_in_db():
|
|||
# Close database connection
|
||||
db.close()
|
||||
|
||||
|
||||
def language_from_alpha2(lang):
|
||||
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()
|
||||
try:
|
||||
result = c.execute('''SELECT name FROM table_settings_languages WHERE code2 = ?''', (lang,)).fetchone()[0]
|
||||
|
@ -41,32 +46,37 @@ def language_from_alpha2(lang):
|
|||
db.close()
|
||||
return result
|
||||
|
||||
|
||||
def language_from_alpha3(lang):
|
||||
if lang == 'fre':
|
||||
lang = 'fra'
|
||||
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()
|
||||
try:
|
||||
result = c.execute('''SELECT name FROM table_settings_languages WHERE code3 = ? OR code3b = ?''', (lang,lang)).fetchone()[0]
|
||||
result = c.execute('''SELECT name FROM table_settings_languages WHERE code3 = ? OR code3b = ?''',
|
||||
(lang, lang)).fetchone()[0]
|
||||
except:
|
||||
result = None
|
||||
db.close()
|
||||
return result
|
||||
|
||||
|
||||
def alpha2_from_alpha3(lang):
|
||||
if lang == 'fre':
|
||||
lang = 'fra'
|
||||
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()
|
||||
try:
|
||||
result = c.execute('''SELECT code2 FROM table_settings_languages WHERE code3 = ? OR code3b = ?''', (lang,lang)).fetchone()[0]
|
||||
result = c.execute('''SELECT code2 FROM table_settings_languages WHERE code3 = ? OR code3b = ?''',
|
||||
(lang, lang)).fetchone()[0]
|
||||
except:
|
||||
result = None
|
||||
db.close()
|
||||
return result
|
||||
|
||||
|
||||
def alpha2_from_language(lang):
|
||||
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()
|
||||
try:
|
||||
result = c.execute('''SELECT code2 FROM table_settings_languages WHERE name = ?''', (lang,)).fetchone()[0]
|
||||
|
@ -75,8 +85,9 @@ def alpha2_from_language(lang):
|
|||
db.close()
|
||||
return result
|
||||
|
||||
|
||||
def alpha3_from_alpha2(lang):
|
||||
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()
|
||||
try:
|
||||
result = c.execute('''SELECT code3 FROM table_settings_languages WHERE code2 = ?''', (lang,)).fetchone()[0]
|
||||
|
@ -85,8 +96,9 @@ def alpha3_from_alpha2(lang):
|
|||
db.close()
|
||||
return result
|
||||
|
||||
|
||||
def alpha3_from_language(lang):
|
||||
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()
|
||||
try:
|
||||
result = c.execute('''SELECT code3 FROM table_settings_languages WHERE name = ?''', (lang,)).fetchone()[0]
|
||||
|
@ -95,5 +107,6 @@ def alpha3_from_language(lang):
|
|||
db.close()
|
||||
return result
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
load_language_in_db()
|
||||
|
|
|
@ -1,13 +1,15 @@
|
|||
from get_argv import config_dir
|
||||
# coding=utf-8
|
||||
|
||||
import os
|
||||
import sqlite3
|
||||
import requests
|
||||
import logging
|
||||
|
||||
from get_args import args
|
||||
from get_settings import get_general_settings, path_replace_movie
|
||||
from list_subtitles import store_subtitles_movie, list_missing_subtitles_movies
|
||||
|
||||
|
||||
def update_movies():
|
||||
logging.debug('BAZARR Starting movie sync from Radarr.')
|
||||
from get_settings import get_radarr_settings
|
||||
|
@ -37,7 +39,7 @@ def update_movies():
|
|||
logging.exception("BAZARR Error trying to get movies from Radarr.")
|
||||
else:
|
||||
# Get current movies in DB
|
||||
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()
|
||||
current_movies_db = c.execute('SELECT tmdbId FROM table_movies').fetchall()
|
||||
db.close()
|
||||
|
@ -79,39 +81,59 @@ def update_movies():
|
|||
separator = "\\"
|
||||
|
||||
if unicode(movie['tmdbId']) in current_movies_db_list:
|
||||
movies_to_update.append((movie["title"],movie["path"] + separator + movie['movieFile']['relativePath'],movie["tmdbId"],movie["id"],overview,poster,fanart,profile_id_to_language(movie['qualityProfileId']),sceneName,unicode(bool(movie['monitored'])),movie["tmdbId"]))
|
||||
movies_to_update.append((movie["title"],
|
||||
movie["path"] + separator + movie['movieFile']['relativePath'],
|
||||
movie["tmdbId"], movie["id"], overview, poster, fanart,
|
||||
profile_id_to_language(movie['qualityProfileId']), sceneName,
|
||||
unicode(bool(movie['monitored'])), movie["tmdbId"]))
|
||||
else:
|
||||
if movie_default_enabled is True:
|
||||
movies_to_add.append((movie["title"], movie["path"] + separator + movie['movieFile']['relativePath'], movie["tmdbId"], movie_default_language, '[]', movie_default_hi, movie["id"], overview, poster, fanart, profile_id_to_language(movie['qualityProfileId']), sceneName, unicode(bool(movie['monitored']))))
|
||||
movies_to_add.append((movie["title"],
|
||||
movie["path"] + separator + movie['movieFile']['relativePath'],
|
||||
movie["tmdbId"], movie_default_language, '[]', movie_default_hi,
|
||||
movie["id"], overview, poster, fanart,
|
||||
profile_id_to_language(movie['qualityProfileId']), sceneName,
|
||||
unicode(bool(movie['monitored']))))
|
||||
else:
|
||||
movies_to_add.append((movie["title"], movie["path"] + separator + movie['movieFile']['relativePath'], movie["tmdbId"], movie["tmdbId"], movie["tmdbId"], movie["id"], overview, poster, fanart, profile_id_to_language(movie['qualityProfileId']), sceneName, unicode(bool(movie['monitored']))))
|
||||
movies_to_add.append((movie["title"],
|
||||
movie["path"] + separator + movie['movieFile']['relativePath'],
|
||||
movie["tmdbId"], movie["tmdbId"], movie["tmdbId"], movie["id"],
|
||||
overview, poster, fanart,
|
||||
profile_id_to_language(movie['qualityProfileId']), sceneName,
|
||||
unicode(bool(movie['monitored']))))
|
||||
|
||||
# Update or insert movies in DB
|
||||
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()
|
||||
|
||||
updated_result = c.executemany('''UPDATE table_movies SET title = ?, path = ?, tmdbId = ?, radarrId = ?, overview = ?, poster = ?, fanart = ?, `audio_language` = ?, sceneName = ?, monitored = ? WHERE tmdbid = ?''', movies_to_update)
|
||||
updated_result = c.executemany(
|
||||
'''UPDATE table_movies SET title = ?, path = ?, tmdbId = ?, radarrId = ?, overview = ?, poster = ?, fanart = ?, `audio_language` = ?, sceneName = ?, monitored = ? WHERE tmdbid = ?''',
|
||||
movies_to_update)
|
||||
db.commit()
|
||||
|
||||
if movie_default_enabled is True:
|
||||
added_result = c.executemany('''INSERT OR IGNORE INTO table_movies(title, path, tmdbId, languages, subtitles,`hearing_impaired`, radarrId, overview, poster, fanart, `audio_language`, sceneName, monitored) VALUES (?,?,?,?,?, ?, ?, ?, ?, ?, ?, ?, ?)''', movies_to_add)
|
||||
added_result = c.executemany(
|
||||
'''INSERT OR IGNORE INTO table_movies(title, path, tmdbId, languages, subtitles,`hearing_impaired`, radarrId, overview, poster, fanart, `audio_language`, sceneName, monitored) VALUES (?,?,?,?,?, ?, ?, ?, ?, ?, ?, ?, ?)''',
|
||||
movies_to_add)
|
||||
db.commit()
|
||||
else:
|
||||
added_result = c.executemany('''INSERT OR IGNORE INTO table_movies(title, path, tmdbId, languages, subtitles,`hearing_impaired`, radarrId, overview, poster, fanart, `audio_language`, sceneName, monitored) VALUES (?,?,?,(SELECT languages FROM table_movies WHERE tmdbId = ?), '[]',(SELECT `hearing_impaired` FROM table_movies WHERE tmdbId = ?), ?, ?, ?, ?, ?, ?, ?)''', movies_to_add)
|
||||
added_result = c.executemany(
|
||||
'''INSERT OR IGNORE INTO table_movies(title, path, tmdbId, languages, subtitles,`hearing_impaired`, radarrId, overview, poster, fanart, `audio_language`, sceneName, monitored) VALUES (?,?,?,(SELECT languages FROM table_movies WHERE tmdbId = ?), '[]',(SELECT `hearing_impaired` FROM table_movies WHERE tmdbId = ?), ?, ?, ?, ?, ?, ?, ?)''',
|
||||
movies_to_add)
|
||||
db.commit()
|
||||
db.close()
|
||||
|
||||
added_movies = list(set(current_movies_radarr) - set(current_movies_db_list))
|
||||
removed_movies = list(set(current_movies_db_list) - set(current_movies_radarr))
|
||||
|
||||
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()
|
||||
for removed_movie in removed_movies:
|
||||
c.execute('DELETE FROM table_movies WHERE tmdbId = ?', (removed_movie,))
|
||||
db.commit()
|
||||
db.close()
|
||||
|
||||
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()
|
||||
for added_movie in added_movies:
|
||||
added_path = c.execute('SELECT path FROM table_movies WHERE tmdbId = ?', (added_movie,)).fetchone()
|
||||
|
@ -123,6 +145,7 @@ def update_movies():
|
|||
list_missing_subtitles_movies()
|
||||
logging.debug('BAZARR All movie missing subtitles updated in database.')
|
||||
|
||||
|
||||
def get_profile_list():
|
||||
from get_settings import get_radarr_settings
|
||||
url_radarr = get_radarr_settings()[6]
|
||||
|
@ -147,10 +170,12 @@ def get_profile_list():
|
|||
for profile in profiles_json.json():
|
||||
profiles_list.append([profile['id'], profile['language'].capitalize()])
|
||||
|
||||
|
||||
def profile_id_to_language(id):
|
||||
for profile in profiles_list:
|
||||
if id == profile[0]:
|
||||
return profile[1]
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
update_movies()
|
||||
|
|
|
@ -1,30 +1,33 @@
|
|||
from get_argv import config_dir
|
||||
# coding=utf-8
|
||||
|
||||
import sqlite3
|
||||
import os
|
||||
from subliminal_patch.extensions import provider_registry as provider_manager
|
||||
import collections
|
||||
|
||||
from subliminal_patch.extensions import provider_registry as provider_manager
|
||||
from get_args import args
|
||||
|
||||
|
||||
def load_providers():
|
||||
# Get providers list from subliminal
|
||||
providers_list = sorted(provider_manager.names())
|
||||
|
||||
# Open database connection
|
||||
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()
|
||||
|
||||
# Remove unsupported providers
|
||||
providers_in_db = c.execute('SELECT name FROM table_settings_providers').fetchall()
|
||||
for provider_in_db in providers_in_db:
|
||||
if provider_in_db[0] not in providers_list:
|
||||
c.execute('DELETE FROM table_settings_providers WHERE name = ?', (provider_in_db[0], ))
|
||||
c.execute('DELETE FROM table_settings_providers WHERE name = ?', (provider_in_db[0],))
|
||||
|
||||
# Commit changes to database table
|
||||
db.commit()
|
||||
|
||||
# Insert providers in database table
|
||||
for provider_name in providers_list:
|
||||
c.execute('''INSERT OR IGNORE INTO table_settings_providers(name) VALUES(?)''', (provider_name, ))
|
||||
c.execute('''INSERT OR IGNORE INTO table_settings_providers(name) VALUES(?)''', (provider_name,))
|
||||
|
||||
# Commit changes to database table
|
||||
db.commit()
|
||||
|
@ -34,7 +37,7 @@ def load_providers():
|
|||
|
||||
|
||||
def get_providers():
|
||||
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()
|
||||
c.close()
|
||||
|
@ -50,9 +53,10 @@ def get_providers():
|
|||
|
||||
|
||||
def get_providers_auth():
|
||||
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 AND username is not NULL AND password is not NULL").fetchall()
|
||||
enabled_providers = c.execute(
|
||||
"SELECT * FROM table_settings_providers WHERE enabled = 1 AND username is not NULL AND password is not NULL").fetchall()
|
||||
c.close()
|
||||
|
||||
providers_auth = collections.defaultdict(dict)
|
||||
|
@ -64,4 +68,4 @@ def get_providers_auth():
|
|||
else:
|
||||
providers_auth = None
|
||||
|
||||
return providers_auth
|
||||
return providers_auth
|
||||
|
|
|
@ -1,13 +1,15 @@
|
|||
from get_argv import config_dir
|
||||
# coding=utf-8
|
||||
|
||||
import os
|
||||
import sqlite3
|
||||
import requests
|
||||
import logging
|
||||
|
||||
from get_args import args
|
||||
from get_settings import get_general_settings
|
||||
from list_subtitles import list_missing_subtitles
|
||||
|
||||
|
||||
def update_series():
|
||||
from get_settings import get_sonarr_settings
|
||||
url_sonarr = get_sonarr_settings()[6]
|
||||
|
@ -20,7 +22,7 @@ def update_series():
|
|||
pass
|
||||
else:
|
||||
get_profile_list()
|
||||
|
||||
|
||||
# Get shows data from Sonarr
|
||||
url_sonarr_api_series = url_sonarr + "/api/series?apikey=" + apikey_sonarr
|
||||
try:
|
||||
|
@ -36,7 +38,7 @@ def update_series():
|
|||
logging.exception("BAZARR Error trying to get series from Sonarr.")
|
||||
else:
|
||||
# Open database connection
|
||||
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()
|
||||
|
||||
# Get current shows in DB
|
||||
|
@ -69,25 +71,38 @@ def update_series():
|
|||
current_shows_sonarr.append(show['tvdbId'])
|
||||
|
||||
if show['tvdbId'] in current_shows_db_list:
|
||||
series_to_update.append((show["title"],show["path"],show["tvdbId"],show["id"],overview,poster,fanart,profile_id_to_language((show['qualityProfileId'] if sonarr_version == 2 else show['languageProfileId'])),show['sortTitle'],show["tvdbId"]))
|
||||
series_to_update.append((show["title"], show["path"], show["tvdbId"], show["id"], overview, poster,
|
||||
fanart, profile_id_to_language(
|
||||
(show['qualityProfileId'] if sonarr_version == 2 else show['languageProfileId'])),
|
||||
show['sortTitle'], show["tvdbId"]))
|
||||
else:
|
||||
if serie_default_enabled is True:
|
||||
series_to_add.append((show["title"], show["path"], show["tvdbId"], serie_default_language, serie_default_hi, show["id"], overview, poster, fanart, profile_id_to_language(show['qualityProfileId']), show['sortTitle']))
|
||||
series_to_add.append((show["title"], show["path"], show["tvdbId"], serie_default_language,
|
||||
serie_default_hi, show["id"], overview, poster, fanart,
|
||||
profile_id_to_language(show['qualityProfileId']), show['sortTitle']))
|
||||
else:
|
||||
series_to_add.append((show["title"], show["path"], show["tvdbId"], show["tvdbId"], show["tvdbId"], show["id"], overview, poster, fanart, profile_id_to_language(show['qualityProfileId']), show['sortTitle']))
|
||||
series_to_add.append((show["title"], show["path"], show["tvdbId"], show["tvdbId"],
|
||||
show["tvdbId"], show["id"], overview, poster, fanart,
|
||||
profile_id_to_language(show['qualityProfileId']), show['sortTitle']))
|
||||
|
||||
# Update or insert series in DB
|
||||
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()
|
||||
|
||||
updated_result = c.executemany('''UPDATE table_shows SET title = ?, path = ?, tvdbId = ?, sonarrSeriesId = ?, overview = ?, poster = ?, fanart = ?, `audio_language` = ? , sortTitle = ? WHERE tvdbid = ?''', series_to_update)
|
||||
updated_result = c.executemany(
|
||||
'''UPDATE table_shows SET title = ?, path = ?, tvdbId = ?, sonarrSeriesId = ?, overview = ?, poster = ?, fanart = ?, `audio_language` = ? , sortTitle = ? WHERE tvdbid = ?''',
|
||||
series_to_update)
|
||||
db.commit()
|
||||
|
||||
if serie_default_enabled is True:
|
||||
added_result = c.executemany('''INSERT OR IGNORE INTO table_shows(title, path, tvdbId, languages,`hearing_impaired`, sonarrSeriesId, overview, poster, fanart, `audio_language`, sortTitle) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)''', series_to_add)
|
||||
added_result = c.executemany(
|
||||
'''INSERT OR IGNORE INTO table_shows(title, path, tvdbId, languages,`hearing_impaired`, sonarrSeriesId, overview, poster, fanart, `audio_language`, sortTitle) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)''',
|
||||
series_to_add)
|
||||
db.commit()
|
||||
else:
|
||||
added_result = c.executemany('''INSERT OR IGNORE INTO table_shows(title, path, tvdbId, languages,`hearing_impaired`, sonarrSeriesId, overview, poster, fanart, `audio_language`, sortTitle) VALUES (?,?,?,(SELECT languages FROM table_shows WHERE tvdbId = ?),(SELECT `hearing_impaired` FROM table_shows WHERE tvdbId = ?), ?, ?, ?, ?, ?, ?)''', series_to_add)
|
||||
added_result = c.executemany(
|
||||
'''INSERT OR IGNORE INTO table_shows(title, path, tvdbId, languages,`hearing_impaired`, sonarrSeriesId, overview, poster, fanart, `audio_language`, sortTitle) VALUES (?,?,?,(SELECT languages FROM table_shows WHERE tvdbId = ?),(SELECT `hearing_impaired` FROM table_shows WHERE tvdbId = ?), ?, ?, ?, ?, ?, ?)''',
|
||||
series_to_add)
|
||||
db.commit()
|
||||
db.close()
|
||||
|
||||
|
@ -99,12 +114,13 @@ def update_series():
|
|||
for item in current_shows_db_list:
|
||||
if item not in current_shows_sonarr:
|
||||
deleted_items.append(tuple([item]))
|
||||
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()
|
||||
c.executemany('DELETE FROM table_shows WHERE tvdbId = ?',deleted_items)
|
||||
c.executemany('DELETE FROM table_shows WHERE tvdbId = ?', deleted_items)
|
||||
db.commit()
|
||||
db.close()
|
||||
|
||||
|
||||
def get_profile_list():
|
||||
from get_settings import get_sonarr_settings
|
||||
url_sonarr = get_sonarr_settings()[6]
|
||||
|
@ -143,7 +159,7 @@ def get_profile_list():
|
|||
global profiles_list
|
||||
profiles_list = []
|
||||
|
||||
if error is False:
|
||||
if not error:
|
||||
# Parsing data returned from Sonarr
|
||||
global sonarr_version
|
||||
if type(profiles_json_v3.json()) != list:
|
||||
|
@ -155,6 +171,7 @@ def get_profile_list():
|
|||
for profile in profiles_json_v3.json():
|
||||
profiles_list.append([profile['id'], profile['name'].capitalize()])
|
||||
|
||||
|
||||
def profile_id_to_language(id):
|
||||
for profile in profiles_list:
|
||||
if id == profile[0]:
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
from get_argv import config_dir
|
||||
# coding=utf-8
|
||||
|
||||
import os
|
||||
import re
|
||||
|
||||
import ast
|
||||
|
||||
from get_args import args
|
||||
from configparser import ConfigParser
|
||||
|
||||
config_file = os.path.normpath(os.path.join(config_dir, 'config/config.ini'))
|
||||
config_file = os.path.normpath(os.path.join(args.config_dir, 'config', 'config.ini'))
|
||||
|
||||
|
||||
def get_general_settings():
|
||||
cfg = ConfigParser()
|
||||
|
@ -29,7 +31,7 @@ def get_general_settings():
|
|||
|
||||
if cfg.has_option('general', 'base_url'):
|
||||
base_url = cfg.get('general', 'base_url')
|
||||
if base_url.endswith('/') is False:
|
||||
if not base_url.endswith('/'):
|
||||
base_url += '/'
|
||||
else:
|
||||
base_url = '/'
|
||||
|
@ -110,7 +112,7 @@ def get_general_settings():
|
|||
serie_default_hi = 'False'
|
||||
|
||||
if cfg.has_option('general', 'movie_default_enabled'):
|
||||
movie_default_enabled = cfg.getboolean('general', 'movie_default_enabled')
|
||||
movie_default_enabled = cfg.getboolean('general', 'movie_default_enabled')
|
||||
else:
|
||||
movie_default_enabled = False
|
||||
|
||||
|
@ -143,7 +145,7 @@ def get_general_settings():
|
|||
only_monitored = cfg.getboolean('general', 'only_monitored')
|
||||
else:
|
||||
only_monitored = False
|
||||
|
||||
|
||||
if cfg.has_option('general', 'adaptive_searching'):
|
||||
adaptive_searching = cfg.getboolean('general', 'adaptive_searching')
|
||||
else:
|
||||
|
@ -177,7 +179,11 @@ def get_general_settings():
|
|||
only_monitored = False
|
||||
adaptive_searching = False
|
||||
|
||||
return [ip, port, base_url, path_mappings, log_level, branch, auto_update, single_language, minimum_score, use_scenename, use_postprocessing, postprocessing_cmd, use_sonarr, use_radarr, path_mappings_movie, serie_default_enabled, serie_default_language, serie_default_hi, movie_default_enabled,movie_default_language, movie_default_hi, page_size, minimum_score_movie, use_embedded_subs, only_monitored, adaptive_searching]
|
||||
return [ip, port, base_url, path_mappings, log_level, branch, auto_update, single_language, minimum_score,
|
||||
use_scenename, use_postprocessing, postprocessing_cmd, use_sonarr, use_radarr, path_mappings_movie,
|
||||
serie_default_enabled, serie_default_language, serie_default_hi, movie_default_enabled,
|
||||
movie_default_language, movie_default_hi, page_size, minimum_score_movie, use_embedded_subs, only_monitored,
|
||||
adaptive_searching]
|
||||
|
||||
|
||||
def get_auth_settings():
|
||||
|
@ -224,12 +230,12 @@ def get_proxy_settings():
|
|||
proxy_type = cfg.get('proxy', 'type')
|
||||
else:
|
||||
proxy_type = 'None'
|
||||
|
||||
|
||||
if cfg.has_option('proxy', 'url'):
|
||||
url = cfg.get('proxy', 'url')
|
||||
else:
|
||||
url = ''
|
||||
|
||||
|
||||
if cfg.has_option('proxy', 'port'):
|
||||
port = cfg.get('proxy', 'port')
|
||||
else:
|
||||
|
@ -244,7 +250,7 @@ def get_proxy_settings():
|
|||
password = cfg.get('proxy', 'password')
|
||||
else:
|
||||
password = ''
|
||||
|
||||
|
||||
if cfg.has_option('proxy', 'exclude'):
|
||||
exclude = cfg.get('proxy', 'exclude')
|
||||
else:
|
||||
|
@ -321,8 +327,6 @@ def get_sonarr_settings():
|
|||
url_sonarr = protocol_sonarr + "://" + ip + ":" + port + base_url
|
||||
url_sonarr_short = protocol_sonarr + "://" + ip + ":" + port
|
||||
|
||||
|
||||
|
||||
return [ip, port, base_url, ssl, apikey, full_update, url_sonarr, url_sonarr_short]
|
||||
|
||||
|
||||
|
@ -379,7 +383,7 @@ def get_radarr_settings():
|
|||
|
||||
if base_url is None:
|
||||
base_url = "/"
|
||||
if base_url.startswith("/") is False:
|
||||
if not base_url.startswith("/"):
|
||||
base_url = "/" + base_url
|
||||
if base_url.endswith("/"):
|
||||
base_url = base_url[:-1]
|
||||
|
@ -387,8 +391,7 @@ def get_radarr_settings():
|
|||
url_radarr = protocol_radarr + "://" + ip + ":" + port + base_url
|
||||
url_radarr_short = protocol_radarr + "://" + ip + ":" + port
|
||||
|
||||
return [ip, port, base_url, ssl, apikey, full_update, url_radarr , url_radarr_short]
|
||||
|
||||
return [ip, port, base_url, ssl, apikey, full_update, url_radarr, url_radarr_short]
|
||||
|
||||
|
||||
def path_replace(path):
|
||||
|
@ -402,6 +405,7 @@ def path_replace(path):
|
|||
break
|
||||
return path
|
||||
|
||||
|
||||
def path_replace_reverse(path):
|
||||
for path_mapping in path_mappings:
|
||||
if path_mapping[1] in path:
|
||||
|
@ -413,6 +417,7 @@ def path_replace_reverse(path):
|
|||
break
|
||||
return path
|
||||
|
||||
|
||||
def path_replace_movie(path):
|
||||
for path_mapping in path_mappings_movie:
|
||||
if path_mapping[0] in path:
|
||||
|
@ -424,6 +429,7 @@ def path_replace_movie(path):
|
|||
break
|
||||
return path
|
||||
|
||||
|
||||
def path_replace_reverse_movie(path):
|
||||
for path_mapping in path_mappings_movie:
|
||||
if path_mapping[1] in path:
|
||||
|
@ -435,6 +441,7 @@ def path_replace_reverse_movie(path):
|
|||
break
|
||||
return path
|
||||
|
||||
|
||||
def pp_replace(pp_command, episode, subtitles, language, language_code2, language_code3):
|
||||
pp_command = pp_command.replace('{{directory}}', os.path.dirname(episode))
|
||||
pp_command = pp_command.replace('{{episode}}', episode)
|
||||
|
@ -445,6 +452,7 @@ def pp_replace(pp_command, episode, subtitles, language, language_code2, languag
|
|||
pp_command = pp_command.replace('{{subtitles_language_code3}}', language_code3)
|
||||
return pp_command
|
||||
|
||||
|
||||
result = get_general_settings()
|
||||
ip = result[0]
|
||||
port = result[1]
|
||||
|
@ -471,4 +479,4 @@ page_size = result[21]
|
|||
minimum_score_movie = result[22]
|
||||
use_embedded_subs = result[23]
|
||||
only_monitored = result[24]
|
||||
adaptive_searching = result[25]
|
||||
adaptive_searching = result[25]
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from get_argv import config_dir
|
||||
# coding=utf-8
|
||||
|
||||
import os
|
||||
import sqlite3
|
||||
|
@ -7,6 +7,8 @@ import logging
|
|||
import operator
|
||||
import subprocess
|
||||
import time
|
||||
import cPickle as pickle
|
||||
import codecs
|
||||
import subliminal
|
||||
import subliminal_patch
|
||||
from datetime import datetime, timedelta
|
||||
|
@ -18,13 +20,13 @@ from subliminal_patch.score import compute_score
|
|||
from subliminal.subtitle import get_subtitle_path
|
||||
from get_languages import language_from_alpha3, alpha2_from_alpha3, alpha3_from_alpha2
|
||||
from bs4 import UnicodeDammit
|
||||
from get_settings import get_general_settings, pp_replace, path_replace, path_replace_movie, path_replace_reverse, path_replace_reverse_movie
|
||||
from get_settings import get_general_settings, pp_replace, path_replace, path_replace_movie, path_replace_reverse, \
|
||||
path_replace_reverse_movie
|
||||
from list_subtitles import store_subtitles, list_missing_subtitles, store_subtitles_movie, list_missing_subtitles_movies
|
||||
from utils import history_log, history_log_movie
|
||||
from notifier import send_notifications, send_notifications_movie
|
||||
import cPickle as pickle
|
||||
import codecs
|
||||
from get_providers import get_providers, get_providers_auth
|
||||
from get_args import args
|
||||
|
||||
# configure the cache
|
||||
|
||||
|
@ -108,7 +110,7 @@ def download_subtitle(path, language, hi, providers, providers_auth, sceneName,
|
|||
"""
|
||||
|
||||
try:
|
||||
if sceneName == "None" or use_scenename is False:
|
||||
if sceneName == "None" or not use_scenename:
|
||||
used_sceneName = False
|
||||
video = parse_video(path, None, providers=providers)
|
||||
else:
|
||||
|
@ -131,7 +133,8 @@ def download_subtitle(path, language, hi, providers, providers_auth, sceneName,
|
|||
else:
|
||||
subtitles_list = []
|
||||
try:
|
||||
sorted_subtitles = sorted([(s, compute_score(s, video, hearing_impaired=hi)) for s in subtitles], key=operator.itemgetter(1), reverse=True)
|
||||
sorted_subtitles = sorted([(s, compute_score(s, video, hearing_impaired=hi)) for s in subtitles],
|
||||
key=operator.itemgetter(1), reverse=True)
|
||||
except Exception as e:
|
||||
logging.exception('BAZARR Exception raised while trying to compute score for this file: ' + path)
|
||||
return None
|
||||
|
@ -158,27 +161,32 @@ def download_subtitle(path, language, hi, providers, providers_auth, sceneName,
|
|||
if any(elem in required for elem in not_matched):
|
||||
continue
|
||||
subtitles_list.append(s)
|
||||
logging.debug('BAZARR ' + str(len(subtitles_list)) + " subtitles have been found for this file: " + path)
|
||||
logging.debug(
|
||||
'BAZARR ' + str(len(subtitles_list)) + " subtitles have been found for this file: " + path)
|
||||
if len(subtitles_list) > 0:
|
||||
try:
|
||||
pdownload_result = False
|
||||
for subtitle in subtitles_list:
|
||||
download_result = p.download_subtitle(subtitle)
|
||||
if download_result == True:
|
||||
logging.debug('BAZARR Subtitles file downloaded from ' + str(subtitle.provider_name) + ' for this file: ' + path)
|
||||
logging.debug('BAZARR Subtitles file downloaded from ' + str(
|
||||
subtitle.provider_name) + ' for this file: ' + path)
|
||||
break
|
||||
else:
|
||||
logging.warning('BAZARR Subtitles file skipped from ' + str(subtitle.provider_name) + ' for this file: ' + path + ' because no content was returned by the provider (probably throttled).')
|
||||
logging.warning('BAZARR Subtitles file skipped from ' + str(
|
||||
subtitle.provider_name) + ' for this file: ' + path + ' because no content was returned by the provider (probably throttled).')
|
||||
continue
|
||||
if download_result == False:
|
||||
logging.error('BAZARR Tried to download a subtitles for file: ' + path + " but we weren't able to do it this time (probably being throttled). Going to retry on next search.")
|
||||
logging.error(
|
||||
'BAZARR Tried to download a subtitles for file: ' + path + " but we weren't able to do it this time (probably being throttled). Going to retry on next search.")
|
||||
return None
|
||||
except Exception as e:
|
||||
logging.exception('BAZARR Error downloading subtitles for this file ' + path)
|
||||
return None
|
||||
else:
|
||||
try:
|
||||
calculated_score = round(float(compute_score(subtitle, video, hearing_impaired=hi)) / max_score * 100, 2)
|
||||
calculated_score = round(
|
||||
float(compute_score(subtitle, video, hearing_impaired=hi)) / max_score * 100, 2)
|
||||
if used_sceneName == True:
|
||||
video = parse_video(path, None, providers=providers)
|
||||
single = get_general_settings()[7]
|
||||
|
@ -197,20 +205,25 @@ def download_subtitle(path, language, hi, providers, providers_auth, sceneName,
|
|||
downloaded_path = get_subtitle_path(path, language=language_set)
|
||||
logging.debug('BAZARR Subtitles file saved to disk: ' + downloaded_path)
|
||||
if used_sceneName == True:
|
||||
message = downloaded_language + " subtitles downloaded from " + downloaded_provider + " with a score of " + unicode(calculated_score) + "% using this scene name: " + sceneName
|
||||
message = downloaded_language + " subtitles downloaded from " + downloaded_provider + " with a score of " + unicode(
|
||||
calculated_score) + "% using this scene name: " + sceneName
|
||||
else:
|
||||
message = downloaded_language + " subtitles downloaded from " + downloaded_provider + " with a score of " + unicode(calculated_score) + "% using filename guessing."
|
||||
message = downloaded_language + " subtitles downloaded from " + downloaded_provider + " with a score of " + unicode(
|
||||
calculated_score) + "% using filename guessing."
|
||||
|
||||
if use_postprocessing is True:
|
||||
command = pp_replace(postprocessing_cmd, path, downloaded_path, downloaded_language, downloaded_language_code2, downloaded_language_code3)
|
||||
command = pp_replace(postprocessing_cmd, path, downloaded_path, downloaded_language,
|
||||
downloaded_language_code2, downloaded_language_code3)
|
||||
try:
|
||||
if os.name == 'nt':
|
||||
codepage = subprocess.Popen("chcp", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
codepage = subprocess.Popen("chcp", shell=True, stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE)
|
||||
# wait for the process to terminate
|
||||
out_codepage, err_codepage = codepage.communicate()
|
||||
encoding = out_codepage.split(':')[-1].strip()
|
||||
|
||||
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE)
|
||||
# wait for the process to terminate
|
||||
out, err = process.communicate()
|
||||
|
||||
|
@ -219,12 +232,14 @@ def download_subtitle(path, language, hi, providers, providers_auth, sceneName,
|
|||
|
||||
except:
|
||||
if out == "":
|
||||
logging.error('BAZARR Post-processing result for file ' + path + ' : Nothing returned from command execution')
|
||||
logging.error(
|
||||
'BAZARR Post-processing result for file ' + path + ' : Nothing returned from command execution')
|
||||
else:
|
||||
logging.error('BAZARR Post-processing result for file ' + path + ' : ' + out)
|
||||
else:
|
||||
if out == "":
|
||||
logging.info('BAZARR Post-processing result for file ' + path + ' : Nothing returned from command execution')
|
||||
logging.info(
|
||||
'BAZARR Post-processing result for file ' + path + ' : Nothing returned from command execution')
|
||||
else:
|
||||
logging.info('BAZARR Post-processing result for file ' + path + ' : ' + out)
|
||||
|
||||
|
@ -234,6 +249,7 @@ def download_subtitle(path, language, hi, providers, providers_auth, sceneName,
|
|||
return None
|
||||
logging.debug('BAZARR Ended searching subtitles for file: ' + path)
|
||||
|
||||
|
||||
def manual_search(path, language, hi, providers, providers_auth, sceneName, media_type):
|
||||
logging.debug('BAZARR Manually searching subtitles for this file: ' + path)
|
||||
if hi == "True":
|
||||
|
@ -253,7 +269,7 @@ def manual_search(path, language, hi, providers, providers_auth, sceneName, medi
|
|||
postprocessing_cmd = get_general_settings()[11]
|
||||
|
||||
try:
|
||||
if sceneName == "None" or use_scenename is False:
|
||||
if sceneName == "None" or not use_scenename:
|
||||
used_sceneName = False
|
||||
video = parse_video(path, None, providers=providers)
|
||||
else:
|
||||
|
@ -296,12 +312,17 @@ def manual_search(path, language, hi, providers, providers_auth, sceneName, medi
|
|||
continue
|
||||
if used_sceneName:
|
||||
not_matched.remove('hash')
|
||||
subtitles_list.append(dict(score=round((compute_score(s, video, hearing_impaired=hi) / max_score * 100), 2), language=alpha2_from_alpha3(s.language.alpha3), hearing_impaired=str(s.hearing_impaired), provider=s.provider_name, subtitle=codecs.encode(pickle.dumps(s), "base64").decode(), url=s.page_link, matches=list(matched), dont_matches=list(not_matched)))
|
||||
subtitles_list.append(
|
||||
dict(score=round((compute_score(s, video, hearing_impaired=hi) / max_score * 100), 2),
|
||||
language=alpha2_from_alpha3(s.language.alpha3), hearing_impaired=str(s.hearing_impaired),
|
||||
provider=s.provider_name, subtitle=codecs.encode(pickle.dumps(s), "base64").decode(),
|
||||
url=s.page_link, matches=list(matched), dont_matches=list(not_matched)))
|
||||
subtitles_dict = {}
|
||||
subtitles_dict = sorted(subtitles_list, key=lambda x: x['score'], reverse=True)
|
||||
logging.debug('BAZARR ' + str(len(subtitles_dict)) + " subtitles have been found for this file: " + path)
|
||||
logging.debug('BAZARR Ended searching subtitles for this file: ' + path)
|
||||
return(subtitles_dict)
|
||||
return (subtitles_dict)
|
||||
|
||||
|
||||
def manual_download_subtitle(path, language, hi, subtitle, provider, providers_auth, sceneName, media_type):
|
||||
logging.debug('BAZARR Manually downloading subtitles for this file: ' + path)
|
||||
|
@ -325,7 +346,7 @@ def manual_download_subtitle(path, language, hi, subtitle, provider, providers_a
|
|||
lang_obj = Language(language)
|
||||
|
||||
try:
|
||||
if sceneName is None or use_scenename is False:
|
||||
if sceneName is None or not use_scenename:
|
||||
used_sceneName = False
|
||||
video = parse_video(path, None, providers={provider})
|
||||
else:
|
||||
|
@ -362,18 +383,22 @@ def manual_download_subtitle(path, language, hi, subtitle, provider, providers_a
|
|||
downloaded_language_code3 = result[0].language.alpha3
|
||||
downloaded_path = get_subtitle_path(path, language=lang_obj)
|
||||
logging.debug('BAZARR Subtitles file saved to disk: ' + downloaded_path)
|
||||
message = downloaded_language + " subtitles downloaded from " + downloaded_provider + " with a score of " + unicode(score) + "% using manual search."
|
||||
message = downloaded_language + " subtitles downloaded from " + downloaded_provider + " with a score of " + unicode(
|
||||
score) + "% using manual search."
|
||||
|
||||
if use_postprocessing is True:
|
||||
command = pp_replace(postprocessing_cmd, path, downloaded_path, downloaded_language, downloaded_language_code2, downloaded_language_code3)
|
||||
command = pp_replace(postprocessing_cmd, path, downloaded_path, downloaded_language,
|
||||
downloaded_language_code2, downloaded_language_code3)
|
||||
try:
|
||||
if os.name == 'nt':
|
||||
codepage = subprocess.Popen("chcp", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
codepage = subprocess.Popen("chcp", shell=True, stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE)
|
||||
# wait for the process to terminate
|
||||
out_codepage, err_codepage = codepage.communicate()
|
||||
encoding = out_codepage.split(':')[-1].strip()
|
||||
|
||||
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE)
|
||||
# wait for the process to terminate
|
||||
out, err = process.communicate()
|
||||
|
||||
|
@ -382,40 +407,48 @@ def manual_download_subtitle(path, language, hi, subtitle, provider, providers_a
|
|||
|
||||
except:
|
||||
if out == "":
|
||||
logging.error('BAZARR Post-processing result for file ' + path + ' : Nothing returned from command execution')
|
||||
logging.error(
|
||||
'BAZARR Post-processing result for file ' + path + ' : Nothing returned from command execution')
|
||||
else:
|
||||
logging.error('BAZARR Post-processing result for file ' + path + ' : ' + out)
|
||||
else:
|
||||
if out == "":
|
||||
logging.info('BAZARR Post-processing result for file ' + path + ' : Nothing returned from command execution')
|
||||
logging.info(
|
||||
'BAZARR Post-processing result for file ' + path + ' : Nothing returned from command execution')
|
||||
else:
|
||||
logging.info('BAZARR Post-processing result for file ' + path + ' : ' + out)
|
||||
|
||||
return message
|
||||
else:
|
||||
logging.error('BAZARR Tried to manually download a subtitles for file: ' + path + " but we weren't able to do (probably throttled by ' + str(subtitle.provider_name) + '. Please retry later or select a subtitles from another provider.")
|
||||
logging.error(
|
||||
'BAZARR Tried to manually download a subtitles for file: ' + path + " but we weren't able to do (probably throttled by ' + str(subtitle.provider_name) + '. Please retry later or select a subtitles from another provider.")
|
||||
return None
|
||||
logging.debug('BAZARR Ended manually downloading subtitles for file: ' + path)
|
||||
|
||||
|
||||
def series_download_subtitles(no):
|
||||
if get_general_settings()[24] is True:
|
||||
monitored_only_query_string = ' AND monitored = "True"'
|
||||
else:
|
||||
monitored_only_query_string = ""
|
||||
|
||||
conn_db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
||||
conn_db = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30)
|
||||
c_db = conn_db.cursor()
|
||||
episodes_details = c_db.execute('SELECT path, missing_subtitles, sonarrEpisodeId, scene_name FROM table_episodes WHERE sonarrSeriesId = ? AND missing_subtitles != "[]"' + monitored_only_query_string, (no,)).fetchall()
|
||||
episodes_details = c_db.execute(
|
||||
'SELECT path, missing_subtitles, sonarrEpisodeId, scene_name FROM table_episodes WHERE sonarrSeriesId = ? AND missing_subtitles != "[]"' + monitored_only_query_string,
|
||||
(no,)).fetchall()
|
||||
series_details = c_db.execute("SELECT hearing_impaired FROM table_shows WHERE sonarrSeriesId = ?", (no,)).fetchone()
|
||||
c_db.close()
|
||||
|
||||
|
||||
providers_list = get_providers()
|
||||
providers_auth = get_providers_auth()
|
||||
|
||||
|
||||
for episode in episodes_details:
|
||||
for language in ast.literal_eval(episode[1]):
|
||||
if language is not None:
|
||||
message = download_subtitle(path_replace(episode[0]), str(alpha3_from_alpha2(language)), series_details[0], providers_list, providers_auth, str(episode[3]), 'series')
|
||||
message = download_subtitle(path_replace(episode[0]), str(alpha3_from_alpha2(language)),
|
||||
series_details[0], providers_list, providers_auth, str(episode[3]),
|
||||
'series')
|
||||
if message is not None:
|
||||
store_subtitles(path_replace(episode[0]))
|
||||
history_log(1, no, episode[2], message)
|
||||
|
@ -424,9 +457,11 @@ def series_download_subtitles(no):
|
|||
|
||||
|
||||
def movies_download_subtitles(no):
|
||||
conn_db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
||||
conn_db = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30)
|
||||
c_db = conn_db.cursor()
|
||||
movie = c_db.execute("SELECT path, missing_subtitles, radarrId, sceneName, hearing_impaired FROM table_movies WHERE radarrId = ?", (no,)).fetchone()
|
||||
movie = c_db.execute(
|
||||
"SELECT path, missing_subtitles, radarrId, sceneName, hearing_impaired FROM table_movies WHERE radarrId = ?",
|
||||
(no,)).fetchone()
|
||||
c_db.close()
|
||||
|
||||
providers_list = get_providers()
|
||||
|
@ -434,7 +469,8 @@ def movies_download_subtitles(no):
|
|||
|
||||
for language in ast.literal_eval(movie[1]):
|
||||
if language is not None:
|
||||
message = download_subtitle(path_replace_movie(movie[0]), str(alpha3_from_alpha2(language)), movie[4], providers_list, providers_auth, str(movie[3]), 'movie')
|
||||
message = download_subtitle(path_replace_movie(movie[0]), str(alpha3_from_alpha2(language)), movie[4],
|
||||
providers_list, providers_auth, str(movie[3]), 'movie')
|
||||
if message is not None:
|
||||
store_subtitles_movie(path_replace_movie(movie[0]))
|
||||
history_log_movie(1, no, message)
|
||||
|
@ -443,14 +479,16 @@ def movies_download_subtitles(no):
|
|||
|
||||
|
||||
def wanted_download_subtitles(path):
|
||||
conn_db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
||||
conn_db = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30)
|
||||
c_db = conn_db.cursor()
|
||||
episodes_details = c_db.execute("SELECT table_episodes.path, table_episodes.missing_subtitles, table_episodes.sonarrEpisodeId, table_episodes.sonarrSeriesId, table_shows.hearing_impaired, table_episodes.scene_name, table_episodes.failedAttempts FROM table_episodes INNER JOIN table_shows on table_shows.sonarrSeriesId = table_episodes.sonarrSeriesId WHERE table_episodes.path = ? AND missing_subtitles != '[]'", (path_replace_reverse(path),)).fetchall()
|
||||
episodes_details = c_db.execute(
|
||||
"SELECT table_episodes.path, table_episodes.missing_subtitles, table_episodes.sonarrEpisodeId, table_episodes.sonarrSeriesId, table_shows.hearing_impaired, table_episodes.scene_name, table_episodes.failedAttempts FROM table_episodes INNER JOIN table_shows on table_shows.sonarrSeriesId = table_episodes.sonarrSeriesId WHERE table_episodes.path = ? AND missing_subtitles != '[]'",
|
||||
(path_replace_reverse(path),)).fetchall()
|
||||
c_db.close()
|
||||
|
||||
providers_list = get_providers()
|
||||
providers_auth = get_providers_auth()
|
||||
|
||||
|
||||
for episode in episodes_details:
|
||||
attempt = episode[6]
|
||||
if type(attempt) == unicode:
|
||||
|
@ -463,30 +501,36 @@ def wanted_download_subtitles(path):
|
|||
att = zip(*attempt)[0]
|
||||
if language not in att:
|
||||
attempt.append([language, time.time()])
|
||||
|
||||
conn_db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
||||
|
||||
conn_db = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30)
|
||||
c_db = conn_db.cursor()
|
||||
c_db.execute('UPDATE table_episodes SET failedAttempts = ? WHERE sonarrEpisodeId = ?', (unicode(attempt), episode[2]))
|
||||
c_db.execute('UPDATE table_episodes SET failedAttempts = ? WHERE sonarrEpisodeId = ?',
|
||||
(unicode(attempt), episode[2]))
|
||||
conn_db.commit()
|
||||
c_db.close()
|
||||
|
||||
|
||||
for i in range(len(attempt)):
|
||||
if attempt[i][0] == language:
|
||||
if search_active(attempt[i][1]) is True:
|
||||
message = download_subtitle(path_replace(episode[0]), str(alpha3_from_alpha2(language)), episode[4], providers_list, providers_auth, str(episode[5]), 'series')
|
||||
message = download_subtitle(path_replace(episode[0]), str(alpha3_from_alpha2(language)),
|
||||
episode[4], providers_list, providers_auth, str(episode[5]),
|
||||
'series')
|
||||
if message is not None:
|
||||
store_subtitles(path_replace(episode[0]))
|
||||
list_missing_subtitles(episode[3])
|
||||
history_log(1, episode[3], episode[2], message)
|
||||
send_notifications(episode[3], episode[2], message)
|
||||
else:
|
||||
logging.debug('BAZARR Search is not active for episode ' + episode[0] + ' Language: ' + attempt[i][0])
|
||||
logging.debug(
|
||||
'BAZARR Search is not active for episode ' + episode[0] + ' Language: ' + attempt[i][0])
|
||||
|
||||
|
||||
def wanted_download_subtitles_movie(path):
|
||||
conn_db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
||||
conn_db = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30)
|
||||
c_db = conn_db.cursor()
|
||||
movies_details = c_db.execute("SELECT path, missing_subtitles, radarrId, radarrId, hearing_impaired, sceneName, failedAttempts FROM table_movies WHERE path = ? AND missing_subtitles != '[]'", (path_replace_reverse_movie(path),)).fetchall()
|
||||
movies_details = c_db.execute(
|
||||
"SELECT path, missing_subtitles, radarrId, radarrId, hearing_impaired, sceneName, failedAttempts FROM table_movies WHERE path = ? AND missing_subtitles != '[]'",
|
||||
(path_replace_reverse_movie(path),)).fetchall()
|
||||
c_db.close()
|
||||
|
||||
providers_list = get_providers()
|
||||
|
@ -504,28 +548,30 @@ def wanted_download_subtitles_movie(path):
|
|||
att = zip(*attempt)[0]
|
||||
if language not in att:
|
||||
attempt.append([language, time.time()])
|
||||
|
||||
conn_db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
||||
|
||||
conn_db = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30)
|
||||
c_db = conn_db.cursor()
|
||||
c_db.execute('UPDATE table_movies SET failedAttempts = ? WHERE radarrId = ?', (unicode(attempt), movie[2]))
|
||||
conn_db.commit()
|
||||
c_db.close()
|
||||
|
||||
|
||||
for i in range(len(attempt)):
|
||||
if attempt[i][0] == language:
|
||||
if search_active(attempt[i][1]) is True:
|
||||
message = download_subtitle(path_replace_movie(movie[0]), str(alpha3_from_alpha2(language)), movie[4], providers_list, providers_auth, str(movie[5]), 'movie')
|
||||
message = download_subtitle(path_replace_movie(movie[0]), str(alpha3_from_alpha2(language)),
|
||||
movie[4], providers_list, providers_auth, str(movie[5]), 'movie')
|
||||
if message is not None:
|
||||
store_subtitles_movie(path_replace_movie(movie[0]))
|
||||
list_missing_subtitles_movies(movie[3])
|
||||
history_log_movie(1, movie[3], message)
|
||||
send_notifications_movie(movie[3], message)
|
||||
else:
|
||||
logging.info('BAZARR Search is not active for movie ' + movie[0] + ' Language: ' + attempt[i][0])
|
||||
logging.info(
|
||||
'BAZARR Search is not active for movie ' + movie[0] + ' Language: ' + attempt[i][0])
|
||||
|
||||
|
||||
def wanted_search_missing_subtitles():
|
||||
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)
|
||||
db.create_function("path_substitution", 1, path_replace)
|
||||
db.create_function("path_substitution_movie", 1, path_replace_movie)
|
||||
c = db.cursor()
|
||||
|
@ -535,10 +581,12 @@ def wanted_search_missing_subtitles():
|
|||
else:
|
||||
monitored_only_query_string = ""
|
||||
|
||||
c.execute("SELECT path_substitution(path) FROM table_episodes WHERE missing_subtitles != '[]'" + monitored_only_query_string)
|
||||
c.execute(
|
||||
"SELECT path_substitution(path) FROM table_episodes WHERE missing_subtitles != '[]'" + monitored_only_query_string)
|
||||
episodes = c.fetchall()
|
||||
|
||||
c.execute("SELECT path_substitution_movie(path) FROM table_movies WHERE missing_subtitles != '[]'" + monitored_only_query_string)
|
||||
c.execute(
|
||||
"SELECT path_substitution_movie(path) FROM table_movies WHERE missing_subtitles != '[]'" + monitored_only_query_string)
|
||||
movies = c.fetchall()
|
||||
|
||||
c.close()
|
||||
|
@ -554,7 +602,7 @@ def wanted_search_missing_subtitles():
|
|||
wanted_download_subtitles_movie(movie[0])
|
||||
|
||||
logging.info('BAZARR Finished searching for missing subtitles. Check histories for more information.')
|
||||
|
||||
|
||||
|
||||
def search_active(timestamp):
|
||||
if get_general_settings()[25] is True:
|
||||
|
|
|
@ -1,31 +1,36 @@
|
|||
# coding=utf-8
|
||||
|
||||
import os
|
||||
import sqlite3
|
||||
import logging
|
||||
import time
|
||||
|
||||
from cork import Cork
|
||||
from configparser import ConfigParser
|
||||
from get_argv import config_dir
|
||||
from get_args import args
|
||||
|
||||
# Check if config_dir exist
|
||||
if os.path.exists(config_dir) is False:
|
||||
# Check if args.config_dir exist
|
||||
if not os.path.exists(args.config_dir):
|
||||
# Create config_dir directory tree
|
||||
try:
|
||||
os.mkdir(os.path.join(config_dir))
|
||||
os.mkdir(os.path.join(args.config_dir))
|
||||
logging.debug("BAZARR Created data directory")
|
||||
except OSError:
|
||||
logging.exception("BAZARR The configuration directory doesn't exist and Bazarr cannot create it (permission issue?).")
|
||||
logging.exception(
|
||||
"BAZARR The configuration directory doesn't exist and Bazarr cannot create it (permission issue?).")
|
||||
exit(2)
|
||||
|
||||
if os.path.exists(os.path.join(config_dir, 'config')) is False:
|
||||
os.mkdir(os.path.join(config_dir, 'config'))
|
||||
if not os.path.exists(os.path.join(args.config_dir, 'config')):
|
||||
os.mkdir(os.path.join(args.config_dir, 'config'))
|
||||
logging.debug("BAZARR Created config folder")
|
||||
if os.path.exists(os.path.join(config_dir, 'db')) is False:
|
||||
os.mkdir(os.path.join(config_dir, 'db'))
|
||||
if not os.path.exists(os.path.join(args.config_dir, 'db')):
|
||||
os.mkdir(os.path.join(args.config_dir, 'db'))
|
||||
logging.debug("BAZARR Created db folder")
|
||||
if os.path.exists(os.path.join(config_dir, 'log')) is False:
|
||||
os.mkdir(os.path.join(config_dir, 'log'))
|
||||
if not os.path.exists(os.path.join(args.config_dir, 'log')):
|
||||
os.mkdir(os.path.join(args.config_dir, 'log'))
|
||||
logging.debug("BAZARR Created log folder")
|
||||
|
||||
config_file = os.path.normpath(os.path.join(config_dir, 'config/config.ini'))
|
||||
config_file = os.path.normpath(os.path.join(args.config_dir, 'config', 'config.ini'))
|
||||
|
||||
cfg = ConfigParser()
|
||||
try:
|
||||
|
@ -37,7 +42,7 @@ try:
|
|||
fd.close()
|
||||
|
||||
# Open database connection
|
||||
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()
|
||||
|
||||
# Execute script and commit change to database
|
||||
|
@ -59,18 +64,16 @@ except Exception:
|
|||
if cfg.has_section('auth'):
|
||||
if cfg.has_option('auth', 'enabled'):
|
||||
enabled = cfg.getboolean('auth', 'enabled')
|
||||
if enabled is True:
|
||||
if enabled:
|
||||
cfg.set('auth', 'type', 'basic')
|
||||
elif enabled is False:
|
||||
else:
|
||||
cfg.set('auth', 'type', 'None')
|
||||
cfg.remove_option('auth', 'enabled')
|
||||
with open(config_file, 'w+') as configfile:
|
||||
cfg.write(configfile)
|
||||
|
||||
from cork import Cork
|
||||
import time
|
||||
if os.path.exists(os.path.normpath(os.path.join(config_dir, 'config/users.json'))) is False:
|
||||
cork = Cork(os.path.normpath(os.path.join(config_dir, 'config')), initialize=True)
|
||||
if not os.path.exists(os.path.normpath(os.path.join(args.config_dir, 'config', 'users.json'))):
|
||||
cork = Cork(os.path.normpath(os.path.join(args.config_dir, 'config')), initialize=True)
|
||||
|
||||
cork._store.roles[''] = 100
|
||||
cork._store.save_roles()
|
||||
|
|
11
bazarr/libs.py
Normal file
11
bazarr/libs.py
Normal file
|
@ -0,0 +1,11 @@
|
|||
# coding=utf-8
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
||||
|
||||
def set_libs():
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '../libs/'))
|
||||
|
||||
|
||||
set_libs()
|
|
@ -1,24 +1,27 @@
|
|||
from get_argv import config_dir
|
||||
# coding=utf-8
|
||||
|
||||
import gc
|
||||
import os
|
||||
import enzyme
|
||||
import babelfish
|
||||
import logging
|
||||
import subliminal
|
||||
import subliminal_patch
|
||||
from subliminal import core
|
||||
import sqlite3
|
||||
import ast
|
||||
import langdetect
|
||||
import subliminal
|
||||
import subliminal_patch
|
||||
from subliminal import core
|
||||
from bs4 import UnicodeDammit
|
||||
from itertools import islice
|
||||
|
||||
from get_settings import path_replace_reverse, path_replace, path_replace_reverse_movie, path_replace_movie, get_general_settings
|
||||
from get_args import args
|
||||
from get_settings import path_replace_reverse, path_replace, path_replace_reverse_movie, path_replace_movie, \
|
||||
get_general_settings
|
||||
from get_languages import alpha2_from_alpha3
|
||||
|
||||
gc.enable()
|
||||
|
||||
|
||||
def store_subtitles(file):
|
||||
# languages = []
|
||||
actual_subtitles = []
|
||||
|
@ -27,17 +30,16 @@ def store_subtitles(file):
|
|||
try:
|
||||
with open(file, 'rb') as f:
|
||||
mkv = enzyme.MKV(f)
|
||||
|
||||
|
||||
for subtitle_track in mkv.subtitle_tracks:
|
||||
try:
|
||||
if alpha2_from_alpha3(subtitle_track.language) != None:
|
||||
actual_subtitles.append([str(alpha2_from_alpha3(subtitle_track.language)),None])
|
||||
actual_subtitles.append([str(alpha2_from_alpha3(subtitle_track.language)), None])
|
||||
except:
|
||||
pass
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
brazilian_portuguese = [".pt-br", ".pob", "pb"]
|
||||
try:
|
||||
subtitles = core.search_external_subtitles(file)
|
||||
|
@ -46,9 +48,11 @@ def store_subtitles(file):
|
|||
else:
|
||||
for subtitle, language in subtitles.iteritems():
|
||||
if str(os.path.splitext(subtitle)[0]).lower().endswith(tuple(brazilian_portuguese)) is True:
|
||||
actual_subtitles.append([str("pb"), path_replace_reverse(os.path.join(os.path.dirname(file), subtitle))])
|
||||
actual_subtitles.append(
|
||||
[str("pb"), path_replace_reverse(os.path.join(os.path.dirname(file), subtitle))])
|
||||
elif str(language) != 'und':
|
||||
actual_subtitles.append([str(language), path_replace_reverse(os.path.join(os.path.dirname(file), subtitle))])
|
||||
actual_subtitles.append(
|
||||
[str(language), path_replace_reverse(os.path.join(os.path.dirname(file), subtitle))])
|
||||
else:
|
||||
with open(path_replace(os.path.join(os.path.dirname(file), subtitle)), 'r') as f:
|
||||
text = list(islice(f, 100))
|
||||
|
@ -57,16 +61,21 @@ def store_subtitles(file):
|
|||
try:
|
||||
text = text.decode(encoding.original_encoding)
|
||||
except Exception as e:
|
||||
logging.exception('BAZARR Error trying to detect character encoding for this subtitles file: ' + path_replace(os.path.join(os.path.dirname(file), subtitle)) + ' You should try to delete this subtitles file manually and ask Bazarr to download it again.')
|
||||
logging.exception(
|
||||
'BAZARR Error trying to detect character encoding for this subtitles file: ' + path_replace(
|
||||
os.path.join(os.path.dirname(file),
|
||||
subtitle)) + ' You should try to delete this subtitles file manually and ask Bazarr to download it again.')
|
||||
else:
|
||||
detected_language = langdetect.detect(text)
|
||||
if len(detected_language) > 0:
|
||||
actual_subtitles.append([str(detected_language), path_replace_reverse(os.path.join(os.path.dirname(file), subtitle))])
|
||||
actual_subtitles.append([str(detected_language), path_replace_reverse(
|
||||
os.path.join(os.path.dirname(file), subtitle))])
|
||||
|
||||
conn_db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
||||
conn_db = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30)
|
||||
c_db = conn_db.cursor()
|
||||
|
||||
c_db.execute("UPDATE table_episodes SET subtitles = ? WHERE path = ?", (str(actual_subtitles), path_replace_reverse(file)))
|
||||
c_db.execute("UPDATE table_episodes SET subtitles = ? WHERE path = ?",
|
||||
(str(actual_subtitles), path_replace_reverse(file)))
|
||||
conn_db.commit()
|
||||
|
||||
c_db.close()
|
||||
|
@ -97,9 +106,11 @@ def store_subtitles_movie(file):
|
|||
|
||||
for subtitle, language in subtitles.iteritems():
|
||||
if str(os.path.splitext(subtitle)[0]).lower().endswith(tuple(brazilian_portuguese)) is True:
|
||||
actual_subtitles.append([str("pb"), path_replace_reverse_movie(os.path.join(os.path.dirname(file), subtitle))])
|
||||
actual_subtitles.append(
|
||||
[str("pb"), path_replace_reverse_movie(os.path.join(os.path.dirname(file), subtitle))])
|
||||
elif str(language) != 'und':
|
||||
actual_subtitles.append([str(language), path_replace_reverse_movie(os.path.join(os.path.dirname(file), subtitle))])
|
||||
actual_subtitles.append(
|
||||
[str(language), path_replace_reverse_movie(os.path.join(os.path.dirname(file), subtitle))])
|
||||
else:
|
||||
if os.path.splitext(subtitle)[1] != ".sub":
|
||||
with open(path_replace_movie(os.path.join(os.path.dirname(file), subtitle)), 'r') as f:
|
||||
|
@ -109,16 +120,21 @@ def store_subtitles_movie(file):
|
|||
try:
|
||||
text = text.decode(encoding.original_encoding)
|
||||
except Exception as e:
|
||||
logging.exception('BAZARR Error trying to detect character encoding for this subtitles file: ' + path_replace_movie(os.path.join(os.path.dirname(file), subtitle)) + ' You should try to delete this subtitles file manually and ask Bazarr to download it again.')
|
||||
logging.exception(
|
||||
'BAZARR Error trying to detect character encoding for this subtitles file: ' + path_replace_movie(
|
||||
os.path.join(os.path.dirname(file),
|
||||
subtitle)) + ' You should try to delete this subtitles file manually and ask Bazarr to download it again.')
|
||||
else:
|
||||
detected_language = langdetect.detect(text)
|
||||
if len(detected_language) > 0:
|
||||
actual_subtitles.append([str(detected_language), path_replace_reverse_movie(os.path.join(os.path.dirname(file), subtitle))])
|
||||
actual_subtitles.append([str(detected_language), path_replace_reverse_movie(
|
||||
os.path.join(os.path.dirname(file), subtitle))])
|
||||
|
||||
conn_db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
||||
conn_db = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30)
|
||||
c_db = conn_db.cursor()
|
||||
|
||||
c_db.execute("UPDATE table_movies SET subtitles = ? WHERE path = ?", (str(actual_subtitles), path_replace_reverse_movie(file)))
|
||||
c_db.execute("UPDATE table_movies SET subtitles = ? WHERE path = ?",
|
||||
(str(actual_subtitles), path_replace_reverse_movie(file)))
|
||||
conn_db.commit()
|
||||
|
||||
c_db.close()
|
||||
|
@ -132,9 +148,10 @@ def list_missing_subtitles(*no):
|
|||
query_string = " WHERE table_shows.sonarrSeriesId = " + str(no[0])
|
||||
except:
|
||||
pass
|
||||
conn_db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
||||
conn_db = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30)
|
||||
c_db = conn_db.cursor()
|
||||
episodes_subtitles = c_db.execute("SELECT table_episodes.sonarrEpisodeId, table_episodes.subtitles, table_shows.languages FROM table_episodes INNER JOIN table_shows on table_episodes.sonarrSeriesId = table_shows.sonarrSeriesId" + query_string).fetchall()
|
||||
episodes_subtitles = c_db.execute(
|
||||
"SELECT table_episodes.sonarrEpisodeId, table_episodes.subtitles, table_shows.languages FROM table_episodes INNER JOIN table_shows on table_episodes.sonarrSeriesId = table_shows.sonarrSeriesId" + query_string).fetchall()
|
||||
c_db.close()
|
||||
|
||||
missing_subtitles_global = []
|
||||
|
@ -165,10 +182,11 @@ def list_missing_subtitles(*no):
|
|||
actual_subtitles_list.append(item[0])
|
||||
missing_subtitles = list(set(desired_subtitles) - set(actual_subtitles_list))
|
||||
missing_subtitles_global.append(tuple([str(missing_subtitles), episode_subtitles[0]]))
|
||||
|
||||
conn_db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
||||
|
||||
conn_db = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30)
|
||||
c_db = conn_db.cursor()
|
||||
c_db.executemany("UPDATE table_episodes SET missing_subtitles = ? WHERE sonarrEpisodeId = ?", (missing_subtitles_global))
|
||||
c_db.executemany("UPDATE table_episodes SET missing_subtitles = ? WHERE sonarrEpisodeId = ?",
|
||||
(missing_subtitles_global))
|
||||
conn_db.commit()
|
||||
c_db.close()
|
||||
|
||||
|
@ -179,7 +197,7 @@ def list_missing_subtitles_movies(*no):
|
|||
query_string = " WHERE table_movies.radarrId = " + str(no[0])
|
||||
except:
|
||||
pass
|
||||
conn_db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
||||
conn_db = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30)
|
||||
c_db = conn_db.cursor()
|
||||
movies_subtitles = c_db.execute("SELECT radarrId, subtitles, languages FROM table_movies" + query_string).fetchall()
|
||||
c_db.close()
|
||||
|
@ -213,14 +231,15 @@ def list_missing_subtitles_movies(*no):
|
|||
missing_subtitles = list(set(desired_subtitles) - set(actual_subtitles_list))
|
||||
missing_subtitles_global.append(tuple([str(missing_subtitles), movie_subtitles[0]]))
|
||||
|
||||
conn_db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
||||
conn_db = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30)
|
||||
c_db = conn_db.cursor()
|
||||
c_db.executemany("UPDATE table_movies SET missing_subtitles = ? WHERE radarrId = ?", (missing_subtitles_global))
|
||||
conn_db.commit()
|
||||
c_db.close()
|
||||
|
||||
|
||||
def series_full_scan_subtitles():
|
||||
conn_db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
||||
conn_db = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30)
|
||||
c_db = conn_db.cursor()
|
||||
episodes = c_db.execute("SELECT path FROM table_episodes").fetchall()
|
||||
c_db.close()
|
||||
|
@ -230,8 +249,9 @@ def series_full_scan_subtitles():
|
|||
|
||||
gc.collect()
|
||||
|
||||
|
||||
def movies_full_scan_subtitles():
|
||||
conn_db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
||||
conn_db = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30)
|
||||
c_db = conn_db.cursor()
|
||||
movies = c_db.execute("SELECT path FROM table_movies").fetchall()
|
||||
c_db.close()
|
||||
|
@ -241,12 +261,13 @@ def movies_full_scan_subtitles():
|
|||
|
||||
gc.collect()
|
||||
|
||||
|
||||
def series_scan_subtitles(no):
|
||||
conn_db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
||||
conn_db = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30)
|
||||
c_db = conn_db.cursor()
|
||||
episodes = c_db.execute("SELECT path FROM table_episodes WHERE sonarrSeriesId = ?", (no,)).fetchall()
|
||||
c_db.close()
|
||||
|
||||
|
||||
for episode in episodes:
|
||||
store_subtitles(path_replace(episode[0]))
|
||||
|
||||
|
@ -254,7 +275,7 @@ def series_scan_subtitles(no):
|
|||
|
||||
|
||||
def movies_scan_subtitles(no):
|
||||
conn_db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
||||
conn_db = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30)
|
||||
c_db = conn_db.cursor()
|
||||
movies = c_db.execute("SELECT path FROM table_movies WHERE radarrId = ?", (no,)).fetchall()
|
||||
c_db.close()
|
||||
|
|
407
bazarr/main.py
407
bazarr/main.py
File diff suppressed because it is too large
Load diff
|
@ -1,22 +1,24 @@
|
|||
from get_argv import config_dir
|
||||
# coding=utf-8
|
||||
|
||||
import apprise
|
||||
import os
|
||||
import sqlite3
|
||||
import logging
|
||||
|
||||
from get_args import args
|
||||
|
||||
|
||||
def update_notifier():
|
||||
# define apprise object
|
||||
a = apprise.Apprise()
|
||||
|
||||
|
||||
# Retrieve all of the details
|
||||
results = a.details()
|
||||
|
||||
|
||||
notifiers_new = []
|
||||
notifiers_old = []
|
||||
|
||||
conn_db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
||||
|
||||
conn_db = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30)
|
||||
c_db = conn_db.cursor()
|
||||
notifiers_current = c_db.execute('SELECT name FROM table_settings_notifier').fetchall()
|
||||
for x in results['schemas']:
|
||||
|
@ -26,51 +28,56 @@ def update_notifier():
|
|||
else:
|
||||
notifiers_old.append(x['service_name'])
|
||||
notifier_current = [i[0] for i in notifiers_current]
|
||||
|
||||
|
||||
notifiers_to_delete = list(set(notifier_current) - set(notifiers_old))
|
||||
|
||||
|
||||
for notifier_new in notifiers_new:
|
||||
c_db.execute('INSERT INTO `table_settings_notifier` (name, enabled) VALUES (?, ?);', (notifier_new, '0'))
|
||||
|
||||
|
||||
for notifier_to_delete in notifiers_to_delete:
|
||||
c_db.execute('DELETE FROM `table_settings_notifier` WHERE name=?', (notifier_to_delete,))
|
||||
|
||||
|
||||
conn_db.commit()
|
||||
c_db.close()
|
||||
|
||||
|
||||
def get_notifier_providers():
|
||||
conn_db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
||||
conn_db = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30)
|
||||
c_db = conn_db.cursor()
|
||||
providers = c_db.execute('SELECT name, url FROM table_settings_notifier WHERE enabled = 1').fetchall()
|
||||
c_db.close()
|
||||
|
||||
return providers
|
||||
|
||||
|
||||
def get_series_name(sonarrSeriesId):
|
||||
conn_db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
||||
conn_db = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30)
|
||||
c_db = conn_db.cursor()
|
||||
data = c_db.execute('SELECT title FROM table_shows WHERE sonarrSeriesId = ?', (sonarrSeriesId,)).fetchone()
|
||||
c_db.close()
|
||||
|
||||
return data[0]
|
||||
|
||||
|
||||
def get_episode_name(sonarrEpisodeId):
|
||||
conn_db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
||||
conn_db = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30)
|
||||
c_db = conn_db.cursor()
|
||||
data = c_db.execute('SELECT title, season, episode FROM table_episodes WHERE sonarrEpisodeId = ?', (sonarrEpisodeId,)).fetchone()
|
||||
data = c_db.execute('SELECT title, season, episode FROM table_episodes WHERE sonarrEpisodeId = ?',
|
||||
(sonarrEpisodeId,)).fetchone()
|
||||
c_db.close()
|
||||
|
||||
return data[0], data[1], data[2]
|
||||
|
||||
|
||||
def get_movies_name(radarrId):
|
||||
conn_db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
||||
conn_db = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30)
|
||||
c_db = conn_db.cursor()
|
||||
data = c_db.execute('SELECT title FROM table_movies WHERE radarrId = ?', (radarrId,)).fetchone()
|
||||
c_db.close()
|
||||
|
||||
return data[0]
|
||||
|
||||
|
||||
def send_notifications(sonarrSeriesId, sonarrEpisodeId, message):
|
||||
providers = get_notifier_providers()
|
||||
series = get_series_name(sonarrSeriesId)
|
||||
|
@ -84,7 +91,8 @@ def send_notifications(sonarrSeriesId, sonarrEpisodeId, message):
|
|||
|
||||
apobj.notify(
|
||||
title='Bazarr notification',
|
||||
body=(series + ' - S' + str(episode[1]).zfill(2) + 'E' + str(episode[2]).zfill(2) + ' - ' + episode[0] + ' : ' + message),
|
||||
body=(series + ' - S' + str(episode[1]).zfill(2) + 'E' + str(episode[2]).zfill(2) + ' - ' + episode[
|
||||
0] + ' : ' + message),
|
||||
)
|
||||
|
||||
|
||||
|
@ -101,4 +109,4 @@ def send_notifications_movie(radarrId, message):
|
|||
apobj.notify(
|
||||
title='Bazarr notification',
|
||||
body=movie + ' : ' + message,
|
||||
)
|
||||
)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from get_argv import no_update
|
||||
# coding=utf-8
|
||||
|
||||
from get_settings import get_general_settings, automatic, get_radarr_settings, get_sonarr_settings
|
||||
from get_series import update_series
|
||||
|
@ -6,7 +6,9 @@ from get_episodes import update_all_episodes, update_all_movies, sync_episodes
|
|||
from get_movies import update_movies
|
||||
from list_subtitles import store_subtitles
|
||||
from get_subtitle import wanted_search_missing_subtitles
|
||||
if no_update is False:
|
||||
from get_args import args
|
||||
|
||||
if not args.no_update:
|
||||
from check_update import check_and_apply_update
|
||||
|
||||
from apscheduler.schedulers.background import BackgroundScheduler
|
||||
|
@ -24,32 +26,37 @@ def sonarr_full_update():
|
|||
full_update = get_sonarr_settings()[5]
|
||||
if full_update == "Daily":
|
||||
scheduler.add_job(update_all_episodes, CronTrigger(hour=4), max_instances=1, coalesce=True,
|
||||
misfire_grace_time=15, id='update_all_episodes',
|
||||
name='Update all episodes subtitles from disk', replace_existing=True)
|
||||
misfire_grace_time=15, id='update_all_episodes',
|
||||
name='Update all episodes subtitles from disk', replace_existing=True)
|
||||
elif full_update == "Weekly":
|
||||
scheduler.add_job(update_all_episodes, CronTrigger(day_of_week='sun'), hour=4, max_instances=1, coalesce=True,
|
||||
misfire_grace_time=15, id='update_all_episodes',
|
||||
name='Update all episodes subtitles from disk', replace_existing=True)
|
||||
scheduler.add_job(update_all_episodes, CronTrigger(day_of_week='sun'), hour=4, max_instances=1,
|
||||
coalesce=True,
|
||||
misfire_grace_time=15, id='update_all_episodes',
|
||||
name='Update all episodes subtitles from disk', replace_existing=True)
|
||||
elif full_update == "Manually":
|
||||
scheduler.add_job(update_all_episodes, CronTrigger(year='2100'), hour=4, max_instances=1, coalesce=True,
|
||||
misfire_grace_time=15, id='update_all_episodes',
|
||||
name='Update all episodes subtitles from disk', replace_existing=True)
|
||||
misfire_grace_time=15, id='update_all_episodes',
|
||||
name='Update all episodes subtitles from disk', replace_existing=True)
|
||||
|
||||
|
||||
def radarr_full_update():
|
||||
if integration[13] is True:
|
||||
full_update = get_radarr_settings()[5]
|
||||
if full_update == "Daily":
|
||||
scheduler.add_job(update_all_movies, CronTrigger(hour=5), max_instances=1, coalesce=True, misfire_grace_time=15,
|
||||
id='update_all_movies', name='Update all movies subtitles from disk', replace_existing=True)
|
||||
scheduler.add_job(update_all_movies, CronTrigger(hour=5), max_instances=1, coalesce=True,
|
||||
misfire_grace_time=15,
|
||||
id='update_all_movies', name='Update all movies subtitles from disk',
|
||||
replace_existing=True)
|
||||
elif full_update == "Weekly":
|
||||
scheduler.add_job(update_all_movies, CronTrigger(day_of_week='sun'), hour=5, max_instances=1, coalesce=True,
|
||||
misfire_grace_time=15, id='update_all_movies', name='Update all movies subtitles from disk',
|
||||
replace_existing=True)
|
||||
misfire_grace_time=15, id='update_all_movies',
|
||||
name='Update all movies subtitles from disk',
|
||||
replace_existing=True)
|
||||
elif full_update == "Manually":
|
||||
scheduler.add_job(update_all_movies, CronTrigger(year='2100'), hour=5, max_instances=1, coalesce=True,
|
||||
misfire_grace_time=15, id='update_all_movies', name='Update all movies subtitles from disk',
|
||||
replace_existing=True)
|
||||
misfire_grace_time=15, id='update_all_movies',
|
||||
name='Update all movies subtitles from disk',
|
||||
replace_existing=True)
|
||||
|
||||
|
||||
def execute_now(taskid):
|
||||
|
@ -61,25 +68,32 @@ if str(get_localzone()) == "local":
|
|||
else:
|
||||
scheduler = BackgroundScheduler()
|
||||
|
||||
if no_update is False:
|
||||
if not args.no_update:
|
||||
if automatic is True:
|
||||
scheduler.add_job(check_and_apply_update, IntervalTrigger(hours=6), max_instances=1, coalesce=True, misfire_grace_time=15, id='update_bazarr', name='Update bazarr from source on Github')
|
||||
scheduler.add_job(check_and_apply_update, IntervalTrigger(hours=6), max_instances=1, coalesce=True,
|
||||
misfire_grace_time=15, id='update_bazarr', name='Update bazarr from source on Github')
|
||||
else:
|
||||
scheduler.add_job(check_and_apply_update, CronTrigger(year='2100'), hour=4, id='update_bazarr', name='Update bazarr from source on Github')
|
||||
scheduler.add_job(check_and_apply_update, CronTrigger(year='2100'), hour=4, id='update_bazarr',
|
||||
name='Update bazarr from source on Github')
|
||||
|
||||
if integration[12] is True:
|
||||
scheduler.add_job(update_series, IntervalTrigger(minutes=1), max_instances=1, coalesce=True, misfire_grace_time=15, id='update_series', name='Update series list from Sonarr')
|
||||
scheduler.add_job(sync_episodes, IntervalTrigger(minutes=5), max_instances=1, coalesce=True, misfire_grace_time=15, id='sync_episodes', name='Sync episodes with Sonarr')
|
||||
scheduler.add_job(update_series, IntervalTrigger(minutes=1), max_instances=1, coalesce=True, misfire_grace_time=15,
|
||||
id='update_series', name='Update series list from Sonarr')
|
||||
scheduler.add_job(sync_episodes, IntervalTrigger(minutes=5), max_instances=1, coalesce=True, misfire_grace_time=15,
|
||||
id='sync_episodes', name='Sync episodes with Sonarr')
|
||||
|
||||
if integration[13] is True:
|
||||
scheduler.add_job(update_movies, IntervalTrigger(minutes=5), max_instances=1, coalesce=True, misfire_grace_time=15, id='update_movies', name='Update movies list from Radarr')
|
||||
scheduler.add_job(update_movies, IntervalTrigger(minutes=5), max_instances=1, coalesce=True, misfire_grace_time=15,
|
||||
id='update_movies', name='Update movies list from Radarr')
|
||||
|
||||
if integration[12] is True or integration[13] is True:
|
||||
scheduler.add_job(wanted_search_missing_subtitles, IntervalTrigger(hours=3), max_instances=1, coalesce=True, misfire_grace_time=15, id='wanted_search_missing_subtitles', name='Search for wanted subtitles')
|
||||
scheduler.add_job(wanted_search_missing_subtitles, IntervalTrigger(hours=3), max_instances=1, coalesce=True,
|
||||
misfire_grace_time=15, id='wanted_search_missing_subtitles', name='Search for wanted subtitles')
|
||||
|
||||
sonarr_full_update()
|
||||
radarr_full_update()
|
||||
scheduler.start()
|
||||
|
||||
|
||||
def shutdown_scheduler():
|
||||
scheduler.shutdown(wait=True)
|
||||
scheduler.shutdown(wait=True)
|
||||
|
|
|
@ -1,14 +1,16 @@
|
|||
from get_argv import config_dir
|
||||
# coding=utf-8
|
||||
|
||||
import os
|
||||
import sqlite3
|
||||
|
||||
from get_args import args
|
||||
|
||||
# Check if database exist
|
||||
if os.path.exists(os.path.join(config_dir, 'db/bazarr.db')) == True:
|
||||
if os.path.exists(os.path.join(args.config_dir, 'db', 'bazarr.db')):
|
||||
# Open database connection
|
||||
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()
|
||||
|
||||
|
||||
# Execute tables modifications
|
||||
try:
|
||||
c.execute('alter table table_settings_providers add column "username" "text"')
|
||||
|
@ -55,7 +57,6 @@ if os.path.exists(os.path.join(config_dir, 'db/bazarr.db')) == True:
|
|||
except:
|
||||
pass
|
||||
|
||||
|
||||
# Commit change to db
|
||||
db.commit()
|
||||
|
||||
|
@ -100,4 +101,4 @@ if os.path.exists(os.path.join(config_dir, 'db/bazarr.db')) == True:
|
|||
if integration[13] is True:
|
||||
execute_now('update_movies')
|
||||
|
||||
db.close()
|
||||
db.close()
|
||||
|
|
|
@ -1,30 +1,37 @@
|
|||
from get_argv import config_dir
|
||||
# coding=utf-8
|
||||
|
||||
import os
|
||||
import sqlite3
|
||||
import time
|
||||
|
||||
from get_args import args
|
||||
|
||||
|
||||
def history_log(action, sonarrSeriesId, sonarrEpisodeId, description):
|
||||
# Open database connection
|
||||
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()
|
||||
|
||||
# Get Sonarr API URL from database config table
|
||||
history = c.execute('''INSERT INTO table_history(action, sonarrSeriesId, sonarrEpisodeId, timestamp, description) VALUES (?, ?, ?, ?, ?)''', (action, sonarrSeriesId, sonarrEpisodeId, time.time(), description))
|
||||
history = c.execute(
|
||||
'''INSERT INTO table_history(action, sonarrSeriesId, sonarrEpisodeId, timestamp, description) VALUES (?, ?, ?, ?, ?)''',
|
||||
(action, sonarrSeriesId, sonarrEpisodeId, time.time(), description))
|
||||
|
||||
# Commit changes to DB
|
||||
db.commit()
|
||||
|
||||
|
||||
# Close database connection
|
||||
db.close()
|
||||
|
||||
|
||||
def history_log_movie(action, radarrId, description):
|
||||
# Open database connection
|
||||
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()
|
||||
|
||||
history = c.execute('''INSERT INTO table_history_movie(action, radarrId, timestamp, description) VALUES (?, ?, ?, ?)''', (action, radarrId, time.time(), description))
|
||||
history = c.execute(
|
||||
'''INSERT INTO table_history_movie(action, radarrId, timestamp, description) VALUES (?, ?, ?, ?)''',
|
||||
(action, radarrId, time.time(), description))
|
||||
|
||||
# Commit changes to DB
|
||||
db.commit()
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
% monitored_only_query_string = ""
|
||||
%end
|
||||
|
||||
% conn = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
||||
% conn = sqlite3.connect(os.path.join(config_dir, 'db', 'bazarr.db'), timeout=30)
|
||||
% c = conn.cursor()
|
||||
% wanted_series = c.execute("SELECT COUNT(*) FROM table_episodes WHERE missing_subtitles != '[]'" + monitored_only_query_string).fetchone()
|
||||
% wanted_movies = c.execute("SELECT COUNT(*) FROM table_movies WHERE missing_subtitles != '[]'" + monitored_only_query_string).fetchone()
|
||||
|
|
|
@ -56,7 +56,7 @@
|
|||
% monitored_only_query_string = ""
|
||||
%end
|
||||
|
||||
% conn = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
||||
% conn = sqlite3.connect(os.path.join(config_dir, 'db', 'bazarr.db'), timeout=30)
|
||||
% c = conn.cursor()
|
||||
% wanted_series = c.execute("SELECT COUNT(*) FROM table_episodes WHERE missing_subtitles != '[]'" + monitored_only_query_string).fetchone()
|
||||
% wanted_movies = c.execute("SELECT COUNT(*) FROM table_movies WHERE missing_subtitles != '[]'" + monitored_only_query_string).fetchone()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue