Continuing development

pull/26/head
Louis Vézina 7 years ago
parent 184d2b47e9
commit 2edd6a328d

@ -7,6 +7,7 @@ import sqlite3
import itertools
import operator
import requests
import pycountry
from PIL import Image
from io import BytesIO
from fdsend import send_file
@ -18,6 +19,7 @@ from get_general_settings import *
from get_sonarr_settings import *
from list_subtitles import *
from get_subtitle import *
from utils import *
@route('/static/:path#.+#', name='static')
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()
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=reversed(sorted(episodes, key=operator.itemgetter(2)))
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)))
seasons_list = []
for key,season in itertools.groupby(episodes,operator.itemgetter(2)):
seasons_list.append(list(season))
@ -94,8 +96,9 @@ def episodes(no):
def history():
db = sqlite3.connect('bazarr.db')
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 = reversed(sorted(data, key=operator.itemgetter(4)))
c.close()
return template('history', rows=data)
@ -128,11 +131,15 @@ def system():
@route('/remove_subtitles', method='GET')
def remove_subtitles():
episodePath = request.GET.episodePath
language = request.GET.language
subtitlesPath = request.GET.subtitlesPath
sonarrSeriesId = request.GET.sonarrSeriesId
sonarrEpisodeId = request.GET.sonarrEpisodeId
try:
os.remove(subtitlesPath)
result = pycountry.languages.lookup(language).name + " subtitles deleted from disk."
history_log(0, sonarrSeriesId, sonarrEpisodeId, result)
except OSError:
pass
store_subtitles(episodePath)
@ -144,9 +151,11 @@ def get_subtitle():
language = request.GET.language
hi = request.GET.hi
sonarrSeriesId = request.GET.sonarrSeriesId
sonarrEpisodeId = request.GET.sonarrEpisodeId
try:
download_subtitle(episodePath, language, hi, None)
result = download_subtitle(episodePath, language, hi, None)
history_log(1, sonarrSeriesId, sonarrEpisodeId, result)
store_subtitles(episodePath)
redirect('/episodes/' + sonarrSeriesId)
except OSError:

@ -1,6 +1,7 @@
import os
from babelfish import *
from subliminal import *
from pycountry import *
# configure the cache
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_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

@ -1,44 +1,16 @@
import datetime
import sqlite3
import time
def pretty_date(time=False):
"""
Get a datetime object or a int() Epoch timestamp and return a
pretty string like 'an hour ago', 'Yesterday', '3 months ago',
'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
def history_log(action, sonarrSeriesId, sonarrEpisodeId, description):
# Open database connection
db = sqlite3.connect('bazarr.db')
c = db.cursor()
if day_diff < 0:
return ''
# Get Sonarr API URL from database config table
history = c.execute('''INSERT INTO table_history(action, sonarrSeriesId, sonarrEpisodeId, timestamp, description) VALUES (?, ?, ?, ?, ?)''', (action, sonarrSeriesId, sonarrEpisodeId, time.time(), description))
if day_diff == 0:
if second_diff < 10:
return "just now"
if second_diff < 60:
return str(second_diff) + " seconds ago"
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"
# Commit changes to DB
db.commit()
# Close database connection
db.close()

@ -158,7 +158,7 @@
%if actual_languages is not None:
%for language in actual_languages:
%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]}}
<i class="delete icon"></i>
</a>
@ -174,9 +174,9 @@
%missing_languages = ast.literal_eval(episode[6])
%if missing_languages is not None:
%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}}
<i class="search icon"></i>
<i style="margin-left:3px; margin-right:0px" class="search icon"></i>
</a>
%end
%end

@ -82,7 +82,7 @@
</thead>
<tbody>
%import time
%from utils import *
%import pretty
%for row in rows:
<tr class="selectable">
<td class="collapsing">
@ -104,7 +104,7 @@
<td>{{row[3]}}</td>
<td class="collapsing">
<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>
</td>
<td>{{row[5]}}</td>

Loading…
Cancel
Save