From 41a00305e33e99942ddec8c4c52b15486992a4b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Louis=20V=C3=A9zina?= <5130500+morpheus65535@users.noreply.github.com> Date: Wed, 6 Feb 2019 06:51:19 -0500 Subject: [PATCH] Continuing development --- bazarr/get_episodes.py | 17 +++++++++++------ bazarr/get_movies.py | 21 ++++++++++++--------- bazarr/get_subtitle.py | 18 +++++++++++------- bazarr/update_db.py | 2 ++ 4 files changed, 36 insertions(+), 22 deletions(-) diff --git a/bazarr/get_episodes.py b/bazarr/get_episodes.py index 10c17fc6f..9989285c5 100644 --- a/bazarr/get_episodes.py +++ b/bazarr/get_episodes.py @@ -75,7 +75,13 @@ def sync_episodes(): sceneName = episode['episodeFile']['sceneName'] else: sceneName = None - + + try: + format, resolution = episode['episodeFile']['quality']['quality']['name'].split('-') + except: + format = episode['episodeFile']['quality']['quality']['name'] + resolution = str(episode['episodeFile']['quality']['quality']['resolution']) + 'p' + # Add episodes in sonarr to current episode list current_episodes_sonarr.append(episode['id']) @@ -83,7 +89,7 @@ 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'], + format, resolution, episode['episodeFile']['mediaInfo']['videoCodec'], episode['episodeFile']['mediaInfo']['audioCodec'], episode['id'])) @@ -91,8 +97,7 @@ def sync_episodes(): episodes_to_add.append((episode['seriesId'], episode['id'], episode['title'], episode['episodeFile']['path'], episode['seasonNumber'], episode['episodeNumber'], sceneName, - str(bool(episode['monitored'])), - episode['episodeFile']['quality']['quality']['resolution'], + str(bool(episode['monitored'])), format, resolution, episode['episodeFile']['mediaInfo']['videoCodec'], episode['episodeFile']['mediaInfo']['audioCodec'])) @@ -103,12 +108,12 @@ def sync_episodes(): c = db.cursor() updated_result = c.executemany( - '''UPDATE table_episodes SET title = ?, path = ?, season = ?, episode = ?, scene_name = ?, monitored = ?, resolution = ?, video_codec = ?, audio_codec = ? WHERE sonarrEpisodeId = ?''', + '''UPDATE table_episodes SET title = ?, path = ?, season = ?, episode = ?, scene_name = ?, monitored = ?, format = ?, 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, resolution, video_codec, audio_codec) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)''', + '''INSERT OR IGNORE INTO table_episodes(sonarrSeriesId, sonarrEpisodeId, title, path, season, episode, scene_name, monitored, format, resolution, video_codec, audio_codec) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)''', episodes_to_add) db.commit() diff --git a/bazarr/get_movies.py b/bazarr/get_movies.py index bccc56029..e2d11a5c5 100644 --- a/bazarr/get_movies.py +++ b/bazarr/get_movies.py @@ -77,6 +77,12 @@ def update_movies(): if movie['alternativeTitles'] != None: alternativeTitles = str([item['title'] for item in movie['alternativeTitles']]) + try: + format, resolution = movie['movieFile']['quality']['quality']['name'].split('-') + except: + format = movie['movieFile']['quality']['quality']['name'] + resolution = movie['movieFile']['quality']['quality']['resolution'].lstrip('r').lower() + # Add movies in radarr to current movies list current_movies_radarr.append(unicode(movie['tmdbId'])) @@ -92,8 +98,7 @@ 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['movieFile']['quality']['quality']['resolution'], + movie['year'], alternativeTitles, format, resolution, movie['movieFile']['mediaInfo']['videoCodecLibrary'], movie['movieFile']['mediaInfo']['audioFormat'], movie["tmdbId"])) @@ -105,8 +110,7 @@ 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['movieFile']['quality']['quality']['resolution'], + movie['year'], alternativeTitles, format, resolution, movie['movieFile']['mediaInfo']['videoCodecLibrary'], movie['movieFile']['mediaInfo']['audioFormat'])) else: @@ -116,8 +120,7 @@ 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['moviefile']['quality']['quality']['resolution'], + movie['year'], alternativeTitles, format, resolution, movie['moviefile']['mediaInfo']['videoCodecLibrary'], movie['moviefile']['mediaInfo']['audioFormat'])) else: @@ -130,18 +133,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 = ?, 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 = ? 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, 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) 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, 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) 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 e8a49b6f4..f2e31a1e3 100644 --- a/bazarr/get_subtitle.py +++ b/bazarr/get_subtitle.py @@ -697,13 +697,15 @@ def refine_from_db(path, video): 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.format: + video.format = str(data[7]) if not video.resolution: - if data[7] in ('480','720','1080'): video.resolution = str(data[7]) + 'p' + video.resolution = str(data[8]) if not video.video_codec: - if data[8] == 'x264': video.video_codec = 'h264' - elif data[8]: video.video_codec = data[8] + if data[9] == 'x264': video.video_codec = 'h264' + elif data[9]: video.video_codec = data[9] if not video.audio_codec: - if data[9]: video.audio_codec = data[9] + if data[10]: video.audio_codec = data[10] elif isinstance(video, Movie): db = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30) c = db.cursor() @@ -713,11 +715,13 @@ def refine_from_db(path, video): video.title = re.sub(r'(\(\d\d\d\d\))' , '', data[0]) if int(data[1]) > 0: video.year = int(data[1]) video.alternative_titles = ast.literal_eval(data[2]) + if not video.format: + if data[3]: video.format = data[3] if not video.resolution: - if data[3]: video.resolution = data[3].lstrip('r').lower() + if data[4]: video.resolution = data[4] if not video.video_codec: - if data[4]: video.video_codec = data[4] + if data[5]: video.video_codec = data[5] if not video.audio_codec: - if data[5]: video.audio_codec = data[5] + if data[6]: video.audio_codec = data[6] return video diff --git a/bazarr/update_db.py b/bazarr/update_db.py index e00f853ca..e525f3968 100644 --- a/bazarr/update_db.py +++ b/bazarr/update_db.py @@ -100,12 +100,14 @@ 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 "format" "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 "format" "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"')