Continuing development

This commit is contained in:
Louis Vézina 2017-09-16 20:11:47 -04:00
parent 122ec09f9a
commit 184d2b47e9
5 changed files with 44 additions and 32 deletions

2
.gitignore vendored
View File

@ -1 +1,3 @@
*.pyc *.pyc
bazarr.db
cachefile.dbm

BIN
bazarr.db

Binary file not shown.

View File

@ -17,6 +17,7 @@ from get_languages import *
from get_general_settings import * from get_general_settings import *
from get_sonarr_settings import * from get_sonarr_settings import *
from list_subtitles import * from list_subtitles import *
from get_subtitle import *
@route('/static/:path#.+#', name='static') @route('/static/:path#.+#', name='static')
def static(path): def static(path):
@ -24,7 +25,6 @@ def static(path):
@route('/image_proxy/<url:path>', method='GET') @route('/image_proxy/<url:path>', method='GET')
def image_proxy(url): def image_proxy(url):
print url_sonarr_short + url
img_pil = Image.open(BytesIO(requests.get(url_sonarr_short + '/' + url).content)) img_pil = Image.open(BytesIO(requests.get(url_sonarr_short + '/' + url).content))
img_buffer = BytesIO() img_buffer = BytesIO()
img_pil.tobytes() img_pil.tobytes()
@ -78,7 +78,7 @@ def episodes(no):
c = conn.cursor() c = conn.cursor()
series_details = [] 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) 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() 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: try:
os.remove(subtitlesPath) os.remove(subtitlesPath)
store_subtitles(episodePath)
redirect('/episodes/' + sonarrSeriesId)
except OSError: except OSError:
redirect('/episodes/' + sonarrSeriesId + '?error=1') pass
store_subtitles(episodePath)
redirect('/episodes/' + sonarrSeriesId)
@route('/remove_subtitles', method='GET') @route('/get_subtitle', method='GET')
def remove_subtitles(): def get_subtitle():
episodePath = request.GET.episodePath episodePath = request.GET.episodePath
subtitlesPath = request.GET.subtitlesPath language = request.GET.language
hi = request.GET.hi
sonarrSeriesId = request.GET.sonarrSeriesId sonarrSeriesId = request.GET.sonarrSeriesId
try: try:
os.remove(subtitlesPath) download_subtitle(episodePath, language, hi, None)
store_subtitles(episodePath) store_subtitles(episodePath)
redirect('/episodes/' + sonarrSeriesId) redirect('/episodes/' + sonarrSeriesId)
except OSError: except OSError:
redirect('/episodes/' + sonarrSeriesId + '?error=1') redirect('/episodes/' + sonarrSeriesId + '?error=2')
run(host=ip, port=port) run(host=ip, port=port)

15
get_subtitle.py Normal file
View File

@ -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)

View File

@ -75,6 +75,8 @@
</head> </head>
<body> <body>
%import ast %import ast
%import pycountry
%from get_general_settings import *
<div style="display: none;"><img src="/image_proxy{{details[3]}}"></div> <div style="display: none;"><img src="/image_proxy{{details[3]}}"></div>
<div id='loader' class="ui page dimmer"> <div id='loader' class="ui page dimmer">
<div class="ui indeterminate text loader">Loading...</div> <div class="ui indeterminate text loader">Loading...</div>
@ -144,7 +146,6 @@
<th>Title</th> <th>Title</th>
<th class="collapsing">Existing subtitles</th> <th class="collapsing">Existing subtitles</th>
<th class="collapsing">Missing subtitles</th> <th class="collapsing">Missing subtitles</th>
<th class="no-sort"></th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -156,17 +157,16 @@
%actual_languages = ast.literal_eval(episode[4]) %actual_languages = ast.literal_eval(episode[4])
%if actual_languages is not None: %if actual_languages is not None:
%for language in actual_languages: %for language in actual_languages:
%if language[1] is not None:
%if language[1] is not None: <a href="/remove_subtitles?episodePath={{episode[1]}}&subtitlesPath={{path_replace(language[1])}}&sonarrSeriesId={{episode[5]}}" class="ui tiny label">
<a href="/remove_subtitles?episodePath={{episode[1]}}&subtitlesPath={{language[1]}}&sonarrSeriesId={{episode[5]}}" class="ui tiny label"> {{language[0]}}
{{language[0]}} <i class="delete icon"></i>
<i class="delete icon"></i> </a>
</a> %else:
%else: <div class="ui tiny label">
<div class="ui tiny label"> {{language[0]}}
{{language[0]}} </div>
</div> %end
%end
%end %end
%end %end
</td> </td>
@ -174,19 +174,13 @@
%missing_languages = ast.literal_eval(episode[6]) %missing_languages = ast.literal_eval(episode[6])
%if missing_languages is not None: %if missing_languages is not None:
%for language in missing_languages: %for language in missing_languages:
<div class="ui tiny label"> <a href="/get_subtitle?episodePath={{episode[1]}}&language={{pycountry.languages.lookup(str(language)).alpha_3}}&hi={{details[4]}}&sonarrSeriesId={{episode[5]}}" class="ui tiny label">
{{language}} {{language}}
</div> <i class="search icon"></i>
</a>
%end %end
%end %end
</td> </td>
<td class="collapsing">
%if len(missing_languages) > 0:
<div class="ui inverted basic compact icon" data-tooltip="Download missing subtitles" data-inverted="" onclick="location.href='/edit_series/{{episode[3]}}';">
<i class="ui black download icon"></i>
</div>
%end
</td>
</tr> </tr>
%end %end
</tbody> </tbody>