|
|
@ -12,16 +12,11 @@ def update_movies():
|
|
|
|
logging.debug('Starting movie sync from Radarr.')
|
|
|
|
logging.debug('Starting movie sync from Radarr.')
|
|
|
|
from get_settings import get_radarr_settings
|
|
|
|
from get_settings import get_radarr_settings
|
|
|
|
url_radarr = get_radarr_settings()[6]
|
|
|
|
url_radarr = get_radarr_settings()[6]
|
|
|
|
# url_radarr_short = get_radarr_settings()[7]
|
|
|
|
|
|
|
|
apikey_radarr = get_radarr_settings()[4]
|
|
|
|
apikey_radarr = get_radarr_settings()[4]
|
|
|
|
movie_default_enabled = get_general_settings()[18]
|
|
|
|
movie_default_enabled = get_general_settings()[18]
|
|
|
|
movie_default_language = get_general_settings()[19]
|
|
|
|
movie_default_language = get_general_settings()[19]
|
|
|
|
movie_default_hi = get_general_settings()[20]
|
|
|
|
movie_default_hi = get_general_settings()[20]
|
|
|
|
|
|
|
|
|
|
|
|
# Open database connection
|
|
|
|
|
|
|
|
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
|
|
|
|
|
|
|
c = db.cursor()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if apikey_radarr == None:
|
|
|
|
if apikey_radarr == None:
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
else:
|
|
|
@ -42,9 +37,15 @@ def update_movies():
|
|
|
|
logging.exception("Error trying to get movies from Radarr.")
|
|
|
|
logging.exception("Error trying to get movies from Radarr.")
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
# Get current movies in DB
|
|
|
|
# Get current movies in DB
|
|
|
|
|
|
|
|
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
|
|
|
|
|
|
|
c = db.cursor()
|
|
|
|
current_movies_db = c.execute('SELECT tmdbId FROM table_movies').fetchall()
|
|
|
|
current_movies_db = c.execute('SELECT tmdbId FROM table_movies').fetchall()
|
|
|
|
|
|
|
|
db.close()
|
|
|
|
|
|
|
|
|
|
|
|
current_movies_db_list = [x[0] for x in current_movies_db]
|
|
|
|
current_movies_db_list = [x[0] for x in current_movies_db]
|
|
|
|
current_movies_radarr = []
|
|
|
|
current_movies_radarr = []
|
|
|
|
|
|
|
|
movies_to_update = []
|
|
|
|
|
|
|
|
movies_to_add = []
|
|
|
|
|
|
|
|
|
|
|
|
for movie in r.json():
|
|
|
|
for movie in r.json():
|
|
|
|
if movie['hasFile'] is True:
|
|
|
|
if movie['hasFile'] is True:
|
|
|
@ -63,13 +64,10 @@ def update_movies():
|
|
|
|
except:
|
|
|
|
except:
|
|
|
|
fanart = ""
|
|
|
|
fanart = ""
|
|
|
|
|
|
|
|
|
|
|
|
if 'movieFile' in movie:
|
|
|
|
|
|
|
|
if 'sceneName' in movie['movieFile']:
|
|
|
|
if 'sceneName' in movie['movieFile']:
|
|
|
|
sceneName = movie['movieFile']['sceneName']
|
|
|
|
sceneName = movie['movieFile']['sceneName']
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
sceneName = None
|
|
|
|
sceneName = None
|
|
|
|
else:
|
|
|
|
|
|
|
|
sceneName = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Add movies in radarr to current movies list
|
|
|
|
# Add movies in radarr to current movies list
|
|
|
|
current_movies_radarr.append(unicode(movie['tmdbId']))
|
|
|
|
current_movies_radarr.append(unicode(movie['tmdbId']))
|
|
|
@ -80,31 +78,43 @@ def update_movies():
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
separator = "\\"
|
|
|
|
separator = "\\"
|
|
|
|
|
|
|
|
|
|
|
|
# Update or insert movies list in database table
|
|
|
|
if unicode(movie['tmdbId']) in current_movies_db_list:
|
|
|
|
try:
|
|
|
|
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:
|
|
|
|
if movie_default_enabled is True:
|
|
|
|
c.execute('''INSERT INTO table_movies(title, path, tmdbId, languages, subtitles,`hearing_impaired`, radarrId, overview, poster, fanart, `audio_language`, sceneName, monitored) VALUES (?,?,?,?,?, ?, ?, ?, ?, ?, ?, ?, ?)''', (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:
|
|
|
|
else:
|
|
|
|
c.execute('''INSERT 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 = ?), ?, ?, ?, ?, ?, ?, ?)''', (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']))))
|
|
|
|
except:
|
|
|
|
|
|
|
|
c.execute('''UPDATE table_movies SET title = ?, path = ?, tmdbId = ?, radarrId = ?, overview = ?, poster = ?, fanart = ?, `audio_language` = ?, sceneName = ?, monitored = ? WHERE tmdbid = ?''', (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"]))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Commit changes to database table
|
|
|
|
# Update or insert movies in DB
|
|
|
|
|
|
|
|
db = sqlite3.connect(os.path.join(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)
|
|
|
|
|
|
|
|
db.commit()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if movie_default_enabled is True:
|
|
|
|
|
|
|
|
added_result = c.executemany('''INSERT 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 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.commit()
|
|
|
|
|
|
|
|
db.close()
|
|
|
|
|
|
|
|
|
|
|
|
# Delete movies not in radarr anymore
|
|
|
|
|
|
|
|
added_movies = list(set(current_movies_radarr) - set(current_movies_db_list))
|
|
|
|
added_movies = list(set(current_movies_radarr) - set(current_movies_db_list))
|
|
|
|
removed_movies = list(set(current_movies_db_list) - set(current_movies_radarr))
|
|
|
|
removed_movies = list(set(current_movies_db_list) - set(current_movies_radarr))
|
|
|
|
|
|
|
|
|
|
|
|
for removed_movie in removed_movies:
|
|
|
|
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
|
|
|
c.execute('DELETE FROM table_movies WHERE tmdbId = ?', (removed_movie,))
|
|
|
|
c = db.cursor()
|
|
|
|
|
|
|
|
c.executemany('DELETE FROM table_movies WHERE tmdbId = ?', removed_movies)
|
|
|
|
db.commit()
|
|
|
|
db.commit()
|
|
|
|
|
|
|
|
db.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
|
|
|
|
|
|
|
c = db.cursor()
|
|
|
|
for added_movie in added_movies:
|
|
|
|
for added_movie in added_movies:
|
|
|
|
added_path = c.execute('SELECT path FROM table_movies WHERE tmdbId = ?', (added_movie,)).fetchone()
|
|
|
|
added_path = c.execute('SELECT path FROM table_movies WHERE tmdbId = ?', (added_movie,)).fetchone()
|
|
|
|
store_subtitles_movie(path_replace_movie(added_path[0]))
|
|
|
|
store_subtitles_movie(path_replace_movie(added_path[0]))
|
|
|
|
|
|
|
|
|
|
|
|
# Close database connection
|
|
|
|
|
|
|
|
db.close()
|
|
|
|
db.close()
|
|
|
|
|
|
|
|
|
|
|
|
logging.debug('All movies synced from Radarr into database.')
|
|
|
|
logging.debug('All movies synced from Radarr into database.')
|
|
|
|