diff --git a/bazarr/get_movies.py b/bazarr/get_movies.py index f6890cceb..8206caa65 100644 --- a/bazarr/get_movies.py +++ b/bazarr/get_movies.py @@ -73,6 +73,9 @@ def update_movies(): sceneName = movie['movieFile']['sceneName'] else: sceneName = None + + 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'])) @@ -89,22 +92,24 @@ def update_movies(): movie["tmdbId"], movie["id"], overview, poster, fanart, profile_id_to_language(movie['qualityProfileId']), sceneName, unicode(bool(movie['monitored'])), movie['sortTitle'], - movie["tmdbId"])) + movie['year'], alternativeTitles, movie["tmdbId"])) else: if movie_default_enabled is True: movies_to_add.append((movie["title"], - movie["path"] + separator + movie['movieFile'][ - 'relativePath'], movie["tmdbId"], movie_default_language, - '[]', movie_default_hi, movie["id"], overview, poster, fanart, + movie["path"] + separator + movie['movieFile']['relativePath'], + movie["tmdbId"], movie_default_language, '[]', movie_default_hi, + movie["id"], overview, poster, fanart, profile_id_to_language(movie['qualityProfileId']), sceneName, - unicode(bool(movie['monitored'])), movie['sortTitle'])) + unicode(bool(movie['monitored'])), movie['sortTitle'], + movie['year'], alternativeTitles)) else: movies_to_add.append((movie["title"], movie["path"] + separator + movie['movieFile'][ 'relativePath'], movie["tmdbId"], movie["tmdbId"], movie["tmdbId"], movie["id"], overview, poster, fanart, profile_id_to_language(movie['qualityProfileId']), sceneName, - unicode(bool(movie['monitored'])), movie['sortTitle'])) + unicode(bool(movie['monitored'])), movie['sortTitle'], + movie['year'], alternativeTitles)) else: logging.error( 'BAZARR Radarr returned a movie without a file path: ' + movie["path"] + separator + @@ -115,18 +120,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= ? WHERE tmdbid = ?''', + '''UPDATE table_movies SET title = ?, path = ?, tmdbId = ?, radarrId = ?, overview = ?, poster = ?, fanart = ?, `audio_language` = ?, sceneName = ?, monitored = ?, sortTitle = ?, year = ?, alternativeTitles = ? 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) 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) 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) 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) 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_series.py b/bazarr/get_series.py index f00f87294..960cb8c57 100644 --- a/bazarr/get_series.py +++ b/bazarr/get_series.py @@ -68,7 +68,10 @@ def update_series(): fanart = show['images'][0]['url'].split('?')[0] except: fanart = "" - + + if show['alternateTitles'] != None: + alternateTitles = str([item['title'] for item in show['alternateTitles']]) + # Add shows in Sonarr to current shows list current_shows_sonarr.append(show['tvdbId']) @@ -76,34 +79,36 @@ def update_series(): series_to_update.append((show["title"], show["path"], show["tvdbId"], show["id"], overview, poster, fanart, profile_id_to_language( (show['qualityProfileId'] if sonarr_version == 2 else show['languageProfileId'])), - show['sortTitle'], show["tvdbId"])) + show['sortTitle'], show['year'], alternateTitles, show["tvdbId"])) else: if serie_default_enabled is True: series_to_add.append((show["title"], show["path"], show["tvdbId"], serie_default_language, serie_default_hi, show["id"], overview, poster, fanart, - profile_id_to_language(show['qualityProfileId']), show['sortTitle'])) + profile_id_to_language(show['qualityProfileId']), show['sortTitle'], + show['year'], alternateTitles)) else: series_to_add.append((show["title"], show["path"], show["tvdbId"], show["tvdbId"], show["tvdbId"], show["id"], overview, poster, fanart, - profile_id_to_language(show['qualityProfileId']), show['sortTitle'])) + profile_id_to_language(show['qualityProfileId']), show['sortTitle'], + show['year'], alternateTitles)) # Update or insert series in DB db = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30) c = db.cursor() updated_result = c.executemany( - '''UPDATE table_shows SET title = ?, path = ?, tvdbId = ?, sonarrSeriesId = ?, overview = ?, poster = ?, fanart = ?, `audio_language` = ? , sortTitle = ? WHERE tvdbid = ?''', + '''UPDATE table_shows SET title = ?, path = ?, tvdbId = ?, sonarrSeriesId = ?, overview = ?, poster = ?, fanart = ?, `audio_language` = ? , sortTitle = ?, year = ?, alternateTitles = ? WHERE tvdbid = ?''', series_to_update) db.commit() if serie_default_enabled is True: added_result = c.executemany( - '''INSERT OR IGNORE INTO table_shows(title, path, tvdbId, languages,`hearing_impaired`, sonarrSeriesId, overview, poster, fanart, `audio_language`, sortTitle) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)''', + '''INSERT OR IGNORE INTO table_shows(title, path, tvdbId, languages,`hearing_impaired`, sonarrSeriesId, overview, poster, fanart, `audio_language`, sortTitle, year, alternateTitles) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)''', series_to_add) db.commit() else: added_result = c.executemany( - '''INSERT OR IGNORE INTO table_shows(title, path, tvdbId, languages,`hearing_impaired`, sonarrSeriesId, overview, poster, fanart, `audio_language`, sortTitle) VALUES (?,?,?,(SELECT languages FROM table_shows WHERE tvdbId = ?),(SELECT `hearing_impaired` FROM table_shows WHERE tvdbId = ?), ?, ?, ?, ?, ?, ?)''', + '''INSERT OR IGNORE INTO table_shows(title, path, tvdbId, languages,`hearing_impaired`, sonarrSeriesId, overview, poster, fanart, `audio_language`, sortTitle, year, alternateTitles) VALUES (?,?,?,(SELECT languages FROM table_shows WHERE tvdbId = ?),(SELECT `hearing_impaired` FROM table_shows WHERE tvdbId = ?), ?, ?, ?, ?, ?, ?, ?, ?)''', series_to_add) db.commit() db.close() diff --git a/bazarr/get_subtitle.py b/bazarr/get_subtitle.py index c45d001c0..ebc523067 100644 --- a/bazarr/get_subtitle.py +++ b/bazarr/get_subtitle.py @@ -13,11 +13,12 @@ import types import chardet import subliminal import subliminal_patch +from ast import literal_eval from datetime import datetime, timedelta from subzero.language import Language -from subzero.video import parse_video, refine_video +from subzero.video import parse_video from subliminal import region, score as subliminal_scores, \ - list_subtitles + list_subtitles, Episode, Movie from subliminal_patch.core import SZAsyncProviderPool, download_best_subtitles, save_subtitles, download_subtitles from subliminal_patch.score import compute_score from get_languages import language_from_alpha3, alpha2_from_alpha3, alpha3_from_alpha2, language_from_alpha2 @@ -63,11 +64,7 @@ def get_video(path, title, sceneName, use_scenename, providers=None, media_type= video.used_scene_name = dont_use_actual_file video.original_name = original_name video.original_path = original_path - try: - refine_video(video) - except Exception as e: - logging.debug('BAZARR Error trying to refine this file: ' + path) - pass + refine_from_db(original_path, video) return video except: @@ -120,7 +117,7 @@ def force_unicode(s): def download_subtitle(path, language, hi, providers, providers_auth, sceneName, title, media_type): # fixme: supply all missing languages, not only one, to hit providers only once who support multiple languages in # one query - + logging.debug('BAZARR Searching subtitles for this file: ' + path) if hi == "True": hi = True @@ -322,7 +319,7 @@ def download_subtitle(path, language, hi, providers, providers_auth, sceneName, def manual_search(path, language, hi, providers, providers_auth, sceneName, title, media_type): logging.debug('BAZARR Manually searching subtitles for this file: ' + path) - + final_subtitles = [] if hi == "True": @@ -683,3 +680,32 @@ def search_active(timestamp): return False else: return True + + +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() + db.close() + if data != None: + video.series = 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]) + video.series_tvdb_id = int(data[5]) + video.alternative_series = ast.literal_eval(data[6]) + 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() + db.close() + if data != None: + video.title = data[0] + if int(data[1]) > 0: + video.year = int(data[1]) + video.alternative_titles = ast.literal_eval(data[2]) + + return video diff --git a/bazarr/update_db.py b/bazarr/update_db.py index fab931320..1b0a1e568 100644 --- a/bazarr/update_db.py +++ b/bazarr/update_db.py @@ -95,5 +95,20 @@ if os.path.exists(os.path.join(args.config_dir, 'db', 'bazarr.db')): else: if settings.general.getboolean('use_radarr'): execute_now('update_movies') + + try: + 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_movies add column "year" "text"') + c.execute('alter table table_movies add column "alternativeTitles" "text"') + db.commit() + except: + pass + else: + if settings.general.getboolean('use_sonarr'): + execute_now('sync_episodes') + if settings.general.getboolean('use_radarr'): + execute_now('update_movies') db.close()