mirror of
https://github.com/morpheus65535/bazarr
synced 2025-01-30 19:02:34 +00:00
Fix for #633.
This commit is contained in:
parent
5a2a5e5e8f
commit
24fc1473df
3 changed files with 42 additions and 30 deletions
|
@ -123,6 +123,12 @@ def sync_episodes():
|
|||
'audio_codec': audioCodec,
|
||||
'episode_file_id': episode['episodeFile']['id']})
|
||||
|
||||
# Remove old episodes from DB
|
||||
removed_episodes = list(set(current_episodes_db_list) - set(current_episodes_sonarr))
|
||||
|
||||
for removed_episode in removed_episodes:
|
||||
database.execute("DELETE FROM table_episodes WHERE sonarrEpisodeId=?", (removed_episode,))
|
||||
|
||||
# Update existing episodes in DB
|
||||
episode_in_db_list = []
|
||||
episodes_in_db = database.execute("SELECT sonarrSeriesId, sonarrEpisodeId, title, path, season, episode, "
|
||||
|
@ -145,17 +151,14 @@ def sync_episodes():
|
|||
# Insert new episodes in DB
|
||||
for added_episode in episodes_to_add:
|
||||
query = dict_converter.convert(added_episode)
|
||||
database.execute(
|
||||
result = database.execute(
|
||||
'''INSERT OR IGNORE INTO table_episodes(''' + query.keys_insert + ''') VALUES(''' + query.question_marks +
|
||||
''')''', query.values)
|
||||
altered_episodes.append([added_episode['sonarrEpisodeId'],
|
||||
added_episode['path']])
|
||||
|
||||
# Remove old episodes from DB
|
||||
removed_episodes = list(set(current_episodes_db_list) - set(current_episodes_sonarr))
|
||||
|
||||
for removed_episode in removed_episodes:
|
||||
database.execute("DELETE FROM table_episodes WHERE sonarrEpisodeId=?", (removed_episode,))
|
||||
if result:
|
||||
altered_episodes.append([added_episode['sonarrEpisodeId'], added_episode['path']])
|
||||
else:
|
||||
logging.debug('BAZARR unable to insert this episode into the database:',
|
||||
path_replace(added_episode['path']))
|
||||
|
||||
# Store subtitles for added or modified episodes
|
||||
for i, altered_episode in enumerate(altered_episodes, 1):
|
||||
|
|
|
@ -204,8 +204,14 @@ def update_movies():
|
|||
logging.error(
|
||||
'BAZARR Radarr returned a movie without a file path: ' + movie["path"] + separator +
|
||||
movie['movieFile']['relativePath'])
|
||||
|
||||
# Update or insert movies in DB
|
||||
|
||||
# Remove old movies from DB
|
||||
removed_movies = list(set(current_movies_db_list) - set(current_movies_radarr))
|
||||
|
||||
for removed_movie in removed_movies:
|
||||
database.execute("DELETE FROM table_movies WHERE tmdbId=?", (removed_movie,))
|
||||
|
||||
# Update movies in DB
|
||||
movies_in_db_list = []
|
||||
movies_in_db = database.execute("SELECT radarrId, title, path, tmdbId, overview, poster, fanart, "
|
||||
"audio_language, sceneName, monitored, sortTitle, year, "
|
||||
|
@ -229,19 +235,17 @@ def update_movies():
|
|||
# Insert new movies in DB
|
||||
for added_movie in movies_to_add:
|
||||
query = dict_converter.convert(added_movie)
|
||||
database.execute(
|
||||
result = database.execute(
|
||||
'''INSERT OR IGNORE INTO table_movies(''' + query.keys_insert + ''') VALUES(''' +
|
||||
query.question_marks + ''')''', query.values)
|
||||
altered_movies.append([added_movie['tmdbId'],
|
||||
added_movie['path'],
|
||||
added_movie['radarrId'],
|
||||
added_movie['monitored']])
|
||||
|
||||
# Remove old movies from DB
|
||||
removed_movies = list(set(current_movies_db_list) - set(current_movies_radarr))
|
||||
|
||||
for removed_movie in removed_movies:
|
||||
database.execute("DELETE FROM table_movies WHERE tmdbId=?", (removed_movie,))
|
||||
if result:
|
||||
altered_movies.append([added_movie['tmdbId'],
|
||||
added_movie['path'],
|
||||
added_movie['radarrId'],
|
||||
added_movie['monitored']])
|
||||
else:
|
||||
logging.debug('BAZARR unable to insert this movie into the database:',
|
||||
path_replace_movie(added_movie['path']))
|
||||
|
||||
# Store subtitles for added or modified movies
|
||||
for i, altered_movie in enumerate(altered_movies, 1):
|
||||
|
|
|
@ -12,6 +12,7 @@ from config import settings, url_sonarr
|
|||
from list_subtitles import list_missing_subtitles
|
||||
from database import database, dict_converter
|
||||
from utils import get_sonarr_version
|
||||
from helper import path_replace
|
||||
|
||||
|
||||
def update_series():
|
||||
|
@ -120,6 +121,12 @@ def update_series():
|
|||
'sortTitle': show['sortTitle'],
|
||||
'year': show['year'],
|
||||
'alternateTitles': alternateTitles})
|
||||
|
||||
# Remove old series from DB
|
||||
removed_series = list(set(current_shows_db_list) - set(current_shows_sonarr))
|
||||
|
||||
for series in removed_series:
|
||||
database.execute("DELETE FROM table_shows WHERE tvdbId=?",(series,))
|
||||
|
||||
# Update existing series in DB
|
||||
series_in_db_list = []
|
||||
|
@ -139,16 +146,14 @@ def update_series():
|
|||
# Insert new series in DB
|
||||
for added_series in series_to_add:
|
||||
query = dict_converter.convert(added_series)
|
||||
database.execute(
|
||||
result = database.execute(
|
||||
'''INSERT OR IGNORE INTO table_shows(''' + query.keys_insert + ''') VALUES(''' +
|
||||
query.question_marks + ''')''', query.values)
|
||||
list_missing_subtitles(no=added_series['sonarrSeriesId'])
|
||||
|
||||
# Remove old series from DB
|
||||
removed_series = list(set(current_shows_db_list) - set(current_shows_sonarr))
|
||||
|
||||
for series in removed_series:
|
||||
database.execute("DELETE FROM table_shows WHERE tvdbId=?",(series,))
|
||||
if result:
|
||||
list_missing_subtitles(no=added_series['sonarrSeriesId'])
|
||||
else:
|
||||
logging.debug('BAZARR unable to insert this series into the database:',
|
||||
path_replace(added_series['path']))
|
||||
|
||||
logging.debug('BAZARR All series synced from Sonarr into database.')
|
||||
|
||||
|
|
Loading…
Reference in a new issue