|
|
@ -1,6 +1,7 @@
|
|
|
|
import os
|
|
|
|
import os
|
|
|
|
import sqlite3
|
|
|
|
import sqlite3
|
|
|
|
import requests
|
|
|
|
import requests
|
|
|
|
|
|
|
|
import logging
|
|
|
|
|
|
|
|
|
|
|
|
from get_general_settings import *
|
|
|
|
from get_general_settings import *
|
|
|
|
from list_subtitles import *
|
|
|
|
from list_subtitles import *
|
|
|
@ -25,50 +26,60 @@ def update_series():
|
|
|
|
|
|
|
|
|
|
|
|
# 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
|
|
|
|
r = requests.get(url_sonarr_api_series)
|
|
|
|
try:
|
|
|
|
|
|
|
|
r = requests.get(url_sonarr_api_series, timeout=15)
|
|
|
|
# Get current shows in DB
|
|
|
|
r.raise_for_status()
|
|
|
|
current_shows_db = c.execute('SELECT tvdbId FROM table_shows').fetchall()
|
|
|
|
except requests.exceptions.HTTPError as errh:
|
|
|
|
current_shows_db_list = [x[0] for x in current_shows_db]
|
|
|
|
logging.exception("Error trying to get series from Sonarr. Http error.")
|
|
|
|
current_shows_sonarr = []
|
|
|
|
except requests.exceptions.ConnectionError as errc:
|
|
|
|
|
|
|
|
logging.exception("Error trying to get series from Sonarr. Connection Error.")
|
|
|
|
for show in r.json():
|
|
|
|
except requests.exceptions.Timeout as errt:
|
|
|
|
try:
|
|
|
|
logging.exception("Error trying to get series from Sonarr. Timeout Error.")
|
|
|
|
overview = unicode(show['overview'])
|
|
|
|
except requests.exceptions.RequestException as err:
|
|
|
|
except:
|
|
|
|
logging.exception("Error trying to get series from Sonarr.")
|
|
|
|
overview = ""
|
|
|
|
else:
|
|
|
|
try:
|
|
|
|
# Get current shows in DB
|
|
|
|
poster_big = show['images'][2]['url'].split('?')[0]
|
|
|
|
current_shows_db = c.execute('SELECT tvdbId FROM table_shows').fetchall()
|
|
|
|
poster = os.path.splitext(poster_big)[0] + '-250' + os.path.splitext(poster_big)[1]
|
|
|
|
current_shows_db_list = [x[0] for x in current_shows_db]
|
|
|
|
except:
|
|
|
|
current_shows_sonarr = []
|
|
|
|
poster = ""
|
|
|
|
|
|
|
|
try:
|
|
|
|
for show in r.json():
|
|
|
|
fanart = show['images'][0]['url'].split('?')[0]
|
|
|
|
try:
|
|
|
|
except:
|
|
|
|
overview = unicode(show['overview'])
|
|
|
|
fanart = ""
|
|
|
|
except:
|
|
|
|
|
|
|
|
overview = ""
|
|
|
|
# Add shows in Sonarr to current shows list
|
|
|
|
try:
|
|
|
|
current_shows_sonarr.append(show['tvdbId'])
|
|
|
|
poster_big = show['images'][2]['url'].split('?')[0]
|
|
|
|
|
|
|
|
poster = os.path.splitext(poster_big)[0] + '-250' + os.path.splitext(poster_big)[1]
|
|
|
|
# Update or insert shows list in database table
|
|
|
|
except:
|
|
|
|
try:
|
|
|
|
poster = ""
|
|
|
|
if serie_default_enabled == 'True':
|
|
|
|
try:
|
|
|
|
c.execute('''INSERT INTO table_shows(title, path, tvdbId, languages,`hearing_impaired`, sonarrSeriesId, overview, poster, fanart, `audio_language`, sortTitle) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)''', (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']))
|
|
|
|
fanart = show['images'][0]['url'].split('?')[0]
|
|
|
|
list_missing_subtitles(show["id"])
|
|
|
|
except:
|
|
|
|
else:
|
|
|
|
fanart = ""
|
|
|
|
c.execute('''INSERT 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 = ?), ?, ?, ?, ?, ?, ?)''', (show["title"], show["path"], show["tvdbId"], show["tvdbId"], show["tvdbId"], show["id"], overview, poster, fanart, profile_id_to_language(show['qualityProfileId']), show['sortTitle']))
|
|
|
|
|
|
|
|
except:
|
|
|
|
# Add shows in Sonarr to current shows list
|
|
|
|
c.execute('''UPDATE table_shows SET title = ?, path = ?, tvdbId = ?, sonarrSeriesId = ?, overview = ?, poster = ?, fanart = ?, `audio_language` = ? , sortTitle = ? WHERE tvdbid = ?''', (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"]))
|
|
|
|
current_shows_sonarr.append(show['tvdbId'])
|
|
|
|
|
|
|
|
|
|
|
|
# Delete shows not in Sonarr anymore
|
|
|
|
# Update or insert shows list in database table
|
|
|
|
deleted_items = []
|
|
|
|
try:
|
|
|
|
for item in current_shows_db_list:
|
|
|
|
if serie_default_enabled == 'True':
|
|
|
|
if item not in current_shows_sonarr:
|
|
|
|
c.execute('''INSERT INTO table_shows(title, path, tvdbId, languages,`hearing_impaired`, sonarrSeriesId, overview, poster, fanart, `audio_language`, sortTitle) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)''', (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']))
|
|
|
|
deleted_items.append(tuple([item]))
|
|
|
|
list_missing_subtitles(show["id"])
|
|
|
|
c.executemany('DELETE FROM table_shows WHERE tvdbId = ?',deleted_items)
|
|
|
|
else:
|
|
|
|
|
|
|
|
c.execute('''INSERT 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 = ?), ?, ?, ?, ?, ?, ?)''', (show["title"], show["path"], show["tvdbId"], show["tvdbId"], show["tvdbId"], show["id"], overview, poster, fanart, profile_id_to_language(show['qualityProfileId']), show['sortTitle']))
|
|
|
|
# Commit changes to database table
|
|
|
|
except:
|
|
|
|
db.commit()
|
|
|
|
c.execute('''UPDATE table_shows SET title = ?, path = ?, tvdbId = ?, sonarrSeriesId = ?, overview = ?, poster = ?, fanart = ?, `audio_language` = ? , sortTitle = ? WHERE tvdbid = ?''', (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"]))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Delete shows not in Sonarr anymore
|
|
|
|
|
|
|
|
deleted_items = []
|
|
|
|
|
|
|
|
for item in current_shows_db_list:
|
|
|
|
|
|
|
|
if item not in current_shows_sonarr:
|
|
|
|
|
|
|
|
deleted_items.append(tuple([item]))
|
|
|
|
|
|
|
|
c.executemany('DELETE FROM table_shows WHERE tvdbId = ?',deleted_items)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Commit changes to database table
|
|
|
|
|
|
|
|
db.commit()
|
|
|
|
|
|
|
|
|
|
|
|
# Close database connection
|
|
|
|
# Close database connection
|
|
|
|
db.close()
|
|
|
|
db.close()
|
|
|
@ -80,23 +91,48 @@ def get_profile_list():
|
|
|
|
apikey_sonarr = get_sonarr_settings()[2]
|
|
|
|
apikey_sonarr = get_sonarr_settings()[2]
|
|
|
|
|
|
|
|
|
|
|
|
# Get profiles data from Sonarr
|
|
|
|
# Get profiles data from Sonarr
|
|
|
|
|
|
|
|
error = False
|
|
|
|
|
|
|
|
|
|
|
|
url_sonarr_api_series = url_sonarr + "/api/profile?apikey=" + apikey_sonarr
|
|
|
|
url_sonarr_api_series = url_sonarr + "/api/profile?apikey=" + apikey_sonarr
|
|
|
|
profiles_json = requests.get(url_sonarr_api_series)
|
|
|
|
try:
|
|
|
|
|
|
|
|
profiles_json = requests.get(url_sonarr_api_series, timeout=15)
|
|
|
|
|
|
|
|
except requests.exceptions.ConnectionError as errc:
|
|
|
|
|
|
|
|
error = True
|
|
|
|
|
|
|
|
logging.exception("Error trying to get profiles from Sonarr. Connection Error.")
|
|
|
|
|
|
|
|
except requests.exceptions.Timeout as errt:
|
|
|
|
|
|
|
|
error = True
|
|
|
|
|
|
|
|
logging.exception("Error trying to get profiles from Sonarr. Timeout Error.")
|
|
|
|
|
|
|
|
except requests.exceptions.RequestException as err:
|
|
|
|
|
|
|
|
error = True
|
|
|
|
|
|
|
|
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
|
|
|
|
profiles_json_v3 = requests.get(url_sonarr_api_series_v3)
|
|
|
|
try:
|
|
|
|
|
|
|
|
profiles_json_v3 = requests.get(url_sonarr_api_series_v3, timeout=15)
|
|
|
|
|
|
|
|
except requests.exceptions.ConnectionError as errc:
|
|
|
|
|
|
|
|
error = True
|
|
|
|
|
|
|
|
logging.exception("Error trying to get profiles from Sonarr. Connection Error.")
|
|
|
|
|
|
|
|
except requests.exceptions.Timeout as errt:
|
|
|
|
|
|
|
|
error = True
|
|
|
|
|
|
|
|
logging.exception("Error trying to get profiles from Sonarr. Timeout Error.")
|
|
|
|
|
|
|
|
except requests.exceptions.RequestException as err:
|
|
|
|
|
|
|
|
error = True
|
|
|
|
|
|
|
|
logging.exception("Error trying to get profiles from Sonarr.")
|
|
|
|
|
|
|
|
|
|
|
|
global profiles_list
|
|
|
|
global profiles_list
|
|
|
|
profiles_list = []
|
|
|
|
profiles_list = []
|
|
|
|
|
|
|
|
|
|
|
|
# Parsing data returned from Sonarr
|
|
|
|
if error is False:
|
|
|
|
global sonarr_version
|
|
|
|
# Parsing data returned from Sonarr
|
|
|
|
if type(profiles_json_v3.json()) != list:
|
|
|
|
global sonarr_version
|
|
|
|
sonarr_version = 2
|
|
|
|
if type(profiles_json_v3.json()) != list:
|
|
|
|
for profile in profiles_json.json():
|
|
|
|
sonarr_version = 2
|
|
|
|
profiles_list.append([profile['id'], profile['language'].capitalize()])
|
|
|
|
for profile in profiles_json.json():
|
|
|
|
else:
|
|
|
|
profiles_list.append([profile['id'], profile['language'].capitalize()])
|
|
|
|
sonarr_version = 3
|
|
|
|
else:
|
|
|
|
for profile in profiles_json_v3.json():
|
|
|
|
sonarr_version = 3
|
|
|
|
profiles_list.append([profile['id'], profile['name'].capitalize()])
|
|
|
|
for profile in profiles_json_v3.json():
|
|
|
|
|
|
|
|
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:
|
|
|
|