2018-08-16 02:01:49 +00:00
|
|
|
from get_argv import config_dir
|
|
|
|
|
2018-01-23 04:25:58 +00:00
|
|
|
import apprise
|
|
|
|
import os
|
|
|
|
import sqlite3
|
|
|
|
|
|
|
|
def get_notifier_providers():
|
2018-08-16 02:01:49 +00:00
|
|
|
conn_db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
2018-01-23 04:25:58 +00:00
|
|
|
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):
|
2018-08-16 02:01:49 +00:00
|
|
|
conn_db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
2018-01-23 04:25:58 +00:00
|
|
|
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):
|
2018-08-16 02:01:49 +00:00
|
|
|
conn_db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
2018-01-23 04:25:58 +00:00
|
|
|
c_db = conn_db.cursor()
|
2018-08-28 17:19:20 +00:00
|
|
|
data = c_db.execute('SELECT title, season, episode FROM table_episodes WHERE sonarrEpisodeId = ?', (sonarrEpisodeId,)).fetchone()
|
2018-01-23 04:25:58 +00:00
|
|
|
c_db.close()
|
|
|
|
|
2018-08-28 17:19:20 +00:00
|
|
|
return data[0], data[1], data[2]
|
2018-01-23 04:25:58 +00:00
|
|
|
|
2018-04-24 14:48:52 +00:00
|
|
|
def get_movies_name(radarrId):
|
2018-08-16 02:01:49 +00:00
|
|
|
conn_db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
2018-04-24 14:48:52 +00:00
|
|
|
c_db = conn_db.cursor()
|
|
|
|
data = c_db.execute('SELECT title FROM table_movies WHERE radarrId = ?', (radarrId,)).fetchone()
|
|
|
|
c_db.close()
|
|
|
|
|
|
|
|
return data[0]
|
|
|
|
|
2018-01-23 04:25:58 +00:00
|
|
|
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',
|
2018-08-28 17:19:20 +00:00
|
|
|
body=(series + ' - S' + str(episode[1]).zfill(2) + 'E' + str(episode[2]).zfill(2) + ' - ' + episode[0] + ' : ' + message),
|
2018-04-24 14:48:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def send_notifications_movie(radarrId, message):
|
|
|
|
providers = get_notifier_providers()
|
|
|
|
movie = get_movies_name(radarrId)
|
|
|
|
|
|
|
|
apobj = apprise.Apprise()
|
|
|
|
|
|
|
|
for provider in providers:
|
|
|
|
if provider[1] is not None:
|
|
|
|
apobj.add(provider[1])
|
|
|
|
|
|
|
|
apobj.notify(
|
|
|
|
title='Bazarr notification',
|
|
|
|
body=movie + ' : ' + message,
|
2018-01-23 04:25:58 +00:00
|
|
|
)
|