You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
108 lines
3.1 KiB
108 lines
3.1 KiB
13 years ago
|
from couchpotato.core.event import fireEvent, addEvent
|
||
14 years ago
|
from couchpotato.core.logger import CPLog
|
||
|
from couchpotato.core.notifications.base import Notification
|
||
13 years ago
|
from couchpotato.environment import Env
|
||
14 years ago
|
from gntp import notifier
|
||
13 years ago
|
import traceback
|
||
14 years ago
|
|
||
|
log = CPLog(__name__)
|
||
|
|
||
|
|
||
|
class Growl(Notification):
|
||
|
|
||
13 years ago
|
registered = False
|
||
|
|
||
14 years ago
|
def __init__(self):
|
||
|
super(Growl, self).__init__()
|
||
14 years ago
|
|
||
13 years ago
|
if self.isEnabled():
|
||
11 years ago
|
addEvent('app.load', self.register)
|
||
13 years ago
|
|
||
|
def register(self):
|
||
|
if self.registered: return
|
||
14 years ago
|
try:
|
||
13 years ago
|
|
||
|
hostname = self.conf('hostname')
|
||
|
password = self.conf('password')
|
||
|
port = self.conf('port')
|
||
|
|
||
13 years ago
|
self.growl = notifier.GrowlNotifier(
|
||
13 years ago
|
applicationName = Env.get('appname'),
|
||
13 years ago
|
notifications = ["Updates"],
|
||
|
defaultNotifications = ["Updates"],
|
||
|
applicationIcon = '%s/static/images/couch.png' % fireEvent('app.api_url', single = True),
|
||
13 years ago
|
hostname = hostname if hostname else 'localhost',
|
||
|
password = password if password else None,
|
||
|
port = port if port else 23053
|
||
13 years ago
|
)
|
||
|
self.growl.register()
|
||
|
self.registered = True
|
||
11 years ago
|
except Exception as e:
|
||
13 years ago
|
if 'timed out' in str(e):
|
||
|
self.registered = True
|
||
|
else:
|
||
|
log.error('Failed register of growl: %s', traceback.format_exc())
|
||
14 years ago
|
|
||
12 years ago
|
def notify(self, message = '', data = None, listener = None):
|
||
|
if not data: data = {}
|
||
14 years ago
|
|
||
13 years ago
|
self.register()
|
||
|
|
||
14 years ago
|
try:
|
||
|
self.growl.notify(
|
||
|
noteType = "Updates",
|
||
|
title = self.default_title,
|
||
|
description = message,
|
||
|
sticky = False,
|
||
|
priority = 1,
|
||
|
)
|
||
14 years ago
|
|
||
|
log.info('Growl notifications sent.')
|
||
14 years ago
|
return True
|
||
|
except:
|
||
|
log.error('Failed growl notification.')
|
||
|
|
||
|
return False
|
||
|
|
||
11 years ago
|
|
||
|
config = [{
|
||
|
'name': 'growl',
|
||
|
'groups': [
|
||
|
{
|
||
|
'tab': 'notifications',
|
||
|
'list': 'notification_providers',
|
||
|
'name': 'growl',
|
||
|
'description': 'Version 1.4+',
|
||
|
'options': [
|
||
|
{
|
||
|
'name': 'enabled',
|
||
|
'default': 0,
|
||
|
'type': 'enabler',
|
||
|
},
|
||
|
{
|
||
|
'name': 'on_snatch',
|
||
|
'default': False,
|
||
|
'type': 'bool',
|
||
|
'advanced': True,
|
||
|
'description': 'Also send message when movie is snatched.',
|
||
|
},
|
||
|
{
|
||
|
'name': 'hostname',
|
||
|
'description': 'Notify growl over network. Needs restart.',
|
||
|
'advanced': True,
|
||
|
},
|
||
|
{
|
||
|
'name': 'port',
|
||
|
'type': 'int',
|
||
|
'advanced': True,
|
||
|
},
|
||
|
{
|
||
|
'name': 'password',
|
||
|
'type': 'password',
|
||
|
'advanced': True,
|
||
|
},
|
||
|
],
|
||
|
}
|
||
|
],
|
||
|
}]
|