1
0
Fork 0
mirror of https://github.com/morpheus65535/bazarr synced 2024-12-26 01:27:07 +00:00

Improvement to the episodes and movies update process. We now scan for existing subtitles and store them in DB when Sonarr or Radarr replace or rename the media file.

This commit is contained in:
morpheus65535 2019-01-06 13:50:36 -05:00
parent 84ccabfad4
commit 8b3bf459ea
2 changed files with 19 additions and 18 deletions

View file

@ -35,7 +35,7 @@ def sync_episodes():
c = db.cursor()
# Get current episodes id in DB
current_episodes_db = c.execute('SELECT sonarrEpisodeId FROM table_episodes').fetchall()
current_episodes_db = c.execute('SELECT sonarrEpisodeId, path FROM table_episodes').fetchall()
current_episodes_db_list = [x[0] for x in current_episodes_db]
current_episodes_sonarr = []
@ -99,15 +99,16 @@ def sync_episodes():
c.execute('DELETE FROM table_episodes WHERE sonarrEpisodeId = ?', (removed_episode,))
db.commit()
# Get episodes list after INSERT and UPDATE
episodes_now_in_db = c.execute('SELECT sonarrEpisodeId, path FROM table_episodes').fetchall()
# Close database connection
c.close()
# TODO: Commented until I find a way to make it store only episodes really updated.
#for updated_episode in episodes_to_update:
# store_subtitles(path_replace(updated_episode[1]))
for added_episode in episodes_to_add:
store_subtitles(path_replace(added_episode[3]))
# Get only episodes added or modified and store subtitles for them
altered_episodes = set(episodes_now_in_db).difference(set(current_episodes_db))
for altered_episode in altered_episodes:
store_subtitles(path_replace(altered_episode[1]))
logging.debug('BAZARR All episodes synced from Sonarr into database.')

View file

@ -41,7 +41,7 @@ def update_movies():
# 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, path FROM table_movies').fetchall()
db.close()
current_movies_db_list = [x[0] for x in current_movies_db]
@ -105,23 +105,23 @@ def update_movies():
else:
added_result = c.executemany('''INSERT OR IGNORE INTO table_movies(title, path, tmdbId, languages, subtitles,`hearing_impaired`, radarrId, overview, poster, fanart, `audio_language`, sceneName, monitored, sortTitle) VALUES (?,?,?,(SELECT languages FROM table_movies WHERE tmdbId = ?), '[]',(SELECT `hearing_impaired` FROM table_movies WHERE tmdbId = ?), ?, ?, ?, ?, ?, ?, ?, ?)''', movies_to_add)
db.commit()
db.close()
removed_movies = list(set(current_movies_db_list) - set(current_movies_radarr))
db = sqlite3.connect(os.path.join(config_dir, 'db', 'bazarr.db'), timeout=30)
c = db.cursor()
for removed_movie in removed_movies:
c.execute('DELETE FROM table_movies WHERE tmdbId = ?', (removed_movie,))
db.commit()
db.commit()
# Get movies list after INSERT and UPDATE
movies_now_in_db = c.execute('SELECT tmdbId, path FROM table_movies').fetchall()
# Close database connection
db.close()
for added_movie in movies_to_add:
store_subtitles_movie(path_replace_movie(added_movie[1]))
# TODO: Commented until I find a way to make it store only episodes really updated.
# for updated_movie in movies_to_update:
# store_subtitles_movie(path_replace_movie(updated_movie[1]))
# Get only movies added or modified and store subtitles for them
altered_movies = set(movies_now_in_db).difference(set(current_movies_db))
for altered_movie in altered_movies:
store_subtitles_movie(path_replace_movie(altered_movie[1]))
logging.debug('BAZARR All movies synced from Radarr into database.')