From cfea2951981d3dc9bad73cd1bd2706069155fc32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Louis=20V=C3=A9zina?= <5130500+morpheus65535@users.noreply.github.com> Date: Sun, 10 Feb 2019 22:42:42 -0500 Subject: [PATCH] Continuing development --- bazarr/get_movies.py | 15 +++++++++------ bazarr/get_subtitle.py | 3 ++- bazarr/update_db.py | 1 + 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/bazarr/get_movies.py b/bazarr/get_movies.py index 5ca1b8900..695322758 100644 --- a/bazarr/get_movies.py +++ b/bazarr/get_movies.py @@ -77,6 +77,9 @@ def update_movies(): if movie['alternativeTitles'] != None: alternativeTitles = str([item['title'] for item in movie['alternativeTitles']]) + if 'imdbId' in movie: imdbId = movie['imdbId'] + else: imdbId = None + try: format, resolution = movie['movieFile']['quality']['quality']['name'].split('-') except: @@ -111,7 +114,7 @@ def update_movies(): profile_id_to_language(movie['qualityProfileId']), sceneName, unicode(bool(movie['monitored'])), movie['sortTitle'], movie['year'], alternativeTitles, format, resolution, - videoCodec, audioCodec, movie["tmdbId"])) + videoCodec, audioCodec, imdbId, movie["tmdbId"])) else: if movie_default_enabled is True: movies_to_add.append((movie["title"], @@ -121,7 +124,7 @@ def update_movies(): profile_id_to_language(movie['qualityProfileId']), sceneName, unicode(bool(movie['monitored'])), movie['sortTitle'], movie['year'], alternativeTitles, format, resolution, - videoCodec, audioCodec)) + videoCodec, audioCodec, imdbId)) else: movies_to_add.append((movie["title"], movie["path"] + separator + movie['movieFile'][ @@ -130,7 +133,7 @@ def update_movies(): profile_id_to_language(movie['qualityProfileId']), sceneName, unicode(bool(movie['monitored'])), movie['sortTitle'], movie['year'], alternativeTitles, format, resolution, - videoCodec, audioCodec)) + videoCodec, audioCodec, imdbId)) else: logging.error( 'BAZARR Radarr returned a movie without a file path: ' + movie["path"] + separator + @@ -141,18 +144,18 @@ def update_movies(): c = db.cursor() updated_result = c.executemany( - '''UPDATE table_movies SET title = ?, path = ?, tmdbId = ?, radarrId = ?, overview = ?, poster = ?, fanart = ?, `audio_language` = ?, sceneName = ?, monitored = ?, sortTitle = ?, year = ?, alternativeTitles = ?, format = ?, resolution = ?, video_codec = ?, audio_codec = ? WHERE tmdbid = ?''', + '''UPDATE table_movies SET title = ?, path = ?, tmdbId = ?, radarrId = ?, overview = ?, poster = ?, fanart = ?, `audio_language` = ?, sceneName = ?, monitored = ?, sortTitle = ?, year = ?, alternativeTitles = ?, format = ?, resolution = ?, video_codec = ?, audio_codec = ?, imdbId = ? WHERE tmdbid = ?''', movies_to_update) db.commit() if movie_default_enabled is True: 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, year, alternativeTitles, format, resolution, video_codec, audio_codec) VALUES (?,?,?,?,?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)''', + '''INSERT OR IGNORE INTO table_movies(title, path, tmdbId, languages, subtitles,`hearing_impaired`, radarrId, overview, poster, fanart, `audio_language`, sceneName, monitored, sortTitle, year, alternativeTitles, format, resolution, video_codec, audio_codec, imdbId) VALUES (?,?,?,?,?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)''', movies_to_add) db.commit() 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, year, alternativeTitles, format, resolution, video_codec, audio_codec) VALUES (?,?,?,(SELECT languages FROM table_movies WHERE tmdbId = ?), '[]',(SELECT `hearing_impaired` FROM table_movies WHERE tmdbId = ?), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)''', + '''INSERT OR IGNORE INTO table_movies(title, path, tmdbId, languages, subtitles,`hearing_impaired`, radarrId, overview, poster, fanart, `audio_language`, sceneName, monitored, sortTitle, year, alternativeTitles, format, resolution, video_codec, audio_codec, imdbId) VALUES (?,?,?,(SELECT languages FROM table_movies WHERE tmdbId = ?), '[]',(SELECT `hearing_impaired` FROM table_movies WHERE tmdbId = ?), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)''', movies_to_add) db.commit() diff --git a/bazarr/get_subtitle.py b/bazarr/get_subtitle.py index 0208d4319..f1fe7ca11 100644 --- a/bazarr/get_subtitle.py +++ b/bazarr/get_subtitle.py @@ -708,11 +708,12 @@ def refine_from_db(path, video): elif isinstance(video, Movie): db = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30) c = db.cursor() - data = c.execute("SELECT title, year, alternativeTitles, format, resolution, video_codec, audio_codec FROM table_movies WHERE path = ?", (path_replace_reverse_movie(path),)).fetchone() + data = c.execute("SELECT title, year, alternativeTitles, format, resolution, video_codec, audio_codec, imdbId FROM table_movies WHERE path = ?", (path_replace_reverse_movie(path),)).fetchone() db.close() if data: video.title = re.sub(r'(\(\d\d\d\d\))' , '', data[0]) if int(data[1]) > 0: video.year = int(data[1]) + if data[7]: video.imdb_id = data[7] video.alternative_titles = ast.literal_eval(data[2]) if not video.format: if data[3]: video.format = data[3] diff --git a/bazarr/update_db.py b/bazarr/update_db.py index e525f3968..98a1b55c0 100644 --- a/bazarr/update_db.py +++ b/bazarr/update_db.py @@ -111,6 +111,7 @@ if os.path.exists(os.path.join(args.config_dir, 'db', 'bazarr.db')): c.execute('alter table table_movies add column "resolution" "text"') c.execute('alter table table_movies add column "video_codec" "text"') c.execute('alter table table_movies add column "audio_codec" "text"') + c.execute('alter table table_movies add column "imdbId" "text"') db.commit() except: pass