mirror of
https://github.com/morpheus65535/bazarr
synced 2025-01-03 05:25:28 +00:00
Continuing development
This commit is contained in:
parent
184d2b47e9
commit
2edd6a328d
5 changed files with 37 additions and 52 deletions
17
bazarr.py
17
bazarr.py
|
@ -7,6 +7,7 @@ import sqlite3
|
||||||
import itertools
|
import itertools
|
||||||
import operator
|
import operator
|
||||||
import requests
|
import requests
|
||||||
|
import pycountry
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from fdsend import send_file
|
from fdsend import send_file
|
||||||
|
@ -18,6 +19,7 @@ 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 *
|
from get_subtitle import *
|
||||||
|
from utils import *
|
||||||
|
|
||||||
@route('/static/:path#.+#', name='static')
|
@route('/static/:path#.+#', name='static')
|
||||||
def static(path):
|
def static(path):
|
||||||
|
@ -81,8 +83,8 @@ def episodes(no):
|
||||||
series_details = c.execute("SELECT title, overview, poster, fanart, hearing_impaired 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), sonarrEpisodeId FROM table_episodes WHERE sonarrSeriesId LIKE ?", (str(no),)).fetchall()
|
||||||
episodes=reversed(sorted(episodes, key=operator.itemgetter(2)))
|
episodes = reversed(sorted(episodes, key=operator.itemgetter(2)))
|
||||||
seasons_list = []
|
seasons_list = []
|
||||||
for key,season in itertools.groupby(episodes,operator.itemgetter(2)):
|
for key,season in itertools.groupby(episodes,operator.itemgetter(2)):
|
||||||
seasons_list.append(list(season))
|
seasons_list.append(list(season))
|
||||||
|
@ -94,8 +96,9 @@ def episodes(no):
|
||||||
def history():
|
def history():
|
||||||
db = sqlite3.connect('bazarr.db')
|
db = sqlite3.connect('bazarr.db')
|
||||||
c = db.cursor()
|
c = db.cursor()
|
||||||
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 LIMIT 15")
|
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")
|
||||||
data = c.fetchall()
|
data = c.fetchall()
|
||||||
|
data = reversed(sorted(data, key=operator.itemgetter(4)))
|
||||||
c.close()
|
c.close()
|
||||||
return template('history', rows=data)
|
return template('history', rows=data)
|
||||||
|
|
||||||
|
@ -128,11 +131,15 @@ def system():
|
||||||
@route('/remove_subtitles', method='GET')
|
@route('/remove_subtitles', method='GET')
|
||||||
def remove_subtitles():
|
def remove_subtitles():
|
||||||
episodePath = request.GET.episodePath
|
episodePath = request.GET.episodePath
|
||||||
|
language = request.GET.language
|
||||||
subtitlesPath = request.GET.subtitlesPath
|
subtitlesPath = request.GET.subtitlesPath
|
||||||
sonarrSeriesId = request.GET.sonarrSeriesId
|
sonarrSeriesId = request.GET.sonarrSeriesId
|
||||||
|
sonarrEpisodeId = request.GET.sonarrEpisodeId
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os.remove(subtitlesPath)
|
os.remove(subtitlesPath)
|
||||||
|
result = pycountry.languages.lookup(language).name + " subtitles deleted from disk."
|
||||||
|
history_log(0, sonarrSeriesId, sonarrEpisodeId, result)
|
||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
store_subtitles(episodePath)
|
store_subtitles(episodePath)
|
||||||
|
@ -144,9 +151,11 @@ def get_subtitle():
|
||||||
language = request.GET.language
|
language = request.GET.language
|
||||||
hi = request.GET.hi
|
hi = request.GET.hi
|
||||||
sonarrSeriesId = request.GET.sonarrSeriesId
|
sonarrSeriesId = request.GET.sonarrSeriesId
|
||||||
|
sonarrEpisodeId = request.GET.sonarrEpisodeId
|
||||||
|
|
||||||
try:
|
try:
|
||||||
download_subtitle(episodePath, language, hi, None)
|
result = download_subtitle(episodePath, language, hi, None)
|
||||||
|
history_log(1, sonarrSeriesId, sonarrEpisodeId, result)
|
||||||
store_subtitles(episodePath)
|
store_subtitles(episodePath)
|
||||||
redirect('/episodes/' + sonarrSeriesId)
|
redirect('/episodes/' + sonarrSeriesId)
|
||||||
except OSError:
|
except OSError:
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import os
|
import os
|
||||||
from babelfish import *
|
from babelfish import *
|
||||||
from subliminal import *
|
from subliminal import *
|
||||||
|
from pycountry import *
|
||||||
|
|
||||||
# configure the cache
|
# configure the cache
|
||||||
region.configure('dogpile.cache.dbm', arguments={'filename': 'cachefile.dbm'})
|
region.configure('dogpile.cache.dbm', arguments={'filename': 'cachefile.dbm'})
|
||||||
|
@ -10,6 +11,9 @@ def download_subtitle(path, language, hi, providers):
|
||||||
best_subtitles = download_best_subtitles([video], {Language(language)}, providers=providers, hearing_impaired=hi)
|
best_subtitles = download_best_subtitles([video], {Language(language)}, providers=providers, hearing_impaired=hi)
|
||||||
best_subtitle = best_subtitles[video][0]
|
best_subtitle = best_subtitles[video][0]
|
||||||
|
|
||||||
return save_subtitles(video, [best_subtitle])
|
result = save_subtitles(video, [best_subtitle])
|
||||||
|
downloaded_provider = str(result[0]).strip('<>').split(' ')[0][:-8]
|
||||||
|
downloaded_language = pycountry.languages.lookup(str(str(result[0]).strip('<>').split(' ')[2].strip('[]'))).name
|
||||||
|
message = downloaded_language + " subtitles downloaded from " + downloaded_provider + "."
|
||||||
|
|
||||||
#download_subtitle('Z:\Series TV\Vikings\Season 03\Vikings.S03E03.720p.HDTV.x264-KILLERS.mkv', 'fra', False, None)
|
return message
|
||||||
|
|
54
utils.py
54
utils.py
|
@ -1,44 +1,16 @@
|
||||||
import datetime
|
import sqlite3
|
||||||
|
import time
|
||||||
|
|
||||||
def pretty_date(time=False):
|
def history_log(action, sonarrSeriesId, sonarrEpisodeId, description):
|
||||||
"""
|
# Open database connection
|
||||||
Get a datetime object or a int() Epoch timestamp and return a
|
db = sqlite3.connect('bazarr.db')
|
||||||
pretty string like 'an hour ago', 'Yesterday', '3 months ago',
|
c = db.cursor()
|
||||||
'just now', etc
|
|
||||||
"""
|
|
||||||
from datetime import datetime
|
|
||||||
now = datetime.now()
|
|
||||||
if type(time) is int:
|
|
||||||
diff = now - datetime.fromtimestamp(time)
|
|
||||||
elif isinstance(time,datetime):
|
|
||||||
diff = now - time
|
|
||||||
elif not time:
|
|
||||||
diff = now - now
|
|
||||||
second_diff = diff.seconds
|
|
||||||
day_diff = diff.days
|
|
||||||
|
|
||||||
if day_diff < 0:
|
# Get Sonarr API URL from database config table
|
||||||
return ''
|
history = c.execute('''INSERT INTO table_history(action, sonarrSeriesId, sonarrEpisodeId, timestamp, description) VALUES (?, ?, ?, ?, ?)''', (action, sonarrSeriesId, sonarrEpisodeId, time.time(), description))
|
||||||
|
|
||||||
if day_diff == 0:
|
# Commit changes to DB
|
||||||
if second_diff < 10:
|
db.commit()
|
||||||
return "just now"
|
|
||||||
if second_diff < 60:
|
# Close database connection
|
||||||
return str(second_diff) + " seconds ago"
|
db.close()
|
||||||
if second_diff < 120:
|
|
||||||
return "a minute ago"
|
|
||||||
if second_diff < 3600:
|
|
||||||
return str(second_diff / 60) + " minutes ago"
|
|
||||||
if second_diff < 7200:
|
|
||||||
return "an hour ago"
|
|
||||||
if second_diff < 86400:
|
|
||||||
return str(second_diff / 3600) + " hours ago"
|
|
||||||
if day_diff == 1:
|
|
||||||
return "Yesterday"
|
|
||||||
if day_diff < 7:
|
|
||||||
return str(day_diff) + " days ago"
|
|
||||||
if day_diff < 31:
|
|
||||||
return str(day_diff / 7) + " weeks ago"
|
|
||||||
if day_diff < 365:
|
|
||||||
return str(day_diff / 30) + " months ago"
|
|
||||||
return str(day_diff / 365) + " years ago"
|
|
||||||
|
|
|
@ -158,7 +158,7 @@
|
||||||
%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={{path_replace(language[1])}}&language={{pycountry.languages.lookup(str(language[0])).alpha_3}}&sonarrSeriesId={{episode[5]}}&sonarrEpisodeId={{episode[7]}}" class="ui tiny label">
|
||||||
{{language[0]}}
|
{{language[0]}}
|
||||||
<i class="delete icon"></i>
|
<i class="delete icon"></i>
|
||||||
</a>
|
</a>
|
||||||
|
@ -174,9 +174,9 @@
|
||||||
%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:
|
||||||
<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">
|
<a href="/get_subtitle?episodePath={{episode[1]}}&language={{pycountry.languages.lookup(str(language)).alpha_3}}&hi={{details[4]}}&sonarrSeriesId={{episode[5]}}&sonarrEpisodeId={{episode[7]}}" class="ui tiny label">
|
||||||
{{language}}
|
{{language}}
|
||||||
<i class="search icon"></i>
|
<i style="margin-left:3px; margin-right:0px" class="search icon"></i>
|
||||||
</a>
|
</a>
|
||||||
%end
|
%end
|
||||||
%end
|
%end
|
||||||
|
|
|
@ -82,7 +82,7 @@
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
%import time
|
%import time
|
||||||
%from utils import *
|
%import pretty
|
||||||
%for row in rows:
|
%for row in rows:
|
||||||
<tr class="selectable">
|
<tr class="selectable">
|
||||||
<td class="collapsing">
|
<td class="collapsing">
|
||||||
|
@ -104,7 +104,7 @@
|
||||||
<td>{{row[3]}}</td>
|
<td>{{row[3]}}</td>
|
||||||
<td class="collapsing">
|
<td class="collapsing">
|
||||||
<div class="ui inverted" data-tooltip="{{time.strftime('%A, %B %d %Y %H:%M', time.localtime(row[4]))}}" data-inverted="">
|
<div class="ui inverted" data-tooltip="{{time.strftime('%A, %B %d %Y %H:%M', time.localtime(row[4]))}}" data-inverted="">
|
||||||
{{pretty_date(row[4])}}
|
{{pretty.date(int(row[4]))}}
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td>{{row[5]}}</td>
|
<td>{{row[5]}}</td>
|
||||||
|
|
Loading…
Reference in a new issue