Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add join notifier support #5241

Merged
merged 45 commits into from
Nov 3, 2018
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
c1450f0
add join notifier support
ouldsmobile Sep 20, 2018
f8934f6
Update join.py
ouldsmobile Sep 20, 2018
abf8433
Update __init__.py
ouldsmobile Sep 20, 2018
75000bf
fix bad indent in join.py
ouldsmobile Sep 20, 2018
377d863
fix bad formatting
ouldsmobile Sep 20, 2018
3921354
fix bad formatting
ouldsmobile Sep 20, 2018
b0525b9
fix bad formatting
ouldsmobile Sep 20, 2018
126f5a4
fix more formatting errors
ouldsmobile Sep 20, 2018
9f26357
fix travis errors in join.py
ouldsmobile Sep 20, 2018
0c1ea0a
add missing docstrings in join.py
ouldsmobile Sep 21, 2018
1f1790c
fixing docstrings in join.py
ouldsmobile Sep 21, 2018
0e454ea
fixing docstrings in join.py
ouldsmobile Sep 21, 2018
95fa1d2
fixing docstrings in join.py
ouldsmobile Sep 21, 2018
4d0a3bd
removed unneccessary comments from join.py
ouldsmobile Sep 21, 2018
9321d44
add join notifier support
ouldsmobile Sep 20, 2018
9d27eb8
Update join.py
ouldsmobile Sep 20, 2018
ef77354
Update __init__.py
ouldsmobile Sep 20, 2018
9c2f6d6
fix bad indent in join.py
ouldsmobile Sep 20, 2018
698a532
fix bad formatting
ouldsmobile Sep 20, 2018
7d3fe77
fix bad formatting
ouldsmobile Sep 20, 2018
ed5b3d7
fix bad formatting
ouldsmobile Sep 20, 2018
de2a036
fix more formatting errors
ouldsmobile Sep 20, 2018
6bcaed2
fix travis errors in join.py
ouldsmobile Sep 20, 2018
fde1b10
add missing docstrings in join.py
ouldsmobile Sep 21, 2018
518550a
fixing docstrings in join.py
ouldsmobile Sep 21, 2018
5416d3c
fixing docstrings in join.py
ouldsmobile Sep 21, 2018
8e3947e
fixing docstrings in join.py
ouldsmobile Sep 21, 2018
d315502
removed unneccessary comments from join.py
ouldsmobile Sep 21, 2018
36708ca
initial edits to vueify join notifier support
ouldsmobile Oct 31, 2018
c90b7fb
initial vueification of join notifier support
ouldsmobile Oct 31, 2018
588a5d2
Merge branch 'feature/join-notifier-support' of https://github.com/ou…
ouldsmobile Oct 31, 2018
4a02962
Merge branch 'develop' of https://github.com/pymedusa/Medusa into fea…
ouldsmobile Oct 31, 2018
513f9c0
update to v-model sliders, fix some minor edit errors
ouldsmobile Oct 31, 2018
9b6c6b0
forgot to hit save during one of my edits. push was missing some updates
ouldsmobile Oct 31, 2018
b883c4f
removed @updates
ouldsmobile Oct 31, 2018
7dfb935
remove notifications.js files from themes, no longer used
ouldsmobile Nov 1, 2018
252d42a
remove notifiers.js files from themes-default, no longer used, remove…
ouldsmobile Nov 1, 2018
89482d7
ran yarn
ouldsmobile Nov 1, 2018
70d3f99
update app.py from develop branch
ouldsmobile Nov 1, 2018
07ff739
Merge branch 'develop' into feature/join-notifier-support
ouldsmobile Nov 1, 2018
24af1e8
ran yarn --dev
ouldsmobile Nov 2, 2018
82e7eea
Merge branch 'feature/join-notifier-support' of https://github.com/ou…
ouldsmobile Nov 2, 2018
7ece187
removed unneeded url encoding fron join.py
ouldsmobile Nov 2, 2018
50640be
removed unneeded urllib import from join.py
ouldsmobile Nov 2, 2018
7fadc35
reran yarn
ouldsmobile Nov 3, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 @@ -492,6 +492,13 @@
PUSHBULLET_API = None
PUSHBULLET_DEVICE = None

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

USE_EMAIL = False
EMAIL_NOTIFY_ONSNATCH = False
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
119 changes: 119 additions & 0 deletions medusa/notifiers/join.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# coding=utf-8
# Author: Kevin Ould email: ouldsmobile1@gmail.com
"""Adds Join Notifications."""
from __future__ import unicode_literals

import logging
import urllib
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}
urllib.quote_plus = urllib.quote
params = urllib.urlencode(post_data)

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

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
8 changes: 8 additions & 0 deletions themes-default/slim/src/store/modules/notifiers.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,14 @@ const state = {
authToken: null,
device: null
},
join: {
enabled: null,
notifyOnSnatch: null,
notifyOnDownload: null,
notifyOnSubtitleDownload: null,
api: null,
device: null
},
freemobile: {
enabled: null,
notifyOnSnatch: null,
Expand Down
2 changes: 2 additions & 0 deletions themes-default/slim/src/store/modules/notifiers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import plex from './plex';
import prowl from './prowl';
import pushalot from './pushalot';
import pushbullet from './pushbullet';
import join from './join';
import pushover from './pushover';
import pyTivo from './py-tivo';
import slack from './slack';
Expand Down Expand Up @@ -47,6 +48,7 @@ const modules = {
prowl,
pushalot,
pushbullet,
join,
pushover,
pyTivo,
slack,
Expand Down
21 changes: 21 additions & 0 deletions themes-default/slim/src/store/modules/notifiers/join.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export const state = {
enabled: null,
notifyOnSnatch: null,
notifyOnDownload: null,
notifyOnSubtitleDownload: null,
api: null,
device: null
};

export const mutations = {};

export const getters = {};

export const actions = {};

export default {
state,
mutations,
getters,
actions
};
4 changes: 4 additions & 0 deletions themes-default/slim/static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -2494,6 +2494,10 @@ div.metadataDiv .disabled {
background-position: -704px 0;
}

.icon-notifiers-join {
background-position: -736px 0;
}

div#config-components h3 > a {
padding-left: 5px;
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions themes-default/slim/test/__fixtures__/app-header.json
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,13 @@
"enabled": true,
"api": ""
},
"join": {
"notifyOnSubtitleDownload": false,
"notifyOnDownload": false,
"notifyOnSnatch": false,
"enabled": true,
"api": ""
},
"nmjv2": {
"enabled": false
},
Expand Down
Loading