diff --git a/couchpotato/core/notifications/synoindex/__init__.py b/couchpotato/core/notifications/synoindex/__init__.py new file mode 100644 index 0000000..af47623 --- /dev/null +++ b/couchpotato/core/notifications/synoindex/__init__.py @@ -0,0 +1,22 @@ +from .main import Synoindex + +def start(): + return Synoindex() + +config = [{ + 'name': 'synoindex', + 'groups': [ + { + 'tab': 'notifications', + 'name': 'synoindex', + 'description': 'Automaticly adds index to Synology Media Server.', + 'options': [ + { + 'name': 'enabled', + 'default': 0, + 'type': 'enabler', + } + ], + } + ], +}] diff --git a/couchpotato/core/notifications/synoindex/main.py b/couchpotato/core/notifications/synoindex/main.py new file mode 100644 index 0000000..d866a24 --- /dev/null +++ b/couchpotato/core/notifications/synoindex/main.py @@ -0,0 +1,27 @@ +from couchpotato.core.event import addEvent +from couchpotato.core.logger import CPLog +from couchpotato.core.notifications.base import Notification +import subprocess + +log = CPLog(__name__) + + +class Synoindex(Notification): + + def __init__(self): + addEvent('renamer.after', self.addToLibrary) + + def addToLibrary(self, group = {}): + + command = ['/usr/syno/bin/synoindex', '-A', group.get('destination_dir')] + log.info(u'Executing synoindex command: %s ' % command) + try: + p = subprocess.Popen(command, stdout = subprocess.PIPE, stderr = subprocess.STDOUT) + out = p.communicate() + log.info('Result from synoindex: %s' % out) + return True + except OSError, e: + log.error('Unable to run synoindex: %s' % e) + return False + + return True