1
0
Fork 0
mirror of https://github.com/morpheus65535/bazarr synced 2024-12-26 01:27:07 +00:00

First implementation of notifications #43

This commit is contained in:
morpheus65535 2018-01-22 23:25:58 -05:00
parent 58e40d3c96
commit 8069302986
6 changed files with 861 additions and 591 deletions

151
bazarr.py
View file

@ -86,6 +86,7 @@ from list_subtitles import *
from get_subtitle import * from get_subtitle import *
from utils import * from utils import *
from scheduler import * from scheduler import *
from notifier import send_notifications
# Reset restart required warning on start # Reset restart required warning on start
conn = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30) conn = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30)
@ -362,8 +363,10 @@ def settings():
settings_providers = c.fetchall() settings_providers = c.fetchall()
c.execute("SELECT * FROM table_settings_sonarr") c.execute("SELECT * FROM table_settings_sonarr")
settings_sonarr = c.fetchone() settings_sonarr = c.fetchone()
c.execute("SELECT * FROM table_settings_notifier")
settings_notifier = c.fetchall()
c.close() c.close()
return template('settings', __file__=__file__, bazarr_version=bazarr_version, settings_general=settings_general, settings_languages=settings_languages, settings_providers=settings_providers, settings_sonarr=settings_sonarr, base_url=base_url) return template('settings', __file__=__file__, bazarr_version=bazarr_version, settings_general=settings_general, settings_languages=settings_languages, settings_providers=settings_providers, settings_sonarr=settings_sonarr, settings_notifier=settings_notifier, base_url=base_url)
@route(base_url + 'save_settings', method='POST') @route(base_url + 'save_settings', method='POST')
def save_settings(): def save_settings():
@ -431,6 +434,151 @@ def save_settings():
for item in settings_subliminal_languages: for item in settings_subliminal_languages:
c.execute("UPDATE table_settings_languages SET enabled = '1' WHERE code2 = ?", (item,)) c.execute("UPDATE table_settings_languages SET enabled = '1' WHERE code2 = ?", (item,))
settings_notifier_Boxcar_enabled = request.forms.get('settings_notifier_Boxcar_enabled')
if settings_notifier_Boxcar_enabled == 'on':
settings_notifier_Boxcar_enabled = 1
else:
settings_notifier_Boxcar_enabled = 0
settings_notifier_Boxcar_url = request.forms.get('settings_notifier_Boxcar_url')
c.execute("UPDATE table_settings_notifier SET enabled = ?, url = ? WHERE name = 'Boxcar'", (settings_notifier_Boxcar_enabled, settings_notifier_Boxcar_url))
settings_notifier_Faast_enabled = request.forms.get('settings_notifier_Faast_enabled')
if settings_notifier_Faast_enabled == 'on':
settings_notifier_Faast_enabled = 1
else:
settings_notifier_Faast_enabled = 0
settings_notifier_Faast_url = request.forms.get('settings_notifier_Faast_url')
c.execute("UPDATE table_settings_notifier SET enabled = ?, url = ? WHERE name = 'Faast'", (settings_notifier_Faast_enabled, settings_notifier_Faast_url))
settings_notifier_Growl_enabled = request.forms.get('settings_notifier_Growl_enabled')
if settings_notifier_Growl_enabled == 'on':
settings_notifier_Growl_enabled = 1
else:
settings_notifier_Growl_enabled = 0
settings_notifier_Growl_url = request.forms.get('settings_notifier_Growl_url')
c.execute("UPDATE table_settings_notifier SET enabled = ?, url = ? WHERE name = 'Growl'", (settings_notifier_Growl_enabled, settings_notifier_Growl_url))
settings_notifier_Join_enabled = request.forms.get('settings_notifier_Join_enabled')
if settings_notifier_Join_enabled == 'on':
settings_notifier_Join_enabled = 1
else:
settings_notifier_Join_enabled = 0
settings_notifier_Join_url = request.forms.get('settings_notifier_Join_url')
c.execute("UPDATE table_settings_notifier SET enabled = ?, url = ? WHERE name = 'Join'", (settings_notifier_Join_enabled, settings_notifier_Join_url))
settings_notifier_KODI_enabled = request.forms.get('settings_notifier_KODI_enabled')
if settings_notifier_KODI_enabled == 'on':
settings_notifier_KODI_enabled = 1
else:
settings_notifier_KODI_enabled = 0
settings_notifier_KODI_url = request.forms.get('settings_notifier_KODI_url')
c.execute("UPDATE table_settings_notifier SET enabled = ?, url = ? WHERE name = 'KODI'", (settings_notifier_KODI_enabled, settings_notifier_KODI_url))
settings_notifier_Mattermost_enabled = request.forms.get('settings_notifier_Mattermost_enabled')
if settings_notifier_Mattermost_enabled == 'on':
settings_notifier_Mattermost_enabled = 1
else:
settings_notifier_Mattermost_enabled = 0
settings_notifier_Mattermost_url = request.forms.get('settings_notifier_Mattermost_url')
c.execute("UPDATE table_settings_notifier SET enabled = ?, url = ? WHERE name = 'Mattermost'", (settings_notifier_Mattermost_enabled, settings_notifier_Mattermost_url))
settings_notifier_NMA_enabled = request.forms.get('settings_notifier_Notify My Android_enabled')
if settings_notifier_NMA_enabled == 'on':
settings_notifier_NMA_enabled = 1
else:
settings_notifier_NMA_enabled = 0
settings_notifier_NMA_url = request.forms.get('settings_notifier_Notify My Android_url')
c.execute("UPDATE table_settings_notifier SET enabled = ?, url = ? WHERE name = 'Notify My Android'", (settings_notifier_NMA_enabled, settings_notifier_NMA_url))
settings_notifier_Prowl_enabled = request.forms.get('settings_notifier_Prowl_enabled')
if settings_notifier_Prowl_enabled == 'on':
settings_notifier_Prowl_enabled = 1
else:
settings_notifier_Prowl_enabled = 0
settings_notifier_Prowl_url = request.forms.get('settings_notifier_Prowl_url')
c.execute("UPDATE table_settings_notifier SET enabled = ?, url = ? WHERE name = 'Prowl'", (settings_notifier_Prowl_enabled, settings_notifier_Prowl_url))
settings_notifier_Pushalot_enabled = request.forms.get('settings_notifier_Pushalot_enabled')
if settings_notifier_Pushalot_enabled == 'on':
settings_notifier_Pushalot_enabled = 1
else:
settings_notifier_Pushalot_enabled = 0
settings_notifier_Pushalot_url = request.forms.get('settings_notifier_Pushalot_url')
c.execute("UPDATE table_settings_notifier SET enabled = ?, url = ? WHERE name = 'Pushalot'", (settings_notifier_Pushalot_enabled, settings_notifier_Pushalot_url))
settings_notifier_PushBullet_enabled = request.forms.get('settings_notifier_PushBullet_enabled')
if settings_notifier_PushBullet_enabled == 'on':
settings_notifier_PushBullet_enabled = 1
else:
settings_notifier_PushBullet_enabled = 0
settings_notifier_PushBullet_url = request.forms.get('settings_notifier_PushBullet_url')
c.execute("UPDATE table_settings_notifier SET enabled = ?, url = ? WHERE name = 'PushBullet'", (settings_notifier_PushBullet_enabled, settings_notifier_PushBullet_url))
settings_notifier_Pushjet_enabled = request.forms.get('settings_notifier_Pushjet_enabled')
if settings_notifier_Pushjet_enabled == 'on':
settings_notifier_Pushjet_enabled = 1
else:
settings_notifier_Pushjet_enabled = 0
settings_notifier_Pushjet_url = request.forms.get('settings_notifier_Pushjet_url')
c.execute("UPDATE table_settings_notifier SET enabled = ?, url = ? WHERE name = 'Pushjet'", (settings_notifier_Pushjet_enabled, settings_notifier_Pushjet_url))
settings_notifier_Pushover_enabled = request.forms.get('settings_notifier_Pushover_enabled')
if settings_notifier_Pushover_enabled == 'on':
settings_notifier_Pushover_enabled = 1
else:
settings_notifier_Pushover_enabled = 0
settings_notifier_Pushover_url = request.forms.get('settings_notifier_Pushover_url')
c.execute("UPDATE table_settings_notifier SET enabled = ?, url = ? WHERE name = 'Pushover'", (settings_notifier_Pushover_enabled, settings_notifier_Pushover_url))
settings_notifier_RocketChat_enabled = request.forms.get('settings_notifier_Rocket.Chat_enabled')
if settings_notifier_RocketChat_enabled == 'on':
settings_notifier_RocketChat_enabled = 1
else:
settings_notifier_RocketChat_enabled = 0
settings_notifier_RocketChat_url = request.forms.get('settings_notifier_Rocket.Chat_url')
c.execute("UPDATE table_settings_notifier SET enabled = ?, url = ? WHERE name = 'Rocket.Chat'", (settings_notifier_RocketChat_enabled, settings_notifier_RocketChat_url))
settings_notifier_Slack_enabled = request.forms.get('settings_notifier_Slack_enabled')
if settings_notifier_Slack_enabled == 'on':
settings_notifier_Slack_enabled = 1
else:
settings_notifier_Slack_enabled = 0
settings_notifier_Slack_url = request.forms.get('settings_notifier_Slack_url')
c.execute("UPDATE table_settings_notifier SET enabled = ?, url = ? WHERE name = 'Slack'", (settings_notifier_Slack_enabled, settings_notifier_Slack_url))
settings_notifier_SuperToasty_enabled = request.forms.get('settings_notifier_Super Toasty_enabled')
if settings_notifier_SuperToasty_enabled == 'on':
settings_notifier_SuperToasty_enabled = 1
else:
settings_notifier_SuperToasty_enabled = 0
settings_notifier_SuperToasty_url = request.forms.get('settings_notifier_Super Toasty_url')
c.execute("UPDATE table_settings_notifier SET enabled = ?, url = ? WHERE name = 'Super Toasty'", (settings_notifier_SuperToasty_enabled, settings_notifier_SuperToasty_url))
settings_notifier_Telegram_enabled = request.forms.get('settings_notifier_Telegram_enabled')
if settings_notifier_Telegram_enabled == 'on':
settings_notifier_Telegram_enabled = 1
else:
settings_notifier_Telegram_enabled = 0
settings_notifier_Telegram_url = request.forms.get('settings_notifier_Telegram_url')
c.execute("UPDATE table_settings_notifier SET enabled = ?, url = ? WHERE name = 'Telegram'", (settings_notifier_Telegram_enabled, settings_notifier_Telegram_url))
settings_notifier_Twitter_enabled = request.forms.get('settings_notifier_Twitter_enabled')
if settings_notifier_Twitter_enabled == 'on':
settings_notifier_Twitter_enabled = 1
else:
settings_notifier_Twitter_enabled = 0
settings_notifier_Twitter_url = request.forms.get('settings_notifier_Twitter_url')
c.execute("UPDATE table_settings_notifier SET enabled = ?, url = ? WHERE name = 'Twitter'", (settings_notifier_Twitter_enabled, settings_notifier_Twitter_url))
settings_notifier_XBMC_enabled = request.forms.get('settings_notifier_XBMC_enabled')
if settings_notifier_XBMC_enabled == 'on':
settings_notifier_XBMC_enabled = 1
else:
settings_notifier_XBMC_enabled = 0
settings_notifier_XBMC_url = request.forms.get('settings_notifier_XBMC_url')
c.execute("UPDATE table_settings_notifier SET enabled = ?, url = ? WHERE name = 'XBMC'", (settings_notifier_XBMC_enabled, settings_notifier_XBMC_url))
conn.commit() conn.commit()
c.close() c.close()
@ -619,6 +767,7 @@ def get_subtitle():
result = download_subtitle(episodePath, language, hi, providers_list, providers_auth) result = download_subtitle(episodePath, language, hi, providers_list, providers_auth)
if result is not None: if result is not None:
history_log(1, sonarrSeriesId, sonarrEpisodeId, result) history_log(1, sonarrSeriesId, sonarrEpisodeId, result)
send_notifications(sonarrSeriesId, sonarrEpisodeId, result)
store_subtitles(episodePath) store_subtitles(episodePath)
list_missing_subtitles(sonarrSeriesId) list_missing_subtitles(sonarrSeriesId)
redirect(ref) redirect(ref)

