diff --git a/.gitignore b/.gitignore index 0d20b6487..2a7da2d1c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ *.pyc +bazarr.db +cachefile.dbm diff --git a/bazarr.db b/bazarr.db index 3763b5dd9..97f40554a 100644 Binary files a/bazarr.db and b/bazarr.db differ diff --git a/bazarr.py b/bazarr.py index e666e5037..8b078261b 100644 --- a/bazarr.py +++ b/bazarr.py @@ -17,6 +17,7 @@ from get_languages import * from get_general_settings import * from get_sonarr_settings import * from list_subtitles import * +from get_subtitle import * @route('/static/:path#.+#', name='static') def static(path): @@ -24,7 +25,6 @@ def static(path): @route('/image_proxy/', method='GET') def image_proxy(url): - print url_sonarr_short + url img_pil = Image.open(BytesIO(requests.get(url_sonarr_short + '/' + url).content)) img_buffer = BytesIO() img_pil.tobytes() @@ -78,7 +78,7 @@ def episodes(no): c = conn.cursor() series_details = [] - series_details = c.execute("SELECT title, overview, poster, fanart FROM table_shows WHERE sonarrSeriesId LIKE ?", (str(no),)).fetchone() + series_details = c.execute("SELECT title, overview, poster, fanart, hearing_impaired FROM table_shows WHERE sonarrSeriesId LIKE ?", (str(no),)).fetchone() sqlite3.enable_callback_tracebacks(True) episodes = c.execute("SELECT title, path_substitution(path), season, episode, subtitles, sonarrSeriesId, missing_subtitles(path) FROM table_episodes WHERE sonarrSeriesId LIKE ?", (str(no),)).fetchall() @@ -133,22 +133,23 @@ def remove_subtitles(): try: os.remove(subtitlesPath) - store_subtitles(episodePath) - redirect('/episodes/' + sonarrSeriesId) except OSError: - redirect('/episodes/' + sonarrSeriesId + '?error=1') + pass + store_subtitles(episodePath) + redirect('/episodes/' + sonarrSeriesId) -@route('/remove_subtitles', method='GET') -def remove_subtitles(): +@route('/get_subtitle', method='GET') +def get_subtitle(): episodePath = request.GET.episodePath - subtitlesPath = request.GET.subtitlesPath + language = request.GET.language + hi = request.GET.hi sonarrSeriesId = request.GET.sonarrSeriesId - + try: - os.remove(subtitlesPath) + download_subtitle(episodePath, language, hi, None) store_subtitles(episodePath) redirect('/episodes/' + sonarrSeriesId) except OSError: - redirect('/episodes/' + sonarrSeriesId + '?error=1') + redirect('/episodes/' + sonarrSeriesId + '?error=2') run(host=ip, port=port) diff --git a/get_subtitle.py b/get_subtitle.py new file mode 100644 index 000000000..f90160f43 --- /dev/null +++ b/get_subtitle.py @@ -0,0 +1,15 @@ +import os +from babelfish import * +from subliminal import * + +# configure the cache +region.configure('dogpile.cache.dbm', arguments={'filename': 'cachefile.dbm'}) + +def download_subtitle(path, language, hi, providers): + video = scan_video(path) + best_subtitles = download_best_subtitles([video], {Language(language)}, providers=providers, hearing_impaired=hi) + best_subtitle = best_subtitles[video][0] + + return save_subtitles(video, [best_subtitle]) + +#download_subtitle('Z:\Series TV\Vikings\Season 03\Vikings.S03E03.720p.HDTV.x264-KILLERS.mkv', 'fra', False, None) diff --git a/views/episodes.tpl b/views/episodes.tpl index 600abfb4c..e1611de5f 100644 --- a/views/episodes.tpl +++ b/views/episodes.tpl @@ -75,6 +75,8 @@ %import ast + %import pycountry + %from get_general_settings import *
Loading...
@@ -144,7 +146,6 @@ Title Existing subtitles Missing subtitles - @@ -156,17 +157,16 @@ %actual_languages = ast.literal_eval(episode[4]) %if actual_languages is not None: %for language in actual_languages: - - %if language[1] is not None: - - {{language[0]}} - - - %else: -
- {{language[0]}} -
- %end + %if language[1] is not None: + + {{language[0]}} + + + %else: +
+ {{language[0]}} +
+ %end %end %end @@ -174,19 +174,13 @@ %missing_languages = ast.literal_eval(episode[6]) %if missing_languages is not None: %for language in missing_languages: - + + %end %end - - %if len(missing_languages) > 0: -
- -
- %end - %end