From 337860e8912bb285149b722d82c9169fd2bc9488 Mon Sep 17 00:00:00 2001 From: morpheus65535 <5130500+morpheus65535@users.noreply.github.com> Date: Tue, 29 May 2018 12:18:59 -0400 Subject: [PATCH] Initial release of Radarr integration --- bazarr.py | 2 +- get_movies.py | 22 ++++++++++++++-------- scheduler.py | 2 +- update_db.py | 2 +- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/bazarr.py b/bazarr.py index 0e2d5ea03..bfb0329ee 100644 --- a/bazarr.py +++ b/bazarr.py @@ -1,4 +1,4 @@ -bazarr_version = '0.5.0 dev' +bazarr_version = '0.5.0' import gc gc.enable() diff --git a/get_movies.py b/get_movies.py index 9b089387b..c2275ae3b 100644 --- a/get_movies.py +++ b/get_movies.py @@ -3,6 +3,7 @@ import sqlite3 import requests from get_general_settings import * +from list_subtitles import * def update_movies(): from get_radarr_settings import get_radarr_settings @@ -64,15 +65,20 @@ def update_movies(): except: c.execute('''UPDATE table_movies SET title = ?, path = ?, tmdbId = ?, radarrId = ?, overview = ?, poster = ?, fanart = ?, `audio_language` = ?, sceneName = ? WHERE tmdbid = ?''', (movie["title"],movie["path"] + separator + movie['movieFile']['relativePath'],movie["tmdbId"],movie["id"],overview,poster,fanart,profile_id_to_language(movie['qualityProfileId']),sceneName,movie["tmdbId"])) + # Commit changes to database table + db.commit() + # Delete movies not in radarr anymore - deleted_items = [] - for item in current_movies_db_list: - if item not in current_movies_radarr: - deleted_items.append(tuple([item])) - c.executemany('DELETE FROM table_movies WHERE tmdbId = ?',deleted_items) - - # Commit changes to database table - db.commit() + added_movies = list(set(current_movies_radarr) - set(current_movies_db_list)) + removed_movies = list(set(current_movies_db_list) - set(current_movies_radarr)) + + for removed_movie in removed_movies: + c.execute('DELETE FROM table_movies WHERE radarrId = ?', (removed_movie,)) + db.commit() + + for added_movie in added_movies: + added_path = c.execute('SELECT path FROM table_movies WHERE tmdbId = ?', (added_movie,)).fetchone() + store_subtitles_movie(path_replace(added_path[0])) # Close database connection db.close() diff --git a/scheduler.py b/scheduler.py index 465c3103a..d578f8f99 100644 --- a/scheduler.py +++ b/scheduler.py @@ -54,7 +54,7 @@ if integration[12] == "True": scheduler.add_job(sync_episodes, 'interval', minutes=5, max_instances=1, coalesce=True, misfire_grace_time=15, id='sync_episodes', name='Sync episodes with Sonarr') if integration[13] == "True": - scheduler.add_job(update_movies, 'interval', minutes=1, max_instances=1, coalesce=True, misfire_grace_time=15, id='update_movies', name='Update movies list from Radarr') + scheduler.add_job(update_movies, 'interval', minutes=5, max_instances=1, coalesce=True, misfire_grace_time=15, id='update_movies', name='Update movies list from Radarr') if integration[12] == "True" or integration[13] == "True": scheduler.add_job(wanted_search_missing_subtitles, 'interval', hours=3, max_instances=1, coalesce=True, misfire_grace_time=15, id='wanted_search_missing_subtitles', name='Search for wanted subtitles') diff --git a/update_db.py b/update_db.py index b01bf9ddd..d7aedce62 100644 --- a/update_db.py +++ b/update_db.py @@ -92,7 +92,7 @@ if os.path.exists(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db')) except: pass else: - c.execute('INSERT INTO `table_settings_radarr` (ip, port, base_url, ssl, apikey, full_update) VALUES ("0.0.0.0", "7878", "/", "False", Null, "Daily")') + c.execute('INSERT INTO `table_settings_radarr` (ip, port, base_url, ssl, apikey, full_update) VALUES ("127.0.0.1", "7878", "/", "False", Null, "Daily")') try: c.execute('CREATE TABLE "table_movies" ( `tmdbId` TEXT NOT NULL UNIQUE, `title` TEXT NOT NULL, `path` TEXT NOT NULL UNIQUE, `languages` TEXT, `subtitles` TEXT, `missing_subtitles` TEXT, `hearing_impaired` TEXT, `radarrId` INTEGER NOT NULL UNIQUE, `overview` TEXT, `poster` TEXT, `fanart` TEXT, "audio_language" "text", `sceneName` TEXT, PRIMARY KEY(`tmdbId`) )')