Notification update
This commit is contained in:
@@ -1,20 +1,47 @@
|
||||
from couchpotato.api import addApiView
|
||||
from couchpotato.core.event import addEvent
|
||||
from couchpotato.core.helpers.request import jsonified
|
||||
from couchpotato.core.logger import CPLog
|
||||
from couchpotato.core.plugins.base import Plugin
|
||||
|
||||
log = CPLog(__name__)
|
||||
|
||||
|
||||
class Notification(Plugin):
|
||||
|
||||
default_title = 'CouchPotato'
|
||||
test_message = 'ZOMG Lazors Pewpewpew!'
|
||||
|
||||
listen_to = []
|
||||
dont_listen_to = []
|
||||
|
||||
def __init__(self):
|
||||
addEvent('notify', self.notify)
|
||||
addEvent('notify.%s' % self.getName().lower(), self.notify)
|
||||
|
||||
def notify(self, message = '', data = {}):
|
||||
addApiView(self.testNotifyName(), self.test)
|
||||
|
||||
def notify(self, message = '', data = {}, type = ''):
|
||||
pass
|
||||
|
||||
def test(self):
|
||||
success = self.notify(message = self.test_message)
|
||||
|
||||
return jsonified({'success': success})
|
||||
test_type = self.testNotifyName()
|
||||
|
||||
log.info('Sending test to %s' % test_type)
|
||||
|
||||
success = self.notify(
|
||||
message = self.test_message,
|
||||
data = {},
|
||||
type = test_type
|
||||
)
|
||||
|
||||
#return jsonified({'success': success})
|
||||
|
||||
def dontNotify(self, type = ''):
|
||||
return (not type in self.listen_to and len(self.listen_to) == 0 and type != self.testNotifyName()) \
|
||||
or type in self.dont_listen_to \
|
||||
or self.isDisabled()
|
||||
|
||||
def testNotifyName(self):
|
||||
return 'notify.%s.test' % self.getName().lower()
|
||||
|
||||
@@ -2,13 +2,13 @@ from couchpotato.api import addApiView
|
||||
from couchpotato.core.event import addEvent, fireEvent
|
||||
from couchpotato.core.helpers.request import jsonified
|
||||
from couchpotato.core.logger import CPLog
|
||||
from couchpotato.core.plugins.base import Plugin
|
||||
from couchpotato.core.notifications.base import Notification
|
||||
import time
|
||||
|
||||
log = CPLog(__name__)
|
||||
|
||||
|
||||
class CoreNotifier(Plugin):
|
||||
class CoreNotifier(Notification):
|
||||
|
||||
messages = []
|
||||
|
||||
@@ -22,7 +22,7 @@ class CoreNotifier(Plugin):
|
||||
static = self.registerStatic(__file__)
|
||||
fireEvent('register_script', static + 'notification.js')
|
||||
|
||||
def notify(self, message = '', data = {}):
|
||||
def notify(self, message = '', data = {}, type = None):
|
||||
self.add(data = {
|
||||
'message': message,
|
||||
'raw': data,
|
||||
|
||||
@@ -12,19 +12,13 @@ log = CPLog(__name__)
|
||||
|
||||
class Growl(Notification):
|
||||
|
||||
def __init__(self):
|
||||
addEvent('notify', self.notify)
|
||||
addEvent('notify.growl', self.notify)
|
||||
|
||||
addApiView('notify.growl.test', self.test)
|
||||
listen_to = ['movie.downloaded', 'movie.snatched']
|
||||
|
||||
def conf(self, attr):
|
||||
return Env.setting(attr, 'growl')
|
||||
|
||||
def notify(self, message = '', data = {}):
|
||||
|
||||
if self.isDisabled():
|
||||
return
|
||||
def notify(self, message = '', data = {}, type = None):
|
||||
if self.dontNotify(type): return
|
||||
|
||||
hosts = [x.strip() for x in self.conf('host').split(",")]
|
||||
password = self.conf('password')
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
from .main import History
|
||||
|
||||
def start():
|
||||
return History()
|
||||
|
||||
config = []
|
||||
@@ -0,0 +1,33 @@
|
||||
from couchpotato import get_session
|
||||
from couchpotato.core.event import addEvent
|
||||
from couchpotato.core.logger import CPLog
|
||||
from couchpotato.core.notifications.base import Notification
|
||||
from couchpotato.core.settings.model import History as Hist
|
||||
import time
|
||||
|
||||
log = CPLog(__name__)
|
||||
|
||||
|
||||
class History(Notification):
|
||||
|
||||
listen_to = ['movie.downloaded', 'movie.snatched', 'movie.renaming.']
|
||||
|
||||
def __init__(self):
|
||||
|
||||
addEvent('notify', self.notify)
|
||||
|
||||
addEvent('app.load', self.test)
|
||||
|
||||
|
||||
def notify(self, message = '', data = {}, type = None):
|
||||
if self.dontNotify(type): return
|
||||
|
||||
db = get_session()
|
||||
history = Hist(
|
||||
added = int(time.time()),
|
||||
message = message,
|
||||
type = type,
|
||||
release_id = data.get('id', 0)
|
||||
)
|
||||
db.add(history)
|
||||
db.commit()
|
||||
@@ -1,5 +1,4 @@
|
||||
from couchpotato.api import addApiView
|
||||
from couchpotato.core.event import addEvent
|
||||
from couchpotato.core.helpers.request import getParams, jsonified
|
||||
from couchpotato.core.logger import CPLog
|
||||
from couchpotato.core.notifications.base import Notification
|
||||
@@ -19,11 +18,11 @@ log = CPLog(__name__)
|
||||
|
||||
class NMJ(Notification):
|
||||
|
||||
def __init__(self):
|
||||
addEvent('notify', self.notify)
|
||||
addEvent('notify.nmj', self.notify)
|
||||
listen_to = ['movie.downloaded', 'movie.snatched']
|
||||
|
||||
def __init__(self):
|
||||
super(NMJ, self).__init__()
|
||||
|
||||
addApiView('notify.nmj.test', self.test)
|
||||
addApiView('notify.nmj.auto_config', self.autoConfig)
|
||||
|
||||
def conf(self, attr):
|
||||
@@ -76,10 +75,8 @@ class NMJ(Notification):
|
||||
'mount': mount,
|
||||
})
|
||||
|
||||
def notify(self, message = '', data = {}):
|
||||
|
||||
if self.isDisabled():
|
||||
return False
|
||||
def notify(self, message = '', data = {}, type = None):
|
||||
if self.dontNotify(type): return
|
||||
|
||||
host = self.conf('host')
|
||||
mount = self.conf('mount')
|
||||
|
||||
@@ -16,19 +16,13 @@ class Notifo(Notification):
|
||||
|
||||
url = 'https://api.notifo.com/v1/send_notification'
|
||||
|
||||
def __init__(self):
|
||||
addEvent('notify', self.notify)
|
||||
addEvent('notify.notifo', self.notify)
|
||||
|
||||
addApiView('notify.notifo.test', self.test)
|
||||
listen_to = ['movie.downloaded', 'movie.snatched']
|
||||
|
||||
def conf(self, attr):
|
||||
return Env.setting(attr, 'notifo')
|
||||
|
||||
def notify(self, message = '', data = {}):
|
||||
|
||||
if self.isDisabled():
|
||||
return False
|
||||
def notify(self, message = '', data = {}, type = None):
|
||||
if self.dontNotify(type): return
|
||||
|
||||
try:
|
||||
data = urllib.urlencode({
|
||||
|
||||
@@ -10,16 +10,10 @@ log = CPLog(__name__)
|
||||
|
||||
class Plex(Notification):
|
||||
|
||||
def __init__(self):
|
||||
addEvent('notify', self.notify)
|
||||
addEvent('notify.plex', self.notify)
|
||||
listen_to = ['movie.downloaded', 'movie.snatched']
|
||||
|
||||
addApiView('notify.plex.test', self.test)
|
||||
|
||||
def notify(self, message = '', data = {}):
|
||||
|
||||
if self.isDisabled():
|
||||
return
|
||||
def notify(self, message = '', data = {}, type = None):
|
||||
if self.dontNotify(type): return
|
||||
|
||||
log.info('Sending notification to Plex')
|
||||
hosts = [x.strip() for x in self.conf('host').split(",")]
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
from couchpotato.api import addApiView
|
||||
from couchpotato.core.event import addEvent
|
||||
from couchpotato.core.helpers.encoding import toUnicode
|
||||
from couchpotato.core.logger import CPLog
|
||||
from couchpotato.core.notifications.base import Notification
|
||||
@@ -11,16 +9,10 @@ log = CPLog(__name__)
|
||||
|
||||
class Prowl(Notification):
|
||||
|
||||
def __init__(self):
|
||||
addEvent('notify', self.notify)
|
||||
addEvent('notify.prowl', self.notify)
|
||||
listen_to = ['movie.downloaded', 'movie.snatched']
|
||||
|
||||
addApiView('notify.prowl.test', self.test)
|
||||
|
||||
def notify(self, message = '', data = {}):
|
||||
|
||||
if self.isDisabled():
|
||||
return
|
||||
def notify(self, message = '', data = {}, type = None):
|
||||
if self.dontNotify(type): return
|
||||
|
||||
http_handler = HTTPSConnection('api.prowlapp.com')
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
from couchpotato.api import addApiView
|
||||
from couchpotato.core.event import addEvent
|
||||
from couchpotato.core.logger import CPLog
|
||||
from couchpotato.core.notifications.base import Notification
|
||||
import base64
|
||||
@@ -11,16 +9,10 @@ log = CPLog(__name__)
|
||||
|
||||
class XBMC(Notification):
|
||||
|
||||
def __init__(self):
|
||||
addEvent('notify', self.notify)
|
||||
addEvent('notify.xbmc', self.notify)
|
||||
listen_to = ['movie.downloaded', 'movie.snatched']
|
||||
|
||||
addApiView('notify.xbmc.test', self.test)
|
||||
|
||||
def notify(self, message = '', data = {}):
|
||||
|
||||
if self.isDisabled():
|
||||
return
|
||||
def notify(self, message = '', data = {}, type = None):
|
||||
if self.dontNotify(type): return
|
||||
|
||||
for host in [x.strip() for x in self.conf('host').split(",")]:
|
||||
self.send({'command': 'ExecBuiltIn', 'parameter': 'Notification(CouchPotato, %s)' % message}, host)
|
||||
|
||||
@@ -5,7 +5,7 @@ import os.path
|
||||
import re
|
||||
|
||||
|
||||
class Plugin():
|
||||
class Plugin(object):
|
||||
|
||||
def conf(self, attr, default = None):
|
||||
return Env.setting(attr, self.getName().lower(), default = default)
|
||||
@@ -35,4 +35,4 @@ class Plugin():
|
||||
return not self.isEnabled()
|
||||
|
||||
def isEnabled(self):
|
||||
return self.conf('enabled')
|
||||
return self.conf('enabled') or self.conf('enabled') == None
|
||||
|
||||
@@ -149,6 +149,10 @@ class Renamer(Plugin):
|
||||
if multiple:
|
||||
cd += 1
|
||||
|
||||
# Notify on download
|
||||
download_message = 'Download of %s (%s) successful.' % (group['library']['titles'][0]['title'], replacements['quality'])
|
||||
fireEvent('notify', type = 'movie.downloaded', message = download_message, data = replacements)
|
||||
|
||||
# Before renaming, remove the lower quality files
|
||||
db = get_session()
|
||||
library = db.query(Library).filter_by(identifier = group['library']['identifier']).first()
|
||||
@@ -172,6 +176,10 @@ class Renamer(Plugin):
|
||||
for rename_me in rename_files:
|
||||
filename = os.path.basename(rename_me)
|
||||
rename_files[rename_me] = rename_me.replace(filename, '_EXISTS_%s' % filename)
|
||||
|
||||
# Notify on rename fail
|
||||
download_message = 'Renaming of %s (%s) canceled, exists in %s already.' % (movie.library.titles[0].title, group['meta_data']['quality']['label'], release.quality.label)
|
||||
fireEvent('notify', type = 'movie.renaming.canceled', message = download_message, data = group)
|
||||
|
||||
break
|
||||
|
||||
@@ -200,7 +208,7 @@ class Renamer(Plugin):
|
||||
|
||||
#print rename_me, rename_files[rename_me]
|
||||
|
||||
# Search for trailers
|
||||
# Search for trailers etc
|
||||
fireEvent('renamer.after', group)
|
||||
|
||||
def moveFile(self, old, dest, suppress = True):
|
||||
|
||||
@@ -91,7 +91,6 @@ class Searcher(Plugin):
|
||||
successful = fireEvent('download', data = nzb, movie = movie, single = True)
|
||||
|
||||
if successful:
|
||||
log.info('Downloading of %s successful.' % nzb.get('name'))
|
||||
|
||||
# Mark release as snatched
|
||||
db = get_session()
|
||||
@@ -105,6 +104,9 @@ class Searcher(Plugin):
|
||||
mvie.status_id = snatched_status.get('id')
|
||||
db.commit()
|
||||
|
||||
log.info('Downloading of %s successful.' % nzb.get('name'))
|
||||
fireEvent('notify', type = 'movie.snatched', message = 'Downloading of %s successful.' % nzb.get('name'), data = rls.to_dict())
|
||||
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
@@ -2,8 +2,8 @@ from elixir.entity import Entity
|
||||
from elixir.fields import Field
|
||||
from elixir.options import options_defaults
|
||||
from elixir.relationships import OneToMany, ManyToOne
|
||||
from libs.elixir.options import using_options
|
||||
from libs.elixir.relationships import ManyToMany
|
||||
from elixir.options import using_options
|
||||
from elixir.relationships import ManyToMany
|
||||
from sqlalchemy.types import Integer, Unicode, UnicodeText, Boolean, Float, \
|
||||
String
|
||||
|
||||
@@ -179,7 +179,10 @@ class History(Entity):
|
||||
"""History of actions that are connected to a certain release,
|
||||
such as, renamed to, downloaded, deleted, download subtitles etc"""
|
||||
|
||||
added = Field(Integer)
|
||||
message = Field(UnicodeText())
|
||||
type = Field(Unicode(50))
|
||||
|
||||
release = ManyToOne('Release')
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user