From 8e5f30e53a009d10646ce1d199a55ffe8517b3e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Louis=20V=C3=A9zina?= <5130500+morpheus65535@users.noreply.github.com> Date: Tue, 5 Feb 2019 22:49:58 -0500 Subject: [PATCH] Continuing development --- bazarr/get_episodes.py | 12 +++++++++--- bazarr/get_movies.py | 24 +++++++++++++++++------- bazarr/get_subtitle.py | 23 +++++++++++++++++------ bazarr/update_db.py | 8 ++++++++ 4 files changed, 51 insertions(+), 16 deletions(-) diff --git a/bazarr/get_episodes.py b/bazarr/get_episodes.py index e7f35a6ab..10c17fc6f 100644 --- a/bazarr/get_episodes.py +++ b/bazarr/get_episodes.py @@ -83,12 +83,18 @@ def sync_episodes(): episodes_to_update.append((episode['title'], episode['episodeFile']['path'], episode['seasonNumber'], episode['episodeNumber'], sceneName, str(bool(episode['monitored'])), + episode['episodeFile']['quality']['quality']['resolution'], + episode['episodeFile']['mediaInfo']['videoCodec'], + episode['episodeFile']['mediaInfo']['audioCodec'], episode['id'])) else: episodes_to_add.append((episode['seriesId'], episode['id'], episode['title'], episode['episodeFile']['path'], episode['seasonNumber'], episode['episodeNumber'], sceneName, - str(bool(episode['monitored'])))) + str(bool(episode['monitored'])), + episode['episodeFile']['quality']['quality']['resolution'], + episode['episodeFile']['mediaInfo']['videoCodec'], + episode['episodeFile']['mediaInfo']['audioCodec'])) removed_episodes = list(set(current_episodes_db_list) - set(current_episodes_sonarr)) @@ -97,12 +103,12 @@ def sync_episodes(): c = db.cursor() updated_result = c.executemany( - '''UPDATE table_episodes SET title = ?, path = ?, season = ?, episode = ?, scene_name = ?, monitored = ? WHERE sonarrEpisodeId = ?''', + '''UPDATE table_episodes SET title = ?, path = ?, season = ?, episode = ?, scene_name = ?, monitored = ?, resolution = ?, video_codec = ?, audio_codec = ? WHERE sonarrEpisodeId = ?''', episodes_to_update) db.commit() added_result = c.executemany( - '''INSERT OR IGNORE INTO table_episodes(sonarrSeriesId, sonarrEpisodeId, title, path, season, episode, scene_name, monitored) VALUES (?, ?, ?, ?, ?, ?, ?, ?)''', + '''INSERT OR IGNORE INTO table_episodes(sonarrSeriesId, sonarrEpisodeId, title, path, season, episode, scene_name, monitored, resolution, video_codec, audio_codec) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)''', episodes_to_add) db.commit() diff --git a/bazarr/get_movies.py b/bazarr/get_movies.py index 8206caa65..bccc56029 100644 --- a/bazarr/get_movies.py +++ b/bazarr/get_movies.py @@ -76,7 +76,7 @@ def update_movies(): if movie['alternativeTitles'] != None: alternativeTitles = str([item['title'] for item in movie['alternativeTitles']]) - + # Add movies in radarr to current movies list current_movies_radarr.append(unicode(movie['tmdbId'])) @@ -92,7 +92,11 @@ def update_movies(): movie["tmdbId"], movie["id"], overview, poster, fanart, profile_id_to_language(movie['qualityProfileId']), sceneName, unicode(bool(movie['monitored'])), movie['sortTitle'], - movie['year'], alternativeTitles, movie["tmdbId"])) + movie['year'], alternativeTitles, + movie['movieFile']['quality']['quality']['resolution'], + movie['movieFile']['mediaInfo']['videoCodecLibrary'], + movie['movieFile']['mediaInfo']['audioFormat'], + movie["tmdbId"])) else: if movie_default_enabled is True: movies_to_add.append((movie["title"], @@ -101,7 +105,10 @@ def update_movies(): movie["id"], overview, poster, fanart, profile_id_to_language(movie['qualityProfileId']), sceneName, unicode(bool(movie['monitored'])), movie['sortTitle'], - movie['year'], alternativeTitles)) + movie['year'], alternativeTitles, + movie['movieFile']['quality']['quality']['resolution'], + movie['movieFile']['mediaInfo']['videoCodecLibrary'], + movie['movieFile']['mediaInfo']['audioFormat'])) else: movies_to_add.append((movie["title"], movie["path"] + separator + movie['movieFile'][ @@ -109,7 +116,10 @@ def update_movies(): movie["tmdbId"], movie["id"], overview, poster, fanart, profile_id_to_language(movie['qualityProfileId']), sceneName, unicode(bool(movie['monitored'])), movie['sortTitle'], - movie['year'], alternativeTitles)) + movie['year'], alternativeTitles, + movie['moviefile']['quality']['quality']['resolution'], + movie['moviefile']['mediaInfo']['videoCodecLibrary'], + movie['moviefile']['mediaInfo']['audioFormat'])) else: logging.error( 'BAZARR Radarr returned a movie without a file path: ' + movie["path"] + separator + @@ -120,18 +130,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 = ? WHERE tmdbid = ?''', + '''UPDATE table_movies SET title = ?, path = ?, tmdbId = ?, radarrId = ?, overview = ?, poster = ?, fanart = ?, `audio_language` = ?, sceneName = ?, monitored = ?, sortTitle = ?, year = ?, alternativeTitles = ?, resolution = ?, video_codec = ?, audio_codec = ? 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) 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, resolution, video_codec, audio_codec) 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) 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, resolution, video_codec, audio_codec) 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 02e7ec5f2..e8a49b6f4 100644 --- a/bazarr/get_subtitle.py +++ b/bazarr/get_subtitle.py @@ -687,26 +687,37 @@ def refine_from_db(path, video): if isinstance(video, Episode): db = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30) c = db.cursor() - data = c.execute("SELECT table_shows.title, table_episodes.season, table_episodes.episode, table_episodes.title, table_shows.year, table_shows.tvdbId, table_shows.alternateTitles FROM table_episodes INNER JOIN table_shows on table_shows.sonarrSeriesId = table_episodes.sonarrSeriesId WHERE table_episodes.path = ?", (path_replace_reverse(path),)).fetchone() + data = c.execute("SELECT table_shows.title, table_episodes.season, table_episodes.episode, table_episodes.title, table_shows.year, table_shows.tvdbId, table_shows.alternateTitles, table_episodes.resolution, table_episodes.video_codec, table_episodes.audio_codec FROM table_episodes INNER JOIN table_shows on table_shows.sonarrSeriesId = table_episodes.sonarrSeriesId WHERE table_episodes.path = ?", (path_replace_reverse(path),)).fetchone() db.close() if data != None: video.series = re.sub(r'(\(\d\d\d\d\))' , '', data[0]) video.season = int(data[1]) video.episode = int(data[2]) video.title = data[3] - if int(data[4]) > 0: - video.year = int(data[4]) + if int(data[4]) > 0: video.year = int(data[4]) video.series_tvdb_id = int(data[5]) video.alternative_series = ast.literal_eval(data[6]) + if not video.resolution: + if data[7] in ('480','720','1080'): video.resolution = str(data[7]) + 'p' + if not video.video_codec: + if data[8] == 'x264': video.video_codec = 'h264' + elif data[8]: video.video_codec = data[8] + if not video.audio_codec: + if data[9]: video.audio_codec = data[9] 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 FROM table_movies WHERE path = ?", (path_replace_reverse_movie(path),)).fetchone() + data = c.execute("SELECT title, year, alternativeTitles, resolution, video_codec, audio_codec FROM table_movies WHERE path = ?", (path_replace_reverse_movie(path),)).fetchone() db.close() if data != None: video.title = re.sub(r'(\(\d\d\d\d\))' , '', data[0]) - if int(data[1]) > 0: - video.year = int(data[1]) + if int(data[1]) > 0: video.year = int(data[1]) video.alternative_titles = ast.literal_eval(data[2]) + if not video.resolution: + if data[3]: video.resolution = data[3].lstrip('r').lower() + if not video.video_codec: + if data[4]: video.video_codec = data[4] + if not video.audio_codec: + if data[5]: video.audio_codec = data[5] return video diff --git a/bazarr/update_db.py b/bazarr/update_db.py index 452f63ca1..e00f853ca 100644 --- a/bazarr/update_db.py +++ b/bazarr/update_db.py @@ -100,14 +100,22 @@ if os.path.exists(os.path.join(args.config_dir, 'db', 'bazarr.db')): c.execute('alter table table_shows add column "year" "text"') c.execute('alter table table_shows add column "alternateTitles" "text"') + c.execute('alter table table_episodes add column "resolution" "text"') + c.execute('alter table table_episodes add column "video_codec" "text"') + c.execute('alter table table_episodes add column "audio_codec" "text"') + c.execute('alter table table_movies add column "year" "text"') c.execute('alter table table_movies add column "alternativeTitles" "text"') + 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"') db.commit() except: pass else: if settings.general.getboolean('use_sonarr'): execute_now('update_series') + execute_now('sync_episodes') if settings.general.getboolean('use_radarr'): execute_now('update_movies')