parent
53b52d364e
commit
1137090735
@ -0,0 +1 @@
|
|||||||
|
from bazarr import *
|
@ -1,106 +1,106 @@
|
|||||||
from get_argv import config_dir
|
from get_argv import config_dir
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import requests
|
import requests
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from get_settings import path_replace
|
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():
|
def update_all_episodes():
|
||||||
series_full_scan_subtitles()
|
series_full_scan_subtitles()
|
||||||
logging.info('All existing episode subtitles indexed from disk.')
|
logging.info('All existing episode subtitles indexed from disk.')
|
||||||
list_missing_subtitles()
|
list_missing_subtitles()
|
||||||
logging.info('All missing episode subtitles updated in database.')
|
logging.info('All missing episode subtitles updated in database.')
|
||||||
|
|
||||||
def update_all_movies():
|
def update_all_movies():
|
||||||
movies_full_scan_subtitles()
|
movies_full_scan_subtitles()
|
||||||
logging.info('All existing movie subtitles indexed from disk.')
|
logging.info('All existing movie subtitles indexed from disk.')
|
||||||
list_missing_subtitles()
|
list_missing_subtitles()
|
||||||
logging.info('All missing movie subtitles updated in database.')
|
logging.info('All missing movie subtitles updated in database.')
|
||||||
|
|
||||||
def sync_episodes():
|
def sync_episodes():
|
||||||
logging.debug('Starting episode sync from Sonarr.')
|
logging.debug('Starting episode sync from Sonarr.')
|
||||||
from get_settings import get_sonarr_settings
|
from get_settings import get_sonarr_settings
|
||||||
url_sonarr = get_sonarr_settings()[6]
|
url_sonarr = get_sonarr_settings()[6]
|
||||||
apikey_sonarr = get_sonarr_settings()[4]
|
apikey_sonarr = get_sonarr_settings()[4]
|
||||||
|
|
||||||
# Open database connection
|
# Open database connection
|
||||||
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
||||||
c = db.cursor()
|
c = db.cursor()
|
||||||
|
|
||||||
# Get current episodes id in DB
|
# Get current episodes id in DB
|
||||||
current_episodes_db = c.execute('SELECT sonarrEpisodeId FROM table_episodes').fetchall()
|
current_episodes_db = c.execute('SELECT sonarrEpisodeId FROM table_episodes').fetchall()
|
||||||
|
|
||||||
current_episodes_db_list = [x[0] for x in current_episodes_db]
|
current_episodes_db_list = [x[0] for x in current_episodes_db]
|
||||||
current_episodes_sonarr = []
|
current_episodes_sonarr = []
|
||||||
episodes_to_update = []
|
episodes_to_update = []
|
||||||
episodes_to_add = []
|
episodes_to_add = []
|
||||||
|
|
||||||
# Get sonarrId for each series from database
|
# Get sonarrId for each series from database
|
||||||
seriesIdList = c.execute("SELECT sonarrSeriesId FROM table_shows").fetchall()
|
seriesIdList = c.execute("SELECT sonarrSeriesId FROM table_shows").fetchall()
|
||||||
|
|
||||||
# Close database connection
|
# Close database connection
|
||||||
c.close()
|
c.close()
|
||||||
|
|
||||||
for seriesId in seriesIdList:
|
for seriesId in seriesIdList:
|
||||||
# Get episodes data for a series from Sonarr
|
# Get episodes data for a series from Sonarr
|
||||||
url_sonarr_api_episode = url_sonarr + "/api/episode?seriesId=" + str(seriesId[0]) + "&apikey=" + apikey_sonarr
|
url_sonarr_api_episode = url_sonarr + "/api/episode?seriesId=" + str(seriesId[0]) + "&apikey=" + apikey_sonarr
|
||||||
try:
|
try:
|
||||||
r = requests.get(url_sonarr_api_episode, timeout=15, verify=False)
|
r = requests.get(url_sonarr_api_episode, timeout=15, verify=False)
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
except requests.exceptions.HTTPError as errh:
|
except requests.exceptions.HTTPError as errh:
|
||||||
logging.exception("Error trying to get episodes from Sonarr. Http error.")
|
logging.exception("Error trying to get episodes from Sonarr. Http error.")
|
||||||
except requests.exceptions.ConnectionError as errc:
|
except requests.exceptions.ConnectionError as errc:
|
||||||
logging.exception("Error trying to get episodes from Sonarr. Connection Error.")
|
logging.exception("Error trying to get episodes from Sonarr. Connection Error.")
|
||||||
except requests.exceptions.Timeout as errt:
|
except requests.exceptions.Timeout as errt:
|
||||||
logging.exception("Error trying to get episodes from Sonarr. Timeout Error.")
|
logging.exception("Error trying to get episodes from Sonarr. Timeout Error.")
|
||||||
except requests.exceptions.RequestException as err:
|
except requests.exceptions.RequestException as err:
|
||||||
logging.exception("Error trying to get episodes from Sonarr.")
|
logging.exception("Error trying to get episodes from Sonarr.")
|
||||||
else:
|
else:
|
||||||
for episode in r.json():
|
for episode in r.json():
|
||||||
if 'hasFile' in episode:
|
if 'hasFile' in episode:
|
||||||
if episode['hasFile'] is True:
|
if episode['hasFile'] is True:
|
||||||
if 'episodeFile' in episode:
|
if 'episodeFile' in episode:
|
||||||
if episode['episodeFile']['size'] > 20480:
|
if episode['episodeFile']['size'] > 20480:
|
||||||
# Add shows in Sonarr to current shows list
|
# Add shows in Sonarr to current shows list
|
||||||
if 'sceneName' in episode['episodeFile']:
|
if 'sceneName' in episode['episodeFile']:
|
||||||
sceneName = episode['episodeFile']['sceneName']
|
sceneName = episode['episodeFile']['sceneName']
|
||||||
else:
|
else:
|
||||||
sceneName = None
|
sceneName = None
|
||||||
|
|
||||||
# Add episodes in sonarr to current episode list
|
# Add episodes in sonarr to current episode list
|
||||||
current_episodes_sonarr.append(episode['id'])
|
current_episodes_sonarr.append(episode['id'])
|
||||||
|
|
||||||
if episode['id'] in current_episodes_db_list:
|
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:
|
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))
|
removed_episodes = list(set(current_episodes_db_list) - set(current_episodes_sonarr))
|
||||||
|
|
||||||
# Update or insert movies in DB
|
# 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(config_dir, 'db/bazarr.db'), timeout=30)
|
||||||
c = db.cursor()
|
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()
|
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()
|
db.commit()
|
||||||
|
|
||||||
for removed_episode in removed_episodes:
|
for removed_episode in removed_episodes:
|
||||||
c.execute('DELETE FROM table_episodes WHERE sonarrEpisodeId = ?', (removed_episode,))
|
c.execute('DELETE FROM table_episodes WHERE sonarrEpisodeId = ?', (removed_episode,))
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
# Close database connection
|
# Close database connection
|
||||||
c.close()
|
c.close()
|
||||||
|
|
||||||
for added_episode in episodes_to_add:
|
for added_episode in episodes_to_add:
|
||||||
store_subtitles(path_replace(added_episode[3]))
|
store_subtitles(path_replace(added_episode[3]))
|
||||||
|
|
||||||
logging.debug('All episodes synced from Sonarr into database.')
|
logging.debug('All episodes synced from Sonarr into database.')
|
||||||
|
|
||||||
list_missing_subtitles()
|
list_missing_subtitles()
|
||||||
logging.debug('All missing subtitles updated in database.')
|
logging.debug('All missing subtitles updated in database.')
|
@ -1,92 +1,92 @@
|
|||||||
from get_argv import config_dir
|
from get_argv import config_dir
|
||||||
|
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import pycountry
|
import pycountry
|
||||||
import os
|
import os
|
||||||
|
|
||||||
def load_language_in_db():
|
def load_language_in_db():
|
||||||
# Get languages list in langs tuple
|
# Get languages list in langs tuple
|
||||||
langs = [[lang.alpha_3,lang.alpha_2,lang.name]
|
langs = [[lang.alpha_3,lang.alpha_2,lang.name]
|
||||||
for lang in pycountry.languages
|
for lang in pycountry.languages
|
||||||
if hasattr(lang, 'alpha_2')]
|
if hasattr(lang, 'alpha_2')]
|
||||||
|
|
||||||
# Open database connection
|
# Open database connection
|
||||||
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
||||||
c = db.cursor()
|
c = db.cursor()
|
||||||
|
|
||||||
# Insert languages in database table
|
# Insert languages in database table
|
||||||
c.executemany('''INSERT OR IGNORE INTO table_settings_languages(code3, code2, name) VALUES(?, ?, ?)''', langs)
|
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'))
|
||||||
|
|
||||||
# Commit changes to database table
|
# Commit changes to database table
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
# Close database connection
|
# Close database connection
|
||||||
db.close()
|
db.close()
|
||||||
|
|
||||||
def language_from_alpha2(lang):
|
def language_from_alpha2(lang):
|
||||||
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
||||||
c = db.cursor()
|
c = db.cursor()
|
||||||
try:
|
try:
|
||||||
result = c.execute('''SELECT name FROM table_settings_languages WHERE code2 = ?''', (lang,)).fetchone()[0]
|
result = c.execute('''SELECT name FROM table_settings_languages WHERE code2 = ?''', (lang,)).fetchone()[0]
|
||||||
except:
|
except:
|
||||||
result = None
|
result = None
|
||||||
db.close
|
db.close
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def language_from_alpha3(lang):
|
def language_from_alpha3(lang):
|
||||||
if lang == 'fre':
|
if lang == 'fre':
|
||||||
lang = 'fra'
|
lang = 'fra'
|
||||||
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
||||||
c = db.cursor()
|
c = db.cursor()
|
||||||
try:
|
try:
|
||||||
result = c.execute('''SELECT name FROM table_settings_languages WHERE code3 = ?''', (lang,)).fetchone()[0]
|
result = c.execute('''SELECT name FROM table_settings_languages WHERE code3 = ?''', (lang,)).fetchone()[0]
|
||||||
except:
|
except:
|
||||||
result = None
|
result = None
|
||||||
db.close
|
db.close
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def alpha2_from_alpha3(lang):
|
def alpha2_from_alpha3(lang):
|
||||||
if lang == 'fre':
|
if lang == 'fre':
|
||||||
lang = 'fra'
|
lang = 'fra'
|
||||||
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
||||||
c = db.cursor()
|
c = db.cursor()
|
||||||
try:
|
try:
|
||||||
result = c.execute('''SELECT code2 FROM table_settings_languages WHERE code3 = ?''', (lang,)).fetchone()[0]
|
result = c.execute('''SELECT code2 FROM table_settings_languages WHERE code3 = ?''', (lang,)).fetchone()[0]
|
||||||
except:
|
except:
|
||||||
result = None
|
result = None
|
||||||
db.close
|
db.close
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def alpha2_from_language(lang):
|
def alpha2_from_language(lang):
|
||||||
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
||||||
c = db.cursor()
|
c = db.cursor()
|
||||||
try:
|
try:
|
||||||
result = c.execute('''SELECT code2 FROM table_settings_languages WHERE name = ?''', (lang,)).fetchone()[0]
|
result = c.execute('''SELECT code2 FROM table_settings_languages WHERE name = ?''', (lang,)).fetchone()[0]
|
||||||
except:
|
except:
|
||||||
result = None
|
result = None
|
||||||
db.close
|
db.close
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def alpha3_from_alpha2(lang):
|
def alpha3_from_alpha2(lang):
|
||||||
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
||||||
c = db.cursor()
|
c = db.cursor()
|
||||||
try:
|
try:
|
||||||
result = c.execute('''SELECT code3 FROM table_settings_languages WHERE code2 = ?''', (lang,)).fetchone()[0]
|
result = c.execute('''SELECT code3 FROM table_settings_languages WHERE code2 = ?''', (lang,)).fetchone()[0]
|
||||||
except:
|
except:
|
||||||
result = None
|
result = None
|
||||||
db.close
|
db.close
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def alpha3_from_language(lang):
|
def alpha3_from_language(lang):
|
||||||
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
||||||
c = db.cursor()
|
c = db.cursor()
|
||||||
try:
|
try:
|
||||||
result = c.execute('''SELECT code3 FROM table_settings_languages WHERE name = ?''', (lang,)).fetchone()[0]
|
result = c.execute('''SELECT code3 FROM table_settings_languages WHERE name = ?''', (lang,)).fetchone()[0]
|
||||||
except:
|
except:
|
||||||
result = None
|
result = None
|
||||||
db.close
|
db.close
|
||||||
return result
|
return result
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
load_language_in_db()
|
load_language_in_db()
|
@ -1,161 +1,161 @@
|
|||||||
from get_argv import config_dir
|
from get_argv import config_dir
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import requests
|
import requests
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from get_settings import get_general_settings
|
from get_settings import get_general_settings
|
||||||
from list_subtitles import list_missing_subtitles
|
from list_subtitles import list_missing_subtitles
|
||||||
|
|
||||||
def update_series():
|
def update_series():
|
||||||
from get_settings import get_sonarr_settings
|
from get_settings import get_sonarr_settings
|
||||||
url_sonarr = get_sonarr_settings()[6]
|
url_sonarr = get_sonarr_settings()[6]
|
||||||
apikey_sonarr = get_sonarr_settings()[4]
|
apikey_sonarr = get_sonarr_settings()[4]
|
||||||
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]
|
||||||
serie_default_hi = get_general_settings()[17]
|
serie_default_hi = get_general_settings()[17]
|
||||||
|
|
||||||
if apikey_sonarr == None:
|
if apikey_sonarr == None:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
get_profile_list()
|
get_profile_list()
|
||||||
|
|
||||||
# Get shows data from Sonarr
|
# Get shows data from Sonarr
|
||||||
url_sonarr_api_series = url_sonarr + "/api/series?apikey=" + apikey_sonarr
|
url_sonarr_api_series = url_sonarr + "/api/series?apikey=" + apikey_sonarr
|
||||||
try:
|
try:
|
||||||
r = requests.get(url_sonarr_api_series, timeout=15, verify=False)
|
r = requests.get(url_sonarr_api_series, timeout=15, verify=False)
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
except requests.exceptions.HTTPError as errh:
|
except requests.exceptions.HTTPError as errh:
|
||||||
logging.exception("Error trying to get series from Sonarr. Http error.")
|
logging.exception("Error trying to get series from Sonarr. Http error.")
|
||||||
except requests.exceptions.ConnectionError as errc:
|
except requests.exceptions.ConnectionError as errc:
|
||||||
logging.exception("Error trying to get series from Sonarr. Connection Error.")
|
logging.exception("Error trying to get series from Sonarr. Connection Error.")
|
||||||
except requests.exceptions.Timeout as errt:
|
except requests.exceptions.Timeout as errt:
|
||||||
logging.exception("Error trying to get series from Sonarr. Timeout Error.")
|
logging.exception("Error trying to get series from Sonarr. Timeout Error.")
|
||||||
except requests.exceptions.RequestException as err:
|
except requests.exceptions.RequestException as err:
|
||||||
logging.exception("Error trying to get series from Sonarr.")
|
logging.exception("Error trying to get series from Sonarr.")
|
||||||
else:
|
else:
|
||||||
# Open database connection
|
# Open database connection
|
||||||
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
||||||
c = db.cursor()
|
c = db.cursor()
|
||||||
|
|
||||||
# Get current shows in DB
|
# Get current shows in DB
|
||||||
current_shows_db = c.execute('SELECT tvdbId FROM table_shows').fetchall()
|
current_shows_db = c.execute('SELECT tvdbId FROM table_shows').fetchall()
|
||||||
|
|
||||||
# Close database connection
|
# Close database connection
|
||||||
db.close()
|
db.close()
|
||||||
|
|
||||||
current_shows_db_list = [x[0] for x in current_shows_db]
|
current_shows_db_list = [x[0] for x in current_shows_db]
|
||||||
current_shows_sonarr = []
|
current_shows_sonarr = []
|
||||||
series_to_update = []
|
series_to_update = []
|
||||||
series_to_add = []
|
series_to_add = []
|
||||||
|
|
||||||
for show in r.json():
|
for show in r.json():
|
||||||
try:
|
try:
|
||||||
overview = unicode(show['overview'])
|
overview = unicode(show['overview'])
|
||||||
except:
|
except:
|
||||||
overview = ""
|
overview = ""
|
||||||
try:
|
try:
|
||||||
poster_big = show['images'][2]['url'].split('?')[0]
|
poster_big = show['images'][2]['url'].split('?')[0]
|
||||||
poster = os.path.splitext(poster_big)[0] + '-250' + os.path.splitext(poster_big)[1]
|
poster = os.path.splitext(poster_big)[0] + '-250' + os.path.splitext(poster_big)[1]
|
||||||
except:
|
except:
|
||||||
poster = ""
|
poster = ""
|
||||||
try:
|
try:
|
||||||
fanart = show['images'][0]['url'].split('?')[0]
|
fanart = show['images'][0]['url'].split('?')[0]
|
||||||
except:
|
except:
|
||||||
fanart = ""
|
fanart = ""
|
||||||
|
|
||||||
# Add shows in Sonarr to current shows list
|
# Add shows in Sonarr to current shows list
|
||||||
current_shows_sonarr.append(show['tvdbId'])
|
current_shows_sonarr.append(show['tvdbId'])
|
||||||
|
|
||||||
if show['tvdbId'] in current_shows_db_list:
|
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:
|
else:
|
||||||
if serie_default_enabled is True:
|
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:
|
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
|
# 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(config_dir, 'db/bazarr.db'), timeout=30)
|
||||||
c = db.cursor()
|
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()
|
db.commit()
|
||||||
|
|
||||||
if serie_default_enabled is True:
|
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()
|
db.commit()
|
||||||
else:
|
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.commit()
|
||||||
db.close()
|
db.close()
|
||||||
|
|
||||||
for show in series_to_add:
|
for show in series_to_add:
|
||||||
list_missing_subtitles(show[5])
|
list_missing_subtitles(show[5])
|
||||||
|
|
||||||
# Delete shows not in Sonarr anymore
|
# Delete shows not in Sonarr anymore
|
||||||
deleted_items = []
|
deleted_items = []
|
||||||
for item in current_shows_db_list:
|
for item in current_shows_db_list:
|
||||||
if item not in current_shows_sonarr:
|
if item not in current_shows_sonarr:
|
||||||
deleted_items.append(tuple([item]))
|
deleted_items.append(tuple([item]))
|
||||||
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
||||||
c = db.cursor()
|
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.commit()
|
||||||
db.close()
|
db.close()
|
||||||
|
|
||||||
def get_profile_list():
|
def get_profile_list():
|
||||||
from get_settings import get_sonarr_settings
|
from get_settings import get_sonarr_settings
|
||||||
url_sonarr = get_sonarr_settings()[6]
|
url_sonarr = get_sonarr_settings()[6]
|
||||||
# url_sonarr_short = get_sonarr_settings()[5]
|
# url_sonarr_short = get_sonarr_settings()[5]
|
||||||
apikey_sonarr = get_sonarr_settings()[4]
|
apikey_sonarr = get_sonarr_settings()[4]
|
||||||
|
|
||||||
# Get profiles data from Sonarr
|
# Get profiles data from Sonarr
|
||||||
error = False
|
error = False
|
||||||
|
|
||||||
url_sonarr_api_series = url_sonarr + "/api/profile?apikey=" + apikey_sonarr
|
url_sonarr_api_series = url_sonarr + "/api/profile?apikey=" + apikey_sonarr
|
||||||
try:
|
try:
|
||||||
profiles_json = requests.get(url_sonarr_api_series, timeout=15, verify=False)
|
profiles_json = requests.get(url_sonarr_api_series, timeout=15, verify=False)
|
||||||
except requests.exceptions.ConnectionError as errc:
|
except requests.exceptions.ConnectionError as errc:
|
||||||
error = True
|
error = True
|
||||||
logging.exception("Error trying to get profiles from Sonarr. Connection Error.")
|
logging.exception("Error trying to get profiles from Sonarr. Connection Error.")
|
||||||
except requests.exceptions.Timeout as errt:
|
except requests.exceptions.Timeout as errt:
|
||||||
error = True
|
error = True
|
||||||
logging.exception("Error trying to get profiles from Sonarr. Timeout Error.")
|
logging.exception("Error trying to get profiles from Sonarr. Timeout Error.")
|
||||||
except requests.exceptions.RequestException as err:
|
except requests.exceptions.RequestException as err:
|
||||||
error = True
|
error = True
|
||||||
logging.exception("Error trying to get profiles from Sonarr.")
|
logging.exception("Error trying to get profiles from Sonarr.")
|
||||||
|
|
||||||
url_sonarr_api_series_v3 = url_sonarr + "/api/v3/languageprofile?apikey=" + apikey_sonarr
|
url_sonarr_api_series_v3 = url_sonarr + "/api/v3/languageprofile?apikey=" + apikey_sonarr
|
||||||
try:
|
try:
|
||||||
profiles_json_v3 = requests.get(url_sonarr_api_series_v3, timeout=15, verify=False)
|
profiles_json_v3 = requests.get(url_sonarr_api_series_v3, timeout=15, verify=False)
|
||||||
except requests.exceptions.ConnectionError as errc:
|
except requests.exceptions.ConnectionError as errc:
|
||||||
error = True
|
error = True
|
||||||
logging.exception("Error trying to get profiles from Sonarr. Connection Error.")
|
logging.exception("Error trying to get profiles from Sonarr. Connection Error.")
|
||||||
except requests.exceptions.Timeout as errt:
|
except requests.exceptions.Timeout as errt:
|
||||||
error = True
|
error = True
|
||||||
logging.exception("Error trying to get profiles from Sonarr. Timeout Error.")
|
logging.exception("Error trying to get profiles from Sonarr. Timeout Error.")
|
||||||
except requests.exceptions.RequestException as err:
|
except requests.exceptions.RequestException as err:
|
||||||
error = True
|
error = True
|
||||||
logging.exception("Error trying to get profiles from Sonarr.")
|
logging.exception("Error trying to get profiles from Sonarr.")
|
||||||
|
|
||||||
global profiles_list
|
global profiles_list
|
||||||
profiles_list = []
|
profiles_list = []
|
||||||
|
|
||||||
if error is False:
|
if error is False:
|
||||||
# Parsing data returned from Sonarr
|
# Parsing data returned from Sonarr
|
||||||
global sonarr_version
|
global sonarr_version
|
||||||
if type(profiles_json_v3.json()) != list:
|
if type(profiles_json_v3.json()) != list:
|
||||||
sonarr_version = 2
|
sonarr_version = 2
|
||||||
for profile in profiles_json.json():
|
for profile in profiles_json.json():
|
||||||
profiles_list.append([profile['id'], profile['language'].capitalize()])
|
profiles_list.append([profile['id'], profile['language'].capitalize()])
|
||||||
else:
|
else:
|
||||||
sonarr_version = 3
|
sonarr_version = 3
|
||||||
for profile in profiles_json_v3.json():
|
for profile in profiles_json_v3.json():
|
||||||
profiles_list.append([profile['id'], profile['name'].capitalize()])
|
profiles_list.append([profile['id'], profile['name'].capitalize()])
|
||||||
|
|
||||||
def profile_id_to_language(id):
|
def profile_id_to_language(id):
|
||||||
for profile in profiles_list:
|
for profile in profiles_list:
|
||||||
if id == profile[0]:
|
if id == profile[0]:
|
||||||
return profile[1]
|
return profile[1]
|
@ -1,263 +1,263 @@
|
|||||||
from get_argv import config_dir
|
from get_argv import config_dir
|
||||||
|
|
||||||
import gc
|
import gc
|
||||||
import os
|
import os
|
||||||
import enzyme
|
import enzyme
|
||||||
import babelfish
|
import babelfish
|
||||||
import logging
|
import logging
|
||||||
from subliminal import core
|
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_settings import path_replace_reverse, path_replace, path_replace_reverse_movie, path_replace_movie, get_general_settings
|
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
|
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':
|
||||||
try:
|
try:
|
||||||
with open(file, 'rb') as f:
|
with open(file, 'rb') as f:
|
||||||
mkv = enzyme.MKV(f)
|
mkv = enzyme.MKV(f)
|
||||||
|
|
||||||
for subtitle_track in mkv.subtitle_tracks:
|
for subtitle_track in mkv.subtitle_tracks:
|
||||||
try:
|
try:
|
||||||
if alpha2_from_alpha3(subtitle_track.language) != None:
|
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:
|
except:
|
||||||
pass
|
pass
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
brazilian_portuguese = [".pt-br", ".pob", "pb"]
|
brazilian_portuguese = [".pt-br", ".pob", "pb"]
|
||||||
try:
|
try:
|
||||||
subtitles = core.search_external_subtitles(file)
|
subtitles = core.search_external_subtitles(file)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
for subtitle, language in subtitles.iteritems():
|
for subtitle, language in subtitles.iteritems():
|
||||||
if str(os.path.splitext(subtitle)[0]).lower().endswith(tuple(brazilian_portuguese)) is True:
|
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':
|
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:
|
else:
|
||||||
with open(path_replace(os.path.join(os.path.dirname(file), subtitle)), 'r') as f:
|
with open(path_replace(os.path.join(os.path.dirname(file), subtitle)), 'r') as f:
|
||||||
text = list(islice(f, 100))
|
text = list(islice(f, 100))
|
||||||
text = ' '.join(text)
|
text = ' '.join(text)
|
||||||
encoding = UnicodeDammit(text)
|
encoding = UnicodeDammit(text)
|
||||||
try:
|
try:
|
||||||
text = text.decode(encoding.original_encoding)
|
text = text.decode(encoding.original_encoding)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.exception('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('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:
|
else:
|
||||||
detected_language = langdetect.detect(text)
|
detected_language = langdetect.detect(text)
|
||||||
if len(detected_language) > 0:
|
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(config_dir, 'db/bazarr.db'), timeout=30)
|
||||||
c_db = conn_db.cursor()
|
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()
|
conn_db.commit()
|
||||||
|
|
||||||
c_db.close()
|
c_db.close()
|
||||||
|
|
||||||
return actual_subtitles
|
return actual_subtitles
|
||||||
|
|
||||||
|
|
||||||
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':
|
||||||
try:
|
try:
|
||||||
with open(file, 'rb') as f:
|
with open(file, 'rb') as f:
|
||||||
mkv = enzyme.MKV(f)
|
mkv = enzyme.MKV(f)
|
||||||
|
|
||||||
for subtitle_track in mkv.subtitle_tracks:
|
for subtitle_track in mkv.subtitle_tracks:
|
||||||
try:
|
try:
|
||||||
if alpha2_from_alpha3(subtitle_track.language) != None:
|
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:
|
except:
|
||||||
pass
|
pass
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
subtitles = core.search_external_subtitles(file)
|
subtitles = core.search_external_subtitles(file)
|
||||||
brazilian_portuguese = [".pt-br", ".pob", "pb"]
|
brazilian_portuguese = [".pt-br", ".pob", "pb"]
|
||||||
|
|
||||||
for subtitle, language in subtitles.iteritems():
|
for subtitle, language in subtitles.iteritems():
|
||||||
if str(os.path.splitext(subtitle)[0]).lower().endswith(tuple(brazilian_portuguese)) is True:
|
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':
|
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:
|
else:
|
||||||
if os.path.splitext(subtitle)[1] != ".sub":
|
if os.path.splitext(subtitle)[1] != ".sub":
|
||||||
with open(path_replace_movie(os.path.join(os.path.dirname(file), subtitle)), 'r') as f:
|
with open(path_replace_movie(os.path.join(os.path.dirname(file), subtitle)), 'r') as f:
|
||||||
text = list(islice(f, 100))
|
text = list(islice(f, 100))
|
||||||
text = ' '.join(text)
|
text = ' '.join(text)
|
||||||
encoding = UnicodeDammit(text)
|
encoding = UnicodeDammit(text)
|
||||||
try:
|
try:
|
||||||
text = text.decode(encoding.original_encoding)
|
text = text.decode(encoding.original_encoding)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.exception('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('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:
|
else:
|
||||||
detected_language = langdetect.detect(text)
|
detected_language = langdetect.detect(text)
|
||||||
if len(detected_language) > 0:
|
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(config_dir, 'db/bazarr.db'), timeout=30)
|
||||||
c_db = conn_db.cursor()
|
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()
|
conn_db.commit()
|
||||||
|
|
||||||
c_db.close()
|
c_db.close()
|
||||||
|
|
||||||
return actual_subtitles
|
return actual_subtitles
|
||||||
|
|
||||||
|
|
||||||
def list_missing_subtitles(*no):
|
def list_missing_subtitles(*no):
|
||||||
query_string = ''
|
query_string = ''
|
||||||
try:
|
try:
|
||||||
query_string = " WHERE table_shows.sonarrSeriesId = " + str(no[0])
|
query_string = " WHERE table_shows.sonarrSeriesId = " + str(no[0])
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
conn_db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
conn_db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
||||||
c_db = conn_db.cursor()
|
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()
|
c_db.close()
|
||||||
|
|
||||||
missing_subtitles_global = []
|
missing_subtitles_global = []
|
||||||
use_embedded_subs = get_general_settings()[23]
|
use_embedded_subs = get_general_settings()[23]
|
||||||
for episode_subtitles in episodes_subtitles:
|
for episode_subtitles in episodes_subtitles:
|
||||||
actual_subtitles_temp = []
|
actual_subtitles_temp = []
|
||||||
actual_subtitles = []
|
actual_subtitles = []
|
||||||
desired_subtitles = []
|
desired_subtitles = []
|
||||||
missing_subtitles = []
|
missing_subtitles = []
|
||||||
if episode_subtitles[1] != None:
|
if episode_subtitles[1] != None:
|
||||||
if use_embedded_subs is True:
|
if use_embedded_subs is True:
|
||||||
actual_subtitles = ast.literal_eval(episode_subtitles[1])
|
actual_subtitles = ast.literal_eval(episode_subtitles[1])
|
||||||
else:
|
else:
|
||||||
actual_subtitles_temp = ast.literal_eval(episode_subtitles[1])
|
actual_subtitles_temp = ast.literal_eval(episode_subtitles[1])
|
||||||
for subtitle in actual_subtitles_temp:
|
for subtitle in actual_subtitles_temp:
|
||||||
if subtitle[1] != None:
|
if subtitle[1] != None:
|
||||||
actual_subtitles.append(subtitle)
|
actual_subtitles.append(subtitle)
|
||||||
if episode_subtitles[2] != None:
|
if episode_subtitles[2] != None:
|
||||||
desired_subtitles = ast.literal_eval(episode_subtitles[2])
|
desired_subtitles = ast.literal_eval(episode_subtitles[2])
|
||||||
actual_subtitles_list = []
|
actual_subtitles_list = []
|
||||||
if desired_subtitles == None:
|
if desired_subtitles == None:
|
||||||
missing_subtitles_global.append(tuple(['[]', episode_subtitles[0]]))
|
missing_subtitles_global.append(tuple(['[]', episode_subtitles[0]]))
|
||||||
else:
|
else:
|
||||||
for item in actual_subtitles:
|
for item in actual_subtitles:
|
||||||
if item[0] == "pt-BR":
|
if item[0] == "pt-BR":
|
||||||
actual_subtitles_list.append("pb")
|
actual_subtitles_list.append("pb")
|
||||||
else:
|
else:
|
||||||
actual_subtitles_list.append(item[0])
|
actual_subtitles_list.append(item[0])
|
||||||
missing_subtitles = list(set(desired_subtitles) - set(actual_subtitles_list))
|
missing_subtitles = list(set(desired_subtitles) - set(actual_subtitles_list))
|
||||||
missing_subtitles_global.append(tuple([str(missing_subtitles), episode_subtitles[0]]))
|
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(config_dir, 'db/bazarr.db'), timeout=30)
|
||||||
c_db = conn_db.cursor()
|
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()
|
conn_db.commit()
|
||||||
c_db.close()
|
c_db.close()
|
||||||
|
|
||||||
|
|
||||||
def list_missing_subtitles_movies(*no):
|
def list_missing_subtitles_movies(*no):
|
||||||
query_string = ''
|
query_string = ''
|
||||||
try:
|
try:
|
||||||
query_string = " WHERE table_movies.radarrId = " + str(no[0])
|
query_string = " WHERE table_movies.radarrId = " + str(no[0])
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
conn_db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
conn_db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
||||||
c_db = conn_db.cursor()
|
c_db = conn_db.cursor()
|
||||||
movies_subtitles = c_db.execute("SELECT radarrId, subtitles, languages FROM table_movies" + query_string).fetchall()
|
movies_subtitles = c_db.execute("SELECT radarrId, subtitles, languages FROM table_movies" + query_string).fetchall()
|
||||||
c_db.close()
|
c_db.close()
|
||||||
|
|
||||||
missing_subtitles_global = []
|
missing_subtitles_global = []
|
||||||
use_embedded_subs = get_general_settings()[23]
|
use_embedded_subs = get_general_settings()[23]
|
||||||
for movie_subtitles in movies_subtitles:
|
for movie_subtitles in movies_subtitles:
|
||||||
actual_subtitles_temp = []
|
actual_subtitles_temp = []
|
||||||
actual_subtitles = []
|
actual_subtitles = []
|
||||||
desired_subtitles = []
|
desired_subtitles = []
|
||||||
missing_subtitles = []
|
missing_subtitles = []
|
||||||
if movie_subtitles[1] != None:
|
if movie_subtitles[1] != None:
|
||||||
if use_embedded_subs is True:
|
if use_embedded_subs is True:
|
||||||
actual_subtitles = ast.literal_eval(movie_subtitles[1])
|
actual_subtitles = ast.literal_eval(movie_subtitles[1])
|
||||||
else:
|
else:
|
||||||
actual_subtitles_temp = ast.literal_eval(movie_subtitles[1])
|
actual_subtitles_temp = ast.literal_eval(movie_subtitles[1])
|
||||||
for subtitle in actual_subtitles_temp:
|
for subtitle in actual_subtitles_temp:
|
||||||
if subtitle[1] != None:
|
if subtitle[1] != None:
|
||||||
actual_subtitles.append(subtitle)
|
actual_subtitles.append(subtitle)
|
||||||
if movie_subtitles[2] != None:
|
if movie_subtitles[2] != None:
|
||||||
desired_subtitles = ast.literal_eval(movie_subtitles[2])
|
desired_subtitles = ast.literal_eval(movie_subtitles[2])
|
||||||
actual_subtitles_list = []
|
actual_subtitles_list = []
|
||||||
if desired_subtitles == None:
|
if desired_subtitles == None:
|
||||||
missing_subtitles_global.append(tuple(['[]', movie_subtitles[0]]))
|
missing_subtitles_global.append(tuple(['[]', movie_subtitles[0]]))
|
||||||
else:
|
else:
|
||||||
for item in actual_subtitles:
|
for item in actual_subtitles:
|
||||||
if item[0] == "pt-BR":
|
if item[0] == "pt-BR":
|
||||||
actual_subtitles_list.append("pb")
|
actual_subtitles_list.append("pb")
|
||||||
else:
|
else:
|
||||||
actual_subtitles_list.append(item[0])
|
actual_subtitles_list.append(item[0])
|
||||||
missing_subtitles = list(set(desired_subtitles) - set(actual_subtitles_list))
|
missing_subtitles = list(set(desired_subtitles) - set(actual_subtitles_list))
|
||||||
missing_subtitles_global.append(tuple([str(missing_subtitles), movie_subtitles[0]]))
|
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(config_dir, 'db/bazarr.db'), timeout=30)
|
||||||
c_db = conn_db.cursor()
|
c_db = conn_db.cursor()
|
||||||
c_db.executemany("UPDATE table_movies SET missing_subtitles = ? WHERE radarrId = ?", (missing_subtitles_global))
|
c_db.executemany("UPDATE table_movies SET missing_subtitles = ? WHERE radarrId = ?", (missing_subtitles_global))
|
||||||
conn_db.commit()
|
conn_db.commit()
|
||||||
c_db.close()
|
c_db.close()
|
||||||
|
|
||||||
def series_full_scan_subtitles():
|
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(config_dir, 'db/bazarr.db'), timeout=30)
|
||||||
c_db = conn_db.cursor()
|
c_db = conn_db.cursor()
|
||||||
episodes = c_db.execute("SELECT path FROM table_episodes").fetchall()
|
episodes = c_db.execute("SELECT path FROM table_episodes").fetchall()
|
||||||
c_db.close()
|
c_db.close()
|
||||||
|
|
||||||
for episode in episodes:
|
for episode in episodes:
|
||||||
store_subtitles(path_replace(episode[0]))
|
store_subtitles(path_replace(episode[0]))
|
||||||
|
|
||||||
gc.collect()
|
gc.collect()
|
||||||
|
|
||||||
def movies_full_scan_subtitles():
|
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(config_dir, 'db/bazarr.db'), timeout=30)
|
||||||
c_db = conn_db.cursor()
|
c_db = conn_db.cursor()
|
||||||
movies = c_db.execute("SELECT path FROM table_movies").fetchall()
|
movies = c_db.execute("SELECT path FROM table_movies").fetchall()
|
||||||
c_db.close()
|
c_db.close()
|
||||||
|
|
||||||
for movie in movies:
|
for movie in movies:
|
||||||
store_subtitles_movie(path_replace_movie(movie[0]))
|
store_subtitles_movie(path_replace_movie(movie[0]))
|
||||||
|
|
||||||
gc.collect()
|
gc.collect()
|
||||||
|
|
||||||
def series_scan_subtitles(no):
|
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(config_dir, 'db/bazarr.db'), timeout=30)
|
||||||
c_db = conn_db.cursor()
|
c_db = conn_db.cursor()
|
||||||
episodes = c_db.execute("SELECT path FROM table_episodes WHERE sonarrSeriesId = ?", (no,)).fetchall()
|
episodes = c_db.execute("SELECT path FROM table_episodes WHERE sonarrSeriesId = ?", (no,)).fetchall()
|
||||||
c_db.close()
|
c_db.close()
|
||||||
|
|
||||||
for episode in episodes:
|
for episode in episodes:
|
||||||
store_subtitles(path_replace(episode[0]))
|
store_subtitles(path_replace(episode[0]))
|
||||||
|
|
||||||
list_missing_subtitles(no)
|
list_missing_subtitles(no)
|
||||||
|
|
||||||
|
|
||||||
def movies_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(config_dir, 'db/bazarr.db'), timeout=30)
|
||||||
c_db = conn_db.cursor()
|
c_db = conn_db.cursor()
|
||||||
movies = c_db.execute("SELECT path FROM table_movies WHERE radarrId = ?", (no,)).fetchall()
|
movies = c_db.execute("SELECT path FROM table_movies WHERE radarrId = ?", (no,)).fetchall()
|
||||||
c_db.close()
|
c_db.close()
|
||||||
|
|
||||||
for movie in movies:
|
for movie in movies:
|
||||||
store_subtitles_movie(path_replace_movie(movie[0]))
|
store_subtitles_movie(path_replace_movie(movie[0]))
|
||||||
|
|
||||||
list_missing_subtitles_movies(no)
|
list_missing_subtitles_movies(no)
|
@ -1,33 +1,33 @@
|
|||||||
from get_argv import config_dir
|
from get_argv import config_dir
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import time
|
import time
|
||||||
|
|
||||||
def history_log(action, sonarrSeriesId, sonarrEpisodeId, description):
|
def history_log(action, sonarrSeriesId, sonarrEpisodeId, description):
|
||||||
# Open database connection
|
# Open database connection
|
||||||
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
||||||
c = db.cursor()
|
c = db.cursor()
|
||||||
|
|
||||||
# Get Sonarr API URL from database config table
|
# 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
|
# Commit changes to DB
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
# Close database connection
|
# Close database connection
|
||||||
db.close()
|
db.close()
|
||||||
|
|
||||||
|
|
||||||
def history_log_movie(action, radarrId, description):
|
def history_log_movie(action, radarrId, description):
|
||||||
# Open database connection
|
# Open database connection
|
||||||
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
||||||
c = db.cursor()
|
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
|
# Commit changes to DB
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
# Close database connection
|
# Close database connection
|
||||||
db.close()
|
db.close()
|
Loading…
Reference in new issue