1
0
Fork 0
mirror of https://github.com/morpheus65535/bazarr synced 2024-12-26 17:47:20 +00:00

Continuing development.

This commit is contained in:
Louis Vézina 2019-08-20 14:53:16 -04:00
parent 060c59e1d0
commit bed02977c2

View file

@ -2,10 +2,10 @@
import apprise import apprise
import os import os
import sqlite3
import logging import logging
from get_args import args from get_args import args
from database import TableSettingsNotifier, TableShows, TableEpisodes, TableMovies
def update_notifier(): def update_notifier():
@ -18,64 +18,75 @@ def update_notifier():
notifiers_new = [] notifiers_new = []
notifiers_old = [] notifiers_old = []
conn_db = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30) notifiers_current = TableSettingsNotifier.select(
c_db = conn_db.cursor() TableSettingsNotifier.name
notifiers_current = c_db.execute('SELECT name FROM table_settings_notifier').fetchall() )
for x in results['schemas']: for x in results['schemas']:
if x['service_name'] not in str(notifiers_current): if x['service_name'] not in str(notifiers_current):
notifiers_new.append(x['service_name']) notifiers_new.append(x['service_name'])
logging.debug('Adding new notifier agent: ' + x['service_name']) logging.debug('Adding new notifier agent: ' + x['service_name'])
else: else:
notifiers_old.append(x['service_name']) notifiers_old.append(x['service_name'])
notifier_current = [i[0] for i in notifiers_current] notifier_current = [i.name for i in notifiers_current]
notifiers_to_delete = list(set(notifier_current) - set(notifiers_old)) notifiers_to_delete = list(set(notifier_current) - set(notifiers_old))
for notifier_new in notifiers_new: for notifier_new in notifiers_new:
c_db.execute('INSERT INTO `table_settings_notifier` (name, enabled) VALUES (?, ?);', (notifier_new, '0')) TableSettingsNotifier.insert(
{
TableSettingsNotifier.name: notifier_new,
TableSettingsNotifier.enabled: 0
}
).execute()
for notifier_to_delete in notifiers_to_delete: for notifier_to_delete in notifiers_to_delete:
c_db.execute('DELETE FROM `table_settings_notifier` WHERE name=?', (notifier_to_delete,)) TableSettingsNotifier.delete().where(
TableSettingsNotifier.Name == notifier_to_delete
conn_db.commit() ).execute()
c_db.close()
def get_notifier_providers(): def get_notifier_providers():
conn_db = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30) providers = TableSettingsNotifier.select(
c_db = conn_db.cursor() TableSettingsNotifier.name,
providers = c_db.execute('SELECT name, url FROM table_settings_notifier WHERE enabled = 1').fetchall() TableSettingsNotifier.url
c_db.close() ).where(
TableSettingsNotifier.enabled == 1
)
return providers return providers
def get_series_name(sonarrSeriesId): def get_series_name(sonarrSeriesId):
conn_db = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30) data = TableShows.select(
c_db = conn_db.cursor() TableShows.title
data = c_db.execute('SELECT title FROM table_shows WHERE sonarrSeriesId = ?', (sonarrSeriesId,)).fetchone() ).where(
c_db.close() TableShows.sonarr_series_id == sonarrSeriesId
).first()
return data[0] return data.title
def get_episode_name(sonarrEpisodeId): def get_episode_name(sonarrEpisodeId):
conn_db = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30) data = TableEpisodes.select(
c_db = conn_db.cursor() TableEpisodes.title,
data = c_db.execute('SELECT title, season, episode FROM table_episodes WHERE sonarrEpisodeId = ?', TableEpisodes.season,
(sonarrEpisodeId,)).fetchone() TableEpisodes.episode
c_db.close() ).where(
TableEpisodes.sonarr_episode_id == sonarrEpisodeId
).first()
return data[0], data[1], data[2] return data.title, data.season, data.episode
def get_movies_name(radarrId): def get_movies_name(radarrId):
conn_db = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30) data = TableMovies.select(
c_db = conn_db.cursor() TableMovies.title
data = c_db.execute('SELECT title FROM table_movies WHERE radarrId = ?', (radarrId,)).fetchone() ).where(
c_db.close() TableMovies.radarr_id == radarrId
).first()
return data[0] return data.title
def send_notifications(sonarrSeriesId, sonarrEpisodeId, message): def send_notifications(sonarrSeriesId, sonarrEpisodeId, message):