Skip to content

Commit

Permalink
add join notifier support (#5241)
Browse files Browse the repository at this point in the history
* add join notifier support

* Update join.py

* Update __init__.py

* fix bad indent in join.py

* fix bad formatting

* fix bad formatting

* fix bad formatting

* fix more formatting errors

* fix travis errors in join.py

* add missing docstrings in join.py

* fixing docstrings in join.py

* fixing docstrings in join.py

* fixing docstrings in join.py

* removed unneccessary comments from join.py

* add join notifier support

* Update join.py

* Update __init__.py

* fix bad indent in join.py

* fix bad formatting

* fix bad formatting

* fix bad formatting

* fix more formatting errors

* fix travis errors in join.py

* add missing docstrings in join.py

* fixing docstrings in join.py

* fixing docstrings in join.py

* fixing docstrings in join.py

* removed unneccessary comments from join.py

* initial edits to  vueify join notifier support

* initial vueification of join notifier support

* update to v-model sliders, fix some minor edit errors

* forgot to hit save during one of my edits. push was missing some updates

* removed @updates

* remove notifications.js files from themes, no longer used

* remove notifiers.js files from themes-default, no longer used, remove unneeded line in config_notifications.mako

* ran yarn

* update app.py from develop branch

* ran yarn --dev

* removed unneeded url encoding fron join.py

* removed unneeded urllib import from join.py

* reran yarn
  • Loading branch information
ouldsmobile authored and p0psicles committed Nov 3, 2018
1 parent e7882f2 commit 676b11e
Show file tree
Hide file tree
Showing 27 changed files with 1,097 additions and 1,794 deletions.
15 changes: 15 additions & 0 deletions dredd/api-description.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1813,6 +1813,21 @@ definitions:
type: boolean
notifyOnSubtitleDownload:
type: boolean
join:
type: object
properties:
enabled:
type: boolean
api:
type: string
device:
type: string
notifyOnSnatch:
type: boolean
notifyOnDownload:
type: boolean
notifyOnSubtitleDownload:
type: boolean
freemobile:
type: object
properties:
Expand Down
1 change: 1 addition & 0 deletions dredd/dredd_hook.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env python2
"""Dredd hook."""
from __future__ import absolute_import

Expand Down
17 changes: 16 additions & 1 deletion medusa/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ def initialize(self, console_logging=True):

sections = [
'General', 'Blackhole', 'Newzbin', 'SABnzbd', 'NZBget', 'KODI', 'PLEX', 'Emby', 'Growl', 'Prowl', 'Twitter',
'Boxcar2', 'NMJ', 'NMJv2', 'Synology', 'Slack', 'SynologyNotifier', 'pyTivo', 'Pushalot', 'Pushbullet',
'Boxcar2', 'NMJ', 'NMJv2', 'Synology', 'Slack', 'SynologyNotifier', 'pyTivo', 'Pushalot', 'Pushbullet', 'Join',
'Subtitles', 'pyTivo',
]

Expand Down Expand Up @@ -875,6 +875,13 @@ def initialize(self, console_logging=True):
app.PUSHBULLET_API = check_setting_str(app.CFG, 'Pushbullet', 'pushbullet_api', '', censor_log='low')
app.PUSHBULLET_DEVICE = check_setting_str(app.CFG, 'Pushbullet', 'pushbullet_device', '')

app.USE_JOIN = bool(check_setting_int(app.CFG, 'Pushbullet', 'use_join', 0))
app.JOIN_NOTIFY_ONSNATCH = bool(check_setting_int(app.CFG, 'Join', 'join_notify_onsnatch', 0))
app.JOIN_NOTIFY_ONDOWNLOAD = bool(check_setting_int(app.CFG, 'Join', 'join_notify_ondownload', 0))
app.JOIN_NOTIFY_ONSUBTITLEDOWNLOAD = bool(check_setting_int(app.CFG, 'Join', 'join_notify_onsubtitledownload', 0))
app.JOIN_API = check_setting_str(app.CFG, 'Join', 'join_api', '', censor_log='low')
app.JOIN_DEVICE = check_setting_str(app.CFG, 'Join', 'join_device', '')

app.USE_EMAIL = bool(check_setting_int(app.CFG, 'Email', 'use_email', 0))
app.EMAIL_NOTIFY_ONSNATCH = bool(check_setting_int(app.CFG, 'Email', 'email_notify_onsnatch', 0))
app.EMAIL_NOTIFY_ONDOWNLOAD = bool(check_setting_int(app.CFG, 'Email', 'email_notify_ondownload', 0))
Expand Down Expand Up @@ -1852,6 +1859,14 @@ def save_config():
new_config['Pushbullet']['pushbullet_api'] = app.PUSHBULLET_API
new_config['Pushbullet']['pushbullet_device'] = app.PUSHBULLET_DEVICE

new_config['Join'] = {}
new_config['Join']['use_join'] = int(app.USE_JOIN)
new_config['Join']['join_notify_onsnatch'] = int(app.JOIN_NOTIFY_ONSNATCH)
new_config['Join']['join_notify_ondownload'] = int(app.JOIN_NOTIFY_ONDOWNLOAD)
new_config['Join']['join_notify_onsubtitledownload'] = int(app.JOIN_NOTIFY_ONSUBTITLEDOWNLOAD)
new_config['Join']['join_api'] = app.JOIN_API
new_config['Join']['join_device'] = app.JOIN_DEVICE

new_config['Email'] = {}
new_config['Email']['use_email'] = int(app.USE_EMAIL)
new_config['Email']['email_notify_onsnatch'] = int(app.EMAIL_NOTIFY_ONSNATCH)
Expand Down
7 changes: 7 additions & 0 deletions medusa/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,13 @@ def __init__(self):
self.PUSHBULLET_API = None
self.PUSHBULLET_DEVICE = None

self.USE_JOIN = False
self.JOIN_NOTIFY_ONSNATCH = False
self.JOIN_NOTIFY_ONDOWNLOAD = False
self.JOIN_NOTIFY_ONSUBTITLEDOWNLOAD = False
self.JOIN_API = None
self.JOIN_DEVICE = None

self.USE_EMAIL = False
self.EMAIL_NOTIFY_ONSNATCH = False
self.EMAIL_NOTIFY_ONDOWNLOAD = False
Expand Down
3 changes: 3 additions & 0 deletions medusa/notifiers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
emby,
freemobile,
growl,
join,
kodi,
libnotify,
nmj,
Expand Down Expand Up @@ -54,6 +55,7 @@
boxcar2_notifier = boxcar2.Notifier()
pushalot_notifier = pushalot.Notifier()
pushbullet_notifier = pushbullet.Notifier()
join_notifier = join.Notifier()
freemobile_notifier = freemobile.Notifier()
telegram_notifier = telegram.Notifier()
# social
Expand All @@ -79,6 +81,7 @@
boxcar2_notifier,
pushalot_notifier,
pushbullet_notifier,
join_notifier,
twitter_notifier,
trakt_notifier,
email_notifier,
Expand Down
116 changes: 116 additions & 0 deletions medusa/notifiers/join.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# coding=utf-8
# Author: Kevin Ould email: ouldsmobile1@gmail.com
"""Adds Join Notifications."""
from __future__ import unicode_literals

import logging
from builtins import object

from medusa import app, common
from medusa.logger.adapters.style import BraceAdapter
from medusa.session.core import MedusaSession

import requests

log = BraceAdapter(logging.getLogger(__name__))
log.logger.addHandler(logging.NullHandler())


class Notifier(object):
"""Notifier class for Join."""

def __init__(self):
"""Init method."""
self.session = MedusaSession()
self.url = 'https://joinjoaomgcd.appspot.com/_ah/api/messaging/v1/sendPush?'

def test_notify(self, join_api, join_device):
"""Sends test notification from config screen."""
log.debug('Sending a test Join notification.')
return self._sendjoin(
join_api=join_api,
join_device=join_device,
event='Test',
message='Testing Join settings from Medusa',
force=True
)

def notify_snatch(self, ep_name, is_proper):
"""Send Join notification when nzb snatched if selected in config."""
if app.JOIN_NOTIFY_ONSNATCH:
self._sendjoin(
join_api=None,
event=common.notifyStrings[(common.NOTIFY_SNATCH, common.NOTIFY_SNATCH_PROPER)[is_proper]] + ' : ' + ep_name,
message=ep_name
)

def notify_download(self, ep_name):
"""Send Join notification when nzb download completed if selected in config."""
if app.JOIN_NOTIFY_ONDOWNLOAD:
self._sendjoin(
join_api=None,
event=common.notifyStrings[common.NOTIFY_DOWNLOAD] + ' : ' + ep_name,
message=ep_name
)

def notify_subtitle_download(self, ep_name, lang):
"""Send Join notification when subtitles downloaded if selected in config."""
if app.JOIN_NOTIFY_ONSUBTITLEDOWNLOAD:
self._sendjoin(
join_api=None,
event=common.notifyStrings[common.NOTIFY_SUBTITLE_DOWNLOAD] + ' : ' + ep_name + ' : ' + lang,
message=ep_name + ': ' + lang
)

def notify_git_update(self, new_version='??'):
"""Send Join notification when new version available from git."""
self._sendjoin(
join_api=None,
event=common.notifyStrings[common.NOTIFY_GIT_UPDATE],
message=common.notifyStrings[common.NOTIFY_GIT_UPDATE_TEXT] + new_version,
)

def notify_login(self, ipaddress=''):
"""Send Join notification when login detected."""
self._sendjoin(
join_api=None,
event=common.notifyStrings[common.NOTIFY_LOGIN],
message=common.notifyStrings[common.NOTIFY_LOGIN_TEXT].format(ipaddress)
)

def _sendjoin(self, join_api=None, join_device=None, event=None, message=None, force=False):
"""Compose and send Join notification."""
push_result = {'success': False, 'error': ''}

if not (app.USE_JOIN or force):
return False

join_api = join_api or app.JOIN_API
join_device = join_device or app.JOIN_DEVICE
icon_url = 'https://cdn.pymedusa.com/images/ico/favicon-310.png'

log.debug('Join title: {0!r}', event)
log.debug('Join message: {0!r}', message)
log.debug('Join api: {0!r}', join_api)
log.debug('Join devices: {0!r}', join_device)

post_data = {'title': event, 'text': message, 'deviceId': join_device, 'apikey': join_api, 'icon': icon_url}

r = requests.get(self.url, params=post_data)

try:
response = r.json()
except ValueError:
log.warning('Join notification failed. Could not parse join response.')
push_result['error'] = 'Join notification failed. Could not parse join response.'
return push_result

failed = response.pop('errorMessage', {})
if failed:
log.warning('Join notification failed: {0}', failed.get('message'))
push_result['error'] = 'Join notification failed: {0}'.format(failed.get('message'))
else:
log.debug('Join notification sent.')
push_result['success'] = True

return push_result
15 changes: 15 additions & 0 deletions medusa/server/api/v2/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,13 @@ class ConfigHandler(BaseRequestHandler):
'notifiers.pushbullet.notifyOnDownload': BooleanField(app, 'PUSHBULLET_NOTIFY_ONDOWNLOAD'),
'notifiers.pushbullet.notifyOnSubtitleDownload': BooleanField(app, 'PUSHBULLET_NOTIFY_ONSUBTITLEDOWNLOAD'),

'notifiers.join.enabled': BooleanField(app, 'USE_JOIN'),
'notifiers.join.api': StringField(app, 'JOIN_API'),
'notifiers.join.device': StringField(app, 'JOIN_DEVICE'),
'notifiers.join.notifyOnSnatch': BooleanField(app, 'JOIN_NOTIFY_ONSNATCH'),
'notifiers.join.notifyOnDownload': BooleanField(app, 'JOIN_NOTIFY_ONDOWNLOAD'),
'notifiers.join.notifyOnSubtitleDownload': BooleanField(app, 'JOIN_NOTIFY_ONSUBTITLEDOWNLOAD'),

'notifiers.freemobile.enabled': BooleanField(app, 'USE_FREEMOBILE'),
'notifiers.freemobile.api': StringField(app, 'FREEMOBILE_APIKEY'),
'notifiers.freemobile.id': StringField(app, 'FREEMOBILE_ID'),
Expand Down Expand Up @@ -867,6 +874,14 @@ def data_notifiers():
section_data['pushbullet']['api'] = app.PUSHBULLET_API
section_data['pushbullet']['device'] = app.PUSHBULLET_DEVICE

section_data['join'] = NonEmptyDict()
section_data['join']['enabled'] = bool(app.USE_JOIN)
section_data['join']['notifyOnSnatch'] = bool(app.JOIN_NOTIFY_ONSNATCH)
section_data['join']['notifyOnDownload'] = bool(app.JOIN_NOTIFY_ONDOWNLOAD)
section_data['join']['notifyOnSubtitleDownload'] = bool(app.JOIN_NOTIFY_ONSUBTITLEDOWNLOAD)
section_data['join']['api'] = app.JOIN_API
section_data['join']['device'] = app.JOIN_DEVICE

section_data['freemobile'] = NonEmptyDict()
section_data['freemobile']['enabled'] = bool(app.USE_FREEMOBILE)
section_data['freemobile']['notifyOnSnatch'] = bool(app.FREEMOBILE_NOTIFY_ONSNATCH)
Expand Down
9 changes: 9 additions & 0 deletions medusa/server/web/config/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ def saveNotifications(self, use_kodi=None, kodi_always_on=None, kodi_notify_onsn
use_pushbullet=None, pushbullet_notify_onsnatch=None, pushbullet_notify_ondownload=None,
pushbullet_notify_onsubtitledownload=None, pushbullet_api=None, pushbullet_device=None,
pushbullet_device_list=None,
use_join=None, join_notify_onsnatch=None, join_notify_ondownload=None,
join_notify_onsubtitledownload=None, join_api=None, join_device=None,
use_email=None, email_notify_onsnatch=None, email_notify_ondownload=None,
email_notify_onsubtitledownload=None, email_host=None, email_port=25, email_from=None,
email_tls=None, email_user=None, email_password=None, email_list=None, email_subject=None, email_show_list=None,
Expand Down Expand Up @@ -251,6 +253,13 @@ def saveNotifications(self, use_kodi=None, kodi_always_on=None, kodi_notify_onsn
app.PUSHBULLET_API = pushbullet_api
app.PUSHBULLET_DEVICE = pushbullet_device_list

app.USE_JOIN = config.checkbox_to_value(use_join)
app.JOIN_NOTIFY_ONSNATCH = config.checkbox_to_value(join_notify_onsnatch)
app.JOIN_NOTIFY_ONDOWNLOAD = config.checkbox_to_value(join_notify_ondownload)
app.JOIN_NOTIFY_ONSUBTITLEDOWNLOAD = config.checkbox_to_value(join_notify_onsubtitledownload)
app.JOIN_API = join_api
app.JOIN_DEVICE = join_device

app.instance.save_config()

if results:
Expand Down
8 changes: 8 additions & 0 deletions medusa/server/web/home/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,14 @@ def testPushbullet(api=None):
else:
return 'Error sending Pushbullet notification: {0}'.format(result.get('error'))

@staticmethod
def testJoin(api=None, device=None):
result = notifiers.join_notifier.test_notify(api, device)
if result.get('success'):
return 'Join notification succeeded. Check your device to make sure it worked'
else:
return 'Error sending Join notification: {0}'.format(result.get('error'))

@staticmethod
def getPushbulletDevices(api=None):
result = notifiers.pushbullet_notifier.get_devices(api)
Expand Down
Loading

0 comments on commit 676b11e

Please sign in to comment.