View file

@ -8,6 +8,7 @@ from pycountry import *
from get_general_settings import * from get_general_settings import *
from list_subtitles import * from list_subtitles import *
from utils import * from utils import *
from notifier import send_notifications
# configure the cache # configure the cache
region.configure('dogpile.cache.memory') region.configure('dogpile.cache.memory')
@ -78,6 +79,7 @@ def series_download_subtitles(no):
if message is not None: if message is not None:
store_subtitles(path_replace(episode[0])) store_subtitles(path_replace(episode[0]))
history_log(1, no, episode[2], message) history_log(1, no, episode[2], message)
send_notifications(no, episode[2], message)
list_missing_subtitles(no) list_missing_subtitles(no)
def wanted_download_subtitles(path): def wanted_download_subtitles(path):
@ -111,6 +113,7 @@ def wanted_download_subtitles(path):
store_subtitles(path_replace(episode[0])) store_subtitles(path_replace(episode[0]))
list_missing_subtitles(episode[3]) list_missing_subtitles(episode[3])
history_log(1, episode[3], episode[2], message) history_log(1, episode[3], episode[2], message)
send_notifications(episode[3], episode[2], message)
def wanted_search_missing_subtitles(): def wanted_search_missing_subtitles():
db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30) db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30)

43
notifier.py Normal file
View file

