Continuing development

This commit is contained in:
Louis Vézina 2019-02-05 22:49:58 -05:00
parent 1d9dec6b20
commit 8e5f30e53a
4 changed files with 51 additions and 16 deletions

View File

@ -83,12 +83,18 @@ def sync_episodes():
episodes_to_update.append((episode['title'], episode['episodeFile']['path'], episodes_to_update.append((episode['title'], episode['episodeFile']['path'],
episode['seasonNumber'], episode['episodeNumber'], episode['seasonNumber'], episode['episodeNumber'],
sceneName, str(bool(episode['monitored'])), sceneName, str(bool(episode['monitored'])),
episode['episodeFile']['quality']['quality']['resolution'],
episode['episodeFile']['mediaInfo']['videoCodec'],
episode['episodeFile']['mediaInfo']['audioCodec'],
episode['id'])) episode['id']))
else: else:
episodes_to_add.append((episode['seriesId'], episode['id'], episode['title'], episodes_to_add.append((episode['seriesId'], episode['id'], episode['title'],
episode['episodeFile']['path'], episode['seasonNumber'], episode['episodeFile']['path'], episode['seasonNumber'],
episode['episodeNumber'], sceneName, 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)) removed_episodes = list(set(current_episodes_db_list) - set(current_episodes_sonarr))
@ -97,12 +103,12 @@ def sync_episodes():
c = db.cursor() c = db.cursor()
updated_result = c.executemany( 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) episodes_to_update)
db.commit() db.commit()
added_result = c.executemany( 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) episodes_to_add)
db.commit() db.commit()

View File

@ -76,7 +76,7 @@ def update_movies():
if movie['alternativeTitles'] != None: if movie['alternativeTitles'] != None:
alternativeTitles = str([item['title'] for item in movie['alternativeTitles']]) alternativeTitles = str([item['title'] for item in movie['alternativeTitles']])
# Add movies in radarr to current movies list # Add movies in radarr to current movies list
current_movies_radarr.append(unicode(movie['tmdbId'])) current_movies_radarr.append(unicode(movie['tmdbId']))
@ -92,7 +92,11 @@ def update_movies():
movie["tmdbId"], movie["id"], overview, poster, fanart, movie["tmdbId"], movie["id"], overview, poster, fanart,
profile_id_to_language(movie['qualityProfileId']), sceneName, profile_id_to_language(movie['qualityProfileId']), sceneName,
unicode(bool(movie['monitored'])), movie['sortTitle'], 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: else:
if movie_default_enabled is True: if movie_default_enabled is True:
movies_to_add.append((movie["title"], movies_to_add.append((movie["title"],
@ -101,7 +105,10 @@ def update_movies():
movie["id"], overview, poster, fanart, movie["id"], overview, poster, fanart,
profile_id_to_language(movie['qualityProfileId']), sceneName, profile_id_to_language(movie['qualityProfileId']), sceneName,
unicode(bool(movie['monitored'])), movie['sortTitle'], 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: else:
movies_to_add.append((movie["title"], movies_to_add.append((movie["title"],
movie["path"] + separator + movie['movieFile'][ movie["path"] + separator + movie['movieFile'][
@ -109,7 +116,10 @@ def update_movies():
movie["tmdbId"], movie["id"], overview, poster, fanart, movie["tmdbId"], movie["id"], overview, poster, fanart,
profile_id_to_language(movie['qualityProfileId']), sceneName, profile_id_to_language(movie['qualityProfileId']), sceneName,
unicode(bool(movie['monitored'])), movie['sortTitle'], 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: else:
logging.error( logging.error(
'BAZARR Radarr returned a movie without a file path: ' + movie["path"] + separator + 'BAZARR Radarr returned a movie without a file path: ' + movie["path"] + separator +
@ -120,18 +130,18 @@ def update_movies():
c = db.cursor() c = db.cursor()
updated_result = c.executemany( 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) movies_to_update)
db.commit() db.commit()
if movie_default_enabled is True: if movie_default_enabled is True:
added_result = c.executemany( 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) movies_to_add)
db.commit() db.commit()
else: else:
added_result = c.executemany( 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) movies_to_add)
db.commit() db.commit()

View File

@ -687,26 +687,37 @@ def refine_from_db(path, video):
if isinstance(video, Episode): if isinstance(video, Episode):
db = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30) db = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30)
c = db.cursor() 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() db.close()
if data != None: if data != None:
video.series = re.sub(r'(\(\d\d\d\d\))' , '', data[0]) video.series = re.sub(r'(\(\d\d\d\d\))' , '', data[0])
video.season = int(data[1]) video.season = int(data[1])
video.episode = int(data[2]) video.episode = int(data[2])
video.title = data[3] video.title = data[3]
if int(data[4]) > 0: if int(data[4]) > 0: video.year = int(data[4])
video.year = int(data[4])
video.series_tvdb_id = int(data[5]) video.series_tvdb_id = int(data[5])
video.alternative_series = ast.literal_eval(data[6]) 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): elif isinstance(video, Movie):
db = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30) db = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30)
c = db.cursor() 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() db.close()
if data != None: if data != None:
video.title = re.sub(r'(\(\d\d\d\d\))' , '', data[0]) video.title = re.sub(r'(\(\d\d\d\d\))' , '', data[0])
if int(data[1]) > 0: if int(data[1]) > 0: video.year = int(data[1])
video.year = int(data[1])
video.alternative_titles = ast.literal_eval(data[2]) 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 return video

View File

@ -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 "year" "text"')
c.execute('alter table table_shows add column "alternateTitles" "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 "year" "text"')
c.execute('alter table table_movies add column "alternativeTitles" "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() db.commit()
except: except:
pass pass
else: else:
if settings.general.getboolean('use_sonarr'): if settings.general.getboolean('use_sonarr'):
execute_now('update_series') execute_now('update_series')
execute_now('sync_episodes')
if settings.general.getboolean('use_radarr'): if settings.general.getboolean('use_radarr'):
execute_now('update_movies') execute_now('update_movies')