diff --git a/bazarr.py b/bazarr.py index 91315935f..14f2ca315 100644 --- a/bazarr.py +++ b/bazarr.py @@ -1,4 +1,4 @@ -bazarr_version = '0.3.3' +bazarr_version = '0.3.5' import os import sys @@ -261,7 +261,7 @@ def episodes(no): series_details = c.execute("SELECT title, overview, poster, fanart, hearing_impaired, tvdbid, audio_language, languages, path_substitution(path) FROM table_shows WHERE sonarrSeriesId LIKE ?", (str(no),)).fetchone() tvdbid = series_details[5] - episodes = c.execute("SELECT title, path_substitution(path), season, episode, subtitles, sonarrSeriesId, missing_subtitles, sonarrEpisodeId FROM table_episodes WHERE sonarrSeriesId LIKE ? ORDER BY episode ASC", (str(no),)).fetchall() + episodes = c.execute("SELECT title, path_substitution(path), season, episode, subtitles, sonarrSeriesId, missing_subtitles, sonarrEpisodeId, scene_name FROM table_episodes WHERE sonarrSeriesId LIKE ? ORDER BY episode ASC", (str(no),)).fetchall() number = len(episodes) languages = c.execute("SELECT code2, name FROM table_settings_languages WHERE enabled = 1").fetchall() c.close() @@ -317,7 +317,7 @@ def history(): thisyear.append(datetime.fromtimestamp(stat[0]).date()) stats = [len(today), len(thisweek), len(thisyear), total] - c.execute("SELECT table_history.action, table_shows.title, table_episodes.season || 'x' || table_episodes.episode, table_episodes.title, table_history.timestamp, table_history.description, table_history.sonarrSeriesId FROM table_history INNER JOIN table_shows on table_shows.sonarrSeriesId = table_history.sonarrSeriesId INNER JOIN table_episodes on table_episodes.sonarrEpisodeId = table_history.sonarrEpisodeId ORDER BY id DESC LIMIT 15 OFFSET ?", (offset,)) + c.execute("SELECT table_history.action, table_shows.title, table_episodes.season || 'x' || table_episodes.episode, table_episodes.title, table_history.timestamp, table_history.description, table_history.sonarrSeriesId FROM table_history LEFT JOIN table_shows on table_shows.sonarrSeriesId = table_history.sonarrSeriesId LEFT JOIN table_episodes on table_episodes.sonarrEpisodeId = table_history.sonarrEpisodeId ORDER BY id DESC LIMIT 15 OFFSET ?", (offset,)) data = c.fetchall() c.close() data = reversed(sorted(data, key=operator.itemgetter(4))) @@ -726,7 +726,7 @@ def remove_subtitles(): history_log(0, sonarrSeriesId, sonarrEpisodeId, result) except OSError: pass - store_subtitles(episodePath) + store_subtitles(unicode(episodePath)) list_missing_subtitles(sonarrSeriesId) @route(base_url + 'get_subtitle', method='POST') @@ -734,6 +734,7 @@ def get_subtitle(): ref = request.environ['HTTP_REFERER'] episodePath = request.forms.get('episodePath') + sceneName = request.forms.get('sceneName') language = request.forms.get('language') hi = request.forms.get('hi') sonarrSeriesId = request.forms.get('sonarrSeriesId') @@ -764,11 +765,11 @@ def get_subtitle(): providers_auth = None try: - result = download_subtitle(episodePath, language, hi, providers_list, providers_auth) + result = download_subtitle(episodePath, language, hi, providers_list, providers_auth, sceneName) if result is not None: history_log(1, sonarrSeriesId, sonarrEpisodeId, result) send_notifications(sonarrSeriesId, sonarrEpisodeId, result) - store_subtitles(episodePath) + store_subtitles(unicode(episodePath)) list_missing_subtitles(sonarrSeriesId) redirect(ref) except OSError: diff --git a/get_episodes.py b/get_episodes.py index 4fb427e9f..9bd946d7a 100644 --- a/get_episodes.py +++ b/get_episodes.py @@ -32,12 +32,15 @@ def update_all_episodes(): if episode['hasFile'] and episode['episodeFile']['size'] > 20480: # Add shows in Sonarr to current shows list current_episodes_sonarr.append(episode['id']) - + if 'sceneName' in episode['episodeFile']: + sceneName = episode['episodeFile']['sceneName'] + else: + sceneName = None try: - c.execute('''INSERT INTO table_episodes(sonarrSeriesId, sonarrEpisodeId, title, path, season, episode) VALUES (?, ?, ?, ?, ?, ?)''', (episode['seriesId'], episode['id'], episode['title'], episode['episodeFile']['path'], episode['seasonNumber'], episode['episodeNumber'])) + c.execute('''INSERT INTO table_episodes(sonarrSeriesId, sonarrEpisodeId, title, path, season, episode, scene_name) VALUES (?, ?, ?, ?, ?, ?, ?)''', (episode['seriesId'], episode['id'], episode['title'], episode['episodeFile']['path'], episode['seasonNumber'], episode['episodeNumber'], sceneName)) db.commit() except sqlite3.Error: - c.execute('''UPDATE table_episodes SET sonarrSeriesId = ?, sonarrEpisodeId = ?, title = ?, path = ?, season = ?, episode = ? WHERE sonarrEpisodeId = ?''', (episode['seriesId'], episode['id'], episode['title'], episode['episodeFile']['path'], episode['seasonNumber'], episode['episodeNumber'], episode['id'])) + c.execute('''UPDATE table_episodes SET sonarrSeriesId = ?, sonarrEpisodeId = ?, title = ?, path = ?, season = ?, episode = ?, scene_name = ? WHERE sonarrEpisodeId = ?''', (episode['seriesId'], episode['id'], episode['title'], episode['episodeFile']['path'], episode['seasonNumber'], episode['episodeNumber'], sceneName, episode['id'])) db.commit() else: continue @@ -93,9 +96,12 @@ def add_new_episodes(): if episode['hasFile'] and episode['episodeFile']['size'] > 20480: # Add shows in Sonarr to current shows list current_episodes_sonarr.append(episode['id']) - + if 'sceneName' in episode['episodeFile']: + sceneName = episode['episodeFile']['sceneName'] + else: + sceneName = None try: - c.execute('''INSERT INTO table_episodes(sonarrSeriesId, sonarrEpisodeId, title, path, season, episode) VALUES (?, ?, ?, ?, ?, ?)''', (episode['seriesId'], episode['id'], episode['title'], episode['episodeFile']['path'], episode['seasonNumber'], episode['episodeNumber'])) + c.execute('''INSERT INTO table_episodes(sonarrSeriesId, sonarrEpisodeId, title, path, season, episode, scene_name) VALUES (?, ?, ?, ?, ?, ?, ?)''', (episode['seriesId'], episode['id'], episode['title'], episode['episodeFile']['path'], episode['seasonNumber'], episode['episodeNumber'], sceneName)) except: pass db.commit() diff --git a/get_subtitle.py b/get_subtitle.py index 418add4a9..ad0516367 100644 --- a/get_subtitle.py +++ b/get_subtitle.py @@ -13,15 +13,19 @@ from notifier import send_notifications # configure the cache region.configure('dogpile.cache.memory') -def download_subtitle(path, language, hi, providers, providers_auth): +def download_subtitle(path, language, hi, providers, providers_auth, sceneName): try: - video = scan_video(path) + if sceneName is None: + video = scan_video(path) + else: + video = Video.fromname(sceneName) except Exception as e: logging.exception('Error trying to extract information from this filename: ' + path) return None else: try: best_subtitles = download_best_subtitles([video], {Language(language)}, providers=providers, hearing_impaired=hi, provider_configs=providers_auth) + except Exception as e: logging.exception('Error trying to best subtitles for this file: ' + path) return None @@ -34,6 +38,8 @@ def download_subtitle(path, language, hi, providers, providers_auth): else: single = get_general_settings()[7] try: + if sceneName is not None: + video = scan_video(path) if single == 'True': result = save_subtitles(video, [best_subtitle], single=True, encoding='utf-8') else: @@ -51,7 +57,7 @@ def download_subtitle(path, language, hi, providers, providers_auth): def series_download_subtitles(no): conn_db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30) c_db = conn_db.cursor() - episodes_details = c_db.execute("SELECT path, missing_subtitles, sonarrEpisodeId FROM table_episodes WHERE sonarrSeriesId = ?", (no,)).fetchall() + episodes_details = c_db.execute("SELECT path, missing_subtitles, sonarrEpisodeId, scene_name FROM table_episodes WHERE sonarrSeriesId = ?", (no,)).fetchall() series_details = c_db.execute("SELECT hearing_impaired FROM table_shows WHERE sonarrSeriesId = ?", (no,)).fetchone() enabled_providers = c_db.execute("SELECT * FROM table_settings_providers WHERE enabled = 1").fetchall() c_db.close() @@ -75,7 +81,7 @@ def series_download_subtitles(no): for episode in episodes_details: for language in ast.literal_eval(episode[1]): - message = download_subtitle(path_replace(episode[0]), str(pycountry.languages.lookup(language).alpha_3), series_details[0], providers_list, providers_auth) + message = download_subtitle(path_replace(episode[0]), str(pycountry.languages.lookup(language).alpha_3), series_details[0], providers_list, providers_auth, episode[3]) if message is not None: store_subtitles(path_replace(episode[0])) history_log(1, no, episode[2], message) @@ -85,7 +91,7 @@ def series_download_subtitles(no): def wanted_download_subtitles(path): conn_db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30) c_db = conn_db.cursor() - episodes_details = c_db.execute("SELECT table_episodes.path, table_episodes.missing_subtitles, table_episodes.sonarrEpisodeId, table_episodes.sonarrSeriesId, table_shows.hearing_impaired FROM table_episodes INNER JOIN table_shows on table_shows.sonarrSeriesId = table_episodes.sonarrSeriesId WHERE table_episodes.path = ? AND missing_subtitles != '[]'", (path_replace_reverse(path),)).fetchall() + episodes_details = c_db.execute("SELECT table_episodes.path, table_episodes.missing_subtitles, table_episodes.sonarrEpisodeId, table_episodes.sonarrSeriesId, table_shows.hearing_impaired, table_episodes.scene_name FROM table_episodes INNER JOIN table_shows on table_shows.sonarrSeriesId = table_episodes.sonarrSeriesId WHERE table_episodes.path = ? AND missing_subtitles != '[]'", (path_replace_reverse(path),)).fetchall() enabled_providers = c_db.execute("SELECT * FROM table_settings_providers WHERE enabled = 1").fetchall() c_db.close() @@ -108,7 +114,7 @@ def wanted_download_subtitles(path): for episode in episodes_details: for language in ast.literal_eval(episode[1]): - message = download_subtitle(path_replace(episode[0]), str(pycountry.languages.lookup(language).alpha_3), episode[4], providers_list, providers_auth) + message = download_subtitle(path_replace(episode[0]), str(pycountry.languages.lookup(language).alpha_3), episode[4], providers_list, providers_auth, episode[5]) if message is not None: store_subtitles(path_replace(episode[0])) list_missing_subtitles(episode[3]) diff --git a/update_db.py b/update_db.py index cb6e85d01..0ab6681d3 100644 --- a/update_db.py +++ b/update_db.py @@ -49,6 +49,15 @@ if os.path.exists(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db')) for provider in providers: c.execute('INSERT INTO `table_settings_notifier` (name, enabled) VALUES (?, ?);', (provider,'0')) + try: + c.execute('alter table table_episodes add column "scene_name" TEXT') + db.commit() + except: + pass + else: + from get_episodes import update_all_episodes + update_all_episodes() + # Commit change to db db.commit() diff --git a/views/episodes.tpl b/views/episodes.tpl index aa3654482..c719f87ba 100644 --- a/views/episodes.tpl +++ b/views/episodes.tpl @@ -183,7 +183,7 @@ %end %if missing_languages is not None: %for language in missing_languages: - + {{language}} diff --git a/views/history.tpl b/views/history.tpl index 245cd3f94..de2435d2d 100644 --- a/views/history.tpl +++ b/views/history.tpl @@ -79,14 +79,24 @@ %end - {{row[1]}} + + {{row[1]}} + - <%episode = row[2].split('x')%> + %if row[2] is not None: + % episode = row[2].split('x') {{episode[0] + 'x' + episode[1].zfill(2)}} + %end + + + %if row[3] is not None: + {{row[3]}} + %else: + Deleted episode + %end - {{row[3]}} -
+
{{pretty.date(int(row[4]))}}