@ -0,0 +1,43 @@
import apprise
import os
import sqlite3
def get_notifier_providers():
conn_db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30)
c_db = conn_db.cursor()
providers = c_db.execute('SELECT name, url FROM table_settings_notifier WHERE enabled = 1').fetchall()
c_db.close()
return providers
def get_series_name(sonarrSeriesId):
conn_db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30)
c_db = conn_db.cursor()
data = c_db.execute('SELECT title FROM table_shows WHERE sonarrSeriesId = ?', (sonarrSeriesId,)).fetchone()
c_db.close()
return data[0]
def get_episode_name(sonarrEpisodeId):
conn_db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30)
c_db = conn_db.cursor()
data = c_db.execute('SELECT title FROM table_episodes WHERE sonarrEpisodeId = ?', (sonarrEpisodeId,)).fetchone()
c_db.close()
return data[0]
def send_notifications(sonarrSeriesId, sonarrEpisodeId, message):
providers = get_notifier_providers()
series = get_series_name(sonarrSeriesId)
episode = get_episode_name(sonarrEpisodeId)
apobj = apprise.Apprise()
for provider in providers:
if provider[1] is not None:
apobj.add(provider[1])
apobj.notify(
title='Bazarr notification',
body=series + ' - ' + episode + ' : ' + message,
)

View file

@ -40,6 +40,15 @@ if os.path.exists(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'))
else: else:
c.execute('UPDATE table_settings_general SET single_language="False"') c.execute('UPDATE table_settings_general SET single_language="False"')
try:
c.execute('CREATE TABLE `table_settings_notifier` (`name` TEXT, `url` TEXT, `enabled` INTEGER);')
except:
pass
else:
providers = ['Boxcar','Faast','Growl','Join','KODI','Mattermost','Notify My Android','Prowl','Pushalot','PushBullet','Pushjet','Pushover','Rocket.Chat','Slack','Super Toasty','Telegram','Twitter','XBMC']
for provider in providers:
c.execute('INSERT INTO `table_settings_notifier` (name, enabled) VALUES (?, ?);', (provider,'0'))
# Commit change to db # Commit change to db
db.commit() db.commit()

View file

@ -9,3 +9,8 @@ try:
pip.main(['install', '--user', 'langdetect']) pip.main(['install', '--user', 'langdetect'])
except SystemExit as e: except SystemExit as e:
pass pass
try:
pip.main(['install', '--user', 'apprise'])
except SystemExit as e:
pass

View file

@ -46,6 +46,7 @@
<a class="tabs item active" data-tab="general">General</a> <a class="tabs item active" data-tab="general">General</a>
<a class="tabs item" data-tab="sonarr">Sonarr</a> <a class="tabs item" data-tab="sonarr">Sonarr</a>
<a class="tabs item" data-tab="subliminal">Subliminal</a> <a class="tabs item" data-tab="subliminal">Subliminal</a>
<a class="tabs item" data-tab="notifier">Notifications</a>
</div> </div>
<div class="ui bottom attached tab segment active" data-tab="general"> <div class="ui bottom attached tab segment active" data-tab="general">
<div class="ui container"><button class="submit ui blue right floated button" type="submit" value="Submit" form="settings_form">Save</button></div> <div class="ui container"><button class="submit ui blue right floated button" type="submit" value="Submit" form="settings_form">Save</button></div>
@ -368,6 +369,9 @@
<div class="ui dividing header">Subtitles providers</div> <div class="ui dividing header">Subtitles providers</div>
<div class="twelve wide column"> <div class="twelve wide column">
<div class="ui info message"> <div class="ui info message">
<p>Thanks to Diaoul for his work on <a href="https://github.com/Diaoul/subliminal" target="_blank">Subliminal</a> on which Bazarr is based.</p>
</div>
<div class="ui orange message">
<p>Be aware that the more providers you enable, the longer it will take everytime you search for a subtitles.</p> <p>Be aware that the more providers you enable, the longer it will take everytime you search for a subtitles.</p>
</div> </div>
<div class="ui grid"> <div class="ui grid">
@ -520,8 +524,42 @@
</div> </div>
</div> </div>
</div> </div>
<div class="ui bottom attached tab segment" data-tab="notifier">
<div class="ui container"><button class="submit ui blue right floated button" type="submit" value="Submit" form="settings_form">Save</button></div>
<div class="ui dividing header">Notifications settings</div>
<div class="twelve wide column">
<div class="ui info message">
<p>Thanks to caronc for his work on <a href="https://github.com/caronc/apprise" target="_blank">apprise</a> on which is based the notifications system.</p>
</div>
<div class="ui info message">
<p>Please follow instructions on his <a href="https://github.com/caronc/apprise/wiki" target="_blank">wiki</a> to configure your notifications providers.</p>
</div>
<div class="ui grid">
%for notifier in settings_notifier:
<div class="middle aligned row">
<div class="right aligned four wide column">
<label>{{notifier[0]}}</label>
</div>
<div class="one wide column">
<div id="settings_notifier_{{notifier[0]}}_enabled" class="notifier_enabled ui toggle checkbox" data-notifier-url-div="settings_notifier_{{notifier[0]}}_url_div" data-enabled={{notifier[2]}}>
<input name="settings_notifier_{{notifier[0]}}_enabled" type="checkbox">
<label></label>
</div>
</div>
<div class="eight wide column">
<div class='field'>
<div id="settings_notifier_{{notifier[0]}}_url_div" class="ui fluid input">
<input name="settings_notifier_{{notifier[0]}}_url" type="text" value="{{notifier[1] if notifier[1] != None else ''}}">
</div>
</div>
</div>
</div>
%end
</div>
</div>
</div> </div>
</form> </form>
</div>
% include('footer.tpl') % include('footer.tpl')
</body> </body>
</html> </html>
@ -536,6 +574,10 @@
$('#loader').addClass('active'); $('#loader').addClass('active');
}) })
$('a[target="_blank"]').click(function(){
$('#loader').removeClass('active');
})
if ($('#sonarr_ssl_div').data("ssl") == "True") { if ($('#sonarr_ssl_div').data("ssl") == "True") {
$("#sonarr_ssl_div").checkbox('check'); $("#sonarr_ssl_div").checkbox('check');
} else { } else {
@ -554,6 +596,25 @@
$("#settings_single_language").checkbox('uncheck'); $("#settings_single_language").checkbox('uncheck');
} }
$('.notifier_enabled').each(function(i, obj) {
if ($(this).data("enabled") == 1) {
$(this).checkbox('check');
$('[id=\"' + $(this).data("notifier-url-div") + '\"]').removeClass('disabled');
} else {
$(this).checkbox('uncheck');
$('[id=\"' + $(this).data("notifier-url-div") + '\"]').addClass('disabled');
}
});
$('.notifier_enabled').change(function(i, obj) {
if ($(this).checkbox('is checked')) {
$('[id=\"' + $(this).data("notifier-url-div") + '\"]').removeClass('disabled');
} else {
$('[id=\"' + $(this).data("notifier-url-div") + '\"]').addClass('disabled');
}
});
$('#settings_loglevel').dropdown('clear'); $('#settings_loglevel').dropdown('clear');
$('#settings_loglevel').dropdown('set selected','{{!settings_general[4]}}'); $('#settings_loglevel').dropdown('set selected','{{!settings_general[4]}}');
$('#settings_providers').dropdown('clear'); $('#settings_providers').dropdown('clear');