From 63d503756687e9834024a96f549b01060749dfb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Louis=20V=C3=A9zina?= <5130500+morpheus65535@users.noreply.github.com> Date: Sat, 5 Oct 2019 22:39:58 -0400 Subject: [PATCH] Added episodefile and moviefile id to database for future use. --- bazarr/database.py | 13 +++++++++++++ bazarr/get_episodes.py | 9 ++++++--- bazarr/get_movies.py | 12 ++++++++---- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/bazarr/database.py b/bazarr/database.py index 6d2353b7b..5b1cce45a 100644 --- a/bazarr/database.py +++ b/bazarr/database.py @@ -4,6 +4,7 @@ import atexit from get_args import args from peewee import * from playhouse.sqliteq import SqliteQueueDatabase +from playhouse.migrate import * from helper import path_replace, path_replace_movie, path_replace_reverse, path_replace_reverse_movie @@ -14,6 +15,8 @@ database = SqliteQueueDatabase( queue_max_size=256, # Max. # of pending writes that can accumulate. results_timeout=30.0) # Max. time to wait for query to be executed. +migrator = SqliteMigrator(database) + @database.func('path_substitution') def path_substitution(path): @@ -78,6 +81,11 @@ class TableEpisodes(BaseModel): subtitles = TextField(null=True) title = TextField(null=True) video_codec = TextField(null=True) + episode_file_id = IntegerField(null=True) + + migrate( + migrator.add_column('table_episodes', 'episode_file_id', episode_file_id), + ) class Meta: table_name = 'table_episodes' @@ -109,6 +117,11 @@ class TableMovies(BaseModel): tmdb_id = TextField(column_name='tmdbId', primary_key=True, null=False) video_codec = TextField(null=True) year = TextField(null=True) + movie_file_id = IntegerField(null=True) + + migrate( + migrator.add_column('table_movies', 'movie_file_id', movie_file_id), + ) class Meta: table_name = 'table_movies' diff --git a/bazarr/get_episodes.py b/bazarr/get_episodes.py index 09a1220b8..cc6e5369a 100644 --- a/bazarr/get_episodes.py +++ b/bazarr/get_episodes.py @@ -116,7 +116,8 @@ def sync_episodes(): 'format': format, 'resolution': resolution, 'video_codec': videoCodec, - 'audio_codec': audioCodec}) + 'audio_codec': audioCodec, + 'episode_file_id': episode['episodeFile']['id']}) else: episodes_to_add.append({'sonarr_series_id': episode['seriesId'], 'sonarr_episode_id': episode['id'], @@ -129,7 +130,8 @@ def sync_episodes(): 'format': format, 'resolution': resolution, 'video_codec': videoCodec, - 'audio_codec': audioCodec}) + 'audio_codec': audioCodec, + 'episode_file_id': episode['episodeFile']['id']}) # Update existing episodes in DB episode_in_db_list = [] @@ -145,7 +147,8 @@ def sync_episodes(): TableEpisodes.format, TableEpisodes.resolution, TableEpisodes.video_codec, - TableEpisodes.audio_codec + TableEpisodes.audio_codec, + TableEpisodes.episode_file_id ).dicts() for item in episodes_in_db: diff --git a/bazarr/get_movies.py b/bazarr/get_movies.py index 6a754ae32..5f545580b 100644 --- a/bazarr/get_movies.py +++ b/bazarr/get_movies.py @@ -156,7 +156,8 @@ def update_movies(): 'video_codec': unicode(videoCodec), 'audio_codec': unicode(audioCodec), 'overview': unicode(overview), - 'imdb_id': unicode(imdbId)}) + 'imdb_id': unicode(imdbId), + 'movie_file_id': movie['movieFile']['id']}) else: if movie_default_enabled is True: movies_to_add.append({'radarr_id': movie["id"], @@ -180,7 +181,8 @@ def update_movies(): 'video_codec': videoCodec, 'audio_codec': audioCodec, 'imdb_id': imdbId, - 'forced': movie_default_forced}) + 'forced': movie_default_forced, + 'movie_file_id': movie['movieFile']['id']}) else: movies_to_add.append({'radarr_id': movie["id"], 'title': movie["title"], @@ -199,7 +201,8 @@ def update_movies(): 'resolution': resolution, 'video_codec': videoCodec, 'audio_codec': audioCodec, - 'imdb_id': imdbId}) + 'imdb_id': imdbId, + 'movie_file_id': movie['movieFile']['id']}) else: logging.error( 'BAZARR Radarr returned a movie without a file path: ' + movie["path"] + separator + @@ -225,7 +228,8 @@ def update_movies(): TableMovies.resolution, TableMovies.video_codec, TableMovies.audio_codec, - TableMovies.imdb_id + TableMovies.imdb_id, + TableMovies.movie_file_id ).dicts() for item in movies_in_db: