|
|
@ -49,6 +49,7 @@ def update_series():
|
|
|
|
current_shows_sonarr = []
|
|
|
|
current_shows_sonarr = []
|
|
|
|
series_to_update = []
|
|
|
|
series_to_update = []
|
|
|
|
series_to_add = []
|
|
|
|
series_to_add = []
|
|
|
|
|
|
|
|
altered_series = []
|
|
|
|
|
|
|
|
|
|
|
|
seriesListLength = len(r.json())
|
|
|
|
seriesListLength = len(r.json())
|
|
|
|
for i, show in enumerate(r.json(), 1):
|
|
|
|
for i, show in enumerate(r.json(), 1):
|
|
|
@ -116,40 +117,48 @@ def update_series():
|
|
|
|
'year': show['year'],
|
|
|
|
'year': show['year'],
|
|
|
|
'alternate_title': alternateTitles})
|
|
|
|
'alternate_title': alternateTitles})
|
|
|
|
|
|
|
|
|
|
|
|
# Update or insert series in DB
|
|
|
|
# Update existing series in DB
|
|
|
|
db = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30)
|
|
|
|
series_in_db_list = []
|
|
|
|
c = db.cursor()
|
|
|
|
series_in_db = TableShows.select(
|
|
|
|
|
|
|
|
TableShows.title,
|
|
|
|
updated_result = c.executemany(
|
|
|
|
TableShows.path,
|
|
|
|
'''UPDATE table_shows SET title = ?, path = ?, tvdbId = ?, sonarrSeriesId = ?, overview = ?, poster = ?, fanart = ?, `audio_language` = ? , sortTitle = ?, year = ?, alternateTitles = ? WHERE tvdbid = ?''',
|
|
|
|
TableShows.tvdb_id,
|
|
|
|
series_to_update)
|
|
|
|
TableShows.sonarr_series_id,
|
|
|
|
db.commit()
|
|
|
|
TableShows.overview,
|
|
|
|
|
|
|
|
TableShows.poster,
|
|
|
|
if serie_default_enabled is True:
|
|
|
|
TableShows.fanart,
|
|
|
|
added_result = c.executemany(
|
|
|
|
TableShows.audio_language,
|
|
|
|
'''INSERT OR IGNORE INTO table_shows(title, path, tvdbId, languages,`hearing_impaired`, sonarrSeriesId, overview, poster, fanart, `audio_language`, sortTitle, year, alternateTitles, forced) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)''',
|
|
|
|
TableShows.sort_title,
|
|
|
|
series_to_add)
|
|
|
|
TableShows.year,
|
|
|
|
db.commit()
|
|
|
|
TableShows.alternate_titles
|
|
|
|
else:
|
|
|
|
).dicts()
|
|
|
|
added_result = c.executemany(
|
|
|
|
|
|
|
|
'''INSERT OR IGNORE INTO table_shows(title, path, tvdbId, languages,`hearing_impaired`, sonarrSeriesId, overview, poster, fanart, `audio_language`, sortTitle, year, alternateTitles, forced) VALUES (?,?,?,(SELECT languages FROM table_shows WHERE tvdbId = ?),(SELECT `hearing_impaired` FROM table_shows WHERE tvdbId = ?), ?, ?, ?, ?, ?, ?, ?, ?, (SELECT `forced` FROM table_shows WHERE tvdbId = ?))''',
|
|
|
|
for item in series_in_db:
|
|
|
|
series_to_add)
|
|
|
|
series_in_db_list.append(item)
|
|
|
|
db.commit()
|
|
|
|
|
|
|
|
db.close()
|
|
|
|
series_to_update_list = [i for i in series_to_update if i not in series_in_db_list]
|
|
|
|
|
|
|
|
|
|
|
|
for show in series_to_add:
|
|
|
|
for updated_series in series_to_update_list:
|
|
|
|
list_missing_subtitles(show[5])
|
|
|
|
TableShows.update(
|
|
|
|
|
|
|
|
updated_series
|
|
|
|
# Delete shows not in Sonarr anymore
|
|
|
|
).where(
|
|
|
|
deleted_items = []
|
|
|
|
TableShows.sonarr_series_id == updated_series['sonarr_series_id']
|
|
|
|
for item in current_shows_db_list:
|
|
|
|
).execute()
|
|
|
|
if item not in current_shows_sonarr:
|
|
|
|
|
|
|
|
deleted_items.append(tuple([item]))
|
|
|
|
# Insert new series in DB
|
|
|
|
db = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30)
|
|
|
|
for added_series in series_to_add:
|
|
|
|
c = db.cursor()
|
|
|
|
TableShows.insert(
|
|
|
|
c.executemany('DELETE FROM table_shows WHERE tvdbId = ?', deleted_items)
|
|
|
|
added_series
|
|
|
|
db.commit()
|
|
|
|
).on_conflict_ignore().execute()
|
|
|
|
db.close()
|
|
|
|
list_missing_subtitles(added_series['sonarr_series_id'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Remove old episodes from DB
|
|
|
|
|
|
|
|
removed_series = list(set(current_shows_db_list) - set(current_shows_sonarr))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for series in removed_series:
|
|
|
|
|
|
|
|
print TableShows.delete().where(
|
|
|
|
|
|
|
|
TableShows.tvdb_id == series
|
|
|
|
|
|
|
|
).execute()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_profile_list():
|
|
|
|
def get_profile_list():
|
|
|
|