diff --git a/README.md b/README.md index fb80961..193beaf 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ - [Movies](#movies) - [Shows](#shows) - [Notifications](#notifications) + - [Apprise](#apprise) - [Pushover](#pushover) - [Slack](#slack) - [Radarr](#radarr) @@ -664,15 +665,79 @@ Use filters to specify the movie/shows's country of origin or blacklist (i.e. fi ## Notifications +```json +"notifications": { + "apprise": { + "service": "apprise", + "url": "", + "title": "" + }, + "verbose": false +}, +``` + Notification alerts for Traktarr tasks. -_Note: Manual commands need the `--notifications` flag._ +For auto (i.e. scheduled) runs, notifications are enabled automatically when notification services are listed in this section. + +For manual (i.e. CLI) commands, you need to add the `--notifications` flag. + +Supported `services`: + - `apprise` + - `pushover` + - `slack` + +_Note: The key name can be anything, but the `service` key must be must be the exact service name (e.g. `pushover`). See below for example._ + + +```json +"notifications": { + "anyname": { + "service": "pushover", + } +}, +``` + + +### General + +`verbose` - Toggle detailed notifications. -Currently, only Pushover and Slack are supported; others can be added in the future. + - Default is `true`. -_Note: The key name (i.e the name right under notifications) can be anything, but the `"service":` must be the exact service name (e.g. `"pushover"`)._ + - Set to `false` if you want to reduce the amount of detailed notifications (e.g. just the total vs the names of the movies/shows added). +```json +"notifications": { + "verbose": true +}, +``` +### Apprise + +```json +"notifications": { + "apprise": { + "service": "apprise", + "url": "", + "title": "" + }, + "verbose": false +}, +``` + +`url` - Apprise service URL (see [here](https://github.com/caronc/apprise)). + + - Required. + +`title` - Notification Title. + + - Optional. + + - Default is `Traktarr`. + + +### Pushover ```json "notifications": { @@ -682,26 +747,21 @@ _Note: The key name (i.e the name right under notifications) can be anything, bu "user_token": "", "priority": 0 }, - "slack": { - "service": "slack", - "webhook_url": "" - }, - "verbose": true + "verbose": false }, ``` -`verbose` - Toggle detailed notifications. Default is `true`. +`app_token` - App Token from [Pushover.net](https://pushover.net). - - Set to `false`, if you want to reduce the amount of detailed notifications (e.g. the names of the movies/shows added vs just the total). + - Required. +`user_token` - User Token from [Pushover.net](https://pushover.net). -### Pushover - -`app_token` - Retrieve from Pushover.net. Required. + - Required. -`user_token` - Retrieve from Pushover.net. Required. +`priority` - [Priority](https://pushover.net/api#priority) of the notifications. -`priority` - Priority for the messages (see https://pushover.net/api#priority). Optional. + - Optional. - Choices are: `-2`, `-1`, `0`, `1`, `2`. @@ -713,6 +773,7 @@ _Note: The key name (i.e the name right under notifications) can be anything, bu ### Slack ```json +"notifications": { "slack": { "service": "slack", "webhook_url": "", @@ -720,17 +781,31 @@ _Note: The key name (i.e the name right under notifications) can be anything, bu "sender_name": "Traktarr", "sender_icon": ":movie_camera:" }, - "verbose": true + "verbose": false }, ``` -`webhook_url` - Webhook URL you get after creating an "Incoming Webhook" under "Custom Integrations" on Slack's Website. Required. +`webhook_url` - [Webhook URL](https://my.slack.com/services/new/incoming-webhook/). -`channel` - Slack channel. Optional. Default is none. + - Required. + +`channel` - Slack channel to send the notifications to. -`sender_name` - Name the sender of the message. Optional. Default is `Traktarr`. + - Optional. + + - Default is blank. + +`sender_name` - Sender's name for the notifications. + + - Optional. + + - Default is `Traktarr`. + +`sender_icon` - Icon to use for the notifications. -`sender_icon` - Icon to use for the message. Optional. Default is `:movie_camera:` + - Optional. + + - Default is `:movie_camera:` diff --git a/notifications/__init__.py b/notifications/__init__.py index 903ca31..817fe26 100644 --- a/notifications/__init__.py +++ b/notifications/__init__.py @@ -1,11 +1,13 @@ from misc.log import logger +from .apprise import Apprise from .pushover import Pushover from .slack import Slack log = logger.get_logger(__name__) SERVICES = { + 'apprise': Apprise, 'pushover': Pushover, 'slack': Slack } diff --git a/notifications/apprise.py b/notifications/apprise.py new file mode 100644 index 0000000..3335fee --- /dev/null +++ b/notifications/apprise.py @@ -0,0 +1,32 @@ +import apprise + +from misc.log import logger + +log = logger.get_logger(__name__) + + +class Apprise: + NAME = "Apprise" + + def __init__(self, url, title='Traktarr'): + self.url = url + self.title = title + log.debug("Initialized Apprise notification agent") + + def send(self, **kwargs): + if not self.url: + log.error("You must specify a URL when initializing this class") + return False + + # send notification + try: + apobj = apprise.Apprise() + apobj.add(self.url) + apobj.notify( + title=self.title, + body=kwargs['message'], + ) + + except Exception: + log.exception("Error sending notification to %r", self.url) + return False diff --git a/requirements.txt b/requirements.txt index 1f3ada8..5980449 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,4 +4,5 @@ attrdict==2.0.0 click==6.7 requests~=2.20.0 pyfiglet -cashier~=1.3 \ No newline at end of file +cashier~=1.3 +apprise==0.7.7 \ No newline at end of file