From df42d08fd1a1be3a761897f56691732ded0ad2de Mon Sep 17 00:00:00 2001 From: Aaron Cohen Date: Tue, 10 Jul 2012 00:56:25 -0700 Subject: [PATCH] Adding synology NAS indexing support --- data/interfaces/default/config.html | 9 +++++++- headphones/__init__.py | 7 +++++- headphones/notifiers.py | 36 +++++++++++++++++++++++++++++ headphones/postprocessor.py | 4 ++++ headphones/webserve.py | 4 +++- 5 files changed, 57 insertions(+), 3 deletions(-) diff --git a/data/interfaces/default/config.html b/data/interfaces/default/config.html index e9f36b2c..e00d3c8a 100644 --- a/data/interfaces/default/config.html +++ b/data/interfaces/default/config.html @@ -578,7 +578,14 @@ - + +
+

Synology NAS

+
+ +
+
+
Musicbrainz
diff --git a/headphones/__init__.py b/headphones/__init__.py index 3c9196fc..3d81e2a7 100644 --- a/headphones/__init__.py +++ b/headphones/__init__.py @@ -173,6 +173,7 @@ XBMC_NOTIFY = False NMA_ENABLED = False NMA_APIKEY = None NMA_PRIORITY = None +SYNOINDEX_ENABLED = False MIRRORLIST = ["musicbrainz.org","headphones","custom"] MIRROR = None CUSTOMHOST = None @@ -242,7 +243,7 @@ def initialize(): NZBSORG, NZBSORG_UID, NZBSORG_HASH, NEWZBIN, NEWZBIN_UID, NEWZBIN_PASSWORD, LASTFM_USERNAME, INTERFACE, FOLDER_PERMISSIONS, \ ENCODERFOLDER, ENCODER, BITRATE, SAMPLINGFREQUENCY, MUSIC_ENCODER, ADVANCEDENCODER, ENCODEROUTPUTFORMAT, ENCODERQUALITY, ENCODERVBRCBR, \ ENCODERLOSSLESS, PROWL_ENABLED, PROWL_PRIORITY, PROWL_KEYS, PROWL_ONSNATCH, MIRRORLIST, MIRROR, CUSTOMHOST, CUSTOMPORT, \ - CUSTOMSLEEP, HPUSER, HPPASS, XBMC_ENABLED, XBMC_HOST, XBMC_USERNAME, XBMC_PASSWORD, XBMC_UPDATE, XBMC_NOTIFY, NMA_ENABLED, NMA_APIKEY, NMA_PRIORITY + CUSTOMSLEEP, HPUSER, HPPASS, XBMC_ENABLED, XBMC_HOST, XBMC_USERNAME, XBMC_PASSWORD, XBMC_UPDATE, XBMC_NOTIFY, NMA_ENABLED, NMA_APIKEY, NMA_PRIORITY, SYNOINDEX_ENABLED if __INITIALIZED__: return False @@ -258,6 +259,7 @@ def initialize(): CheckSection('Prowl') CheckSection('XBMC') CheckSection('NMA') + CheckSection('Synoindex') # Set global variables based on config file or use defaults CONFIG_VERSION = check_setting_str(CFG, 'General', 'config_version', '0') @@ -633,6 +635,9 @@ def config_write(): new_config['NMA']['nma_enabled'] = int(NMA_ENABLED) new_config['NMA']['nma_apikey'] = NMA_APIKEY new_config['NMA']['nma_priority'] = NMA_PRIORITY + + new_config['Synoindex'] = {} + new_config['Synoindex']['synoindex_enabled'] = int(SYNOINDEX_ENABLED) new_config['General']['lastfm_username'] = LASTFM_USERNAME new_config['General']['interface'] = INTERFACE diff --git a/headphones/notifiers.py b/headphones/notifiers.py index 695796d0..ae04fe99 100644 --- a/headphones/notifiers.py +++ b/headphones/notifiers.py @@ -21,6 +21,8 @@ import urllib2 import headphones from httplib import HTTPSConnection from urllib import urlencode +import os.path +import subprocess class PROWL: @@ -186,3 +188,37 @@ class NMA: if not request: logger.warn('Error sending notification request to NotifyMyAndroid') + +class Synoindex: + def __init__(self, util_loc='/usr/syno/bin/synoindex'): + self.util_loc = util_loc + + def util_exists(self): + return os.path.exists(self.util_loc) + + def notify(self, path): + if not self.util_exists(): + logger.warn("Error sending notification: synoindex utility not found at %s" % self.util_loc) + return + + if os.path.isfile(path): + cmd_arg = '-a' + elif os.path.isdir(path): + cmd_arg = '-A' + else: + logger.warn("Error sending notification: Path passed to synoindex was not a file or folder.") + return + + cmd = [self.util_loc, cmd_arg, '\"%s\"' % os.path.abspath(path)] + logger.debug("Calling synoindex command: %s" % str(cmd)) + try: + p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=headphones.PROG_DIR) + out, error = p.communicate() + logger.debug("Synoindex result: %s" % str(out)) + except OSError, e: + logger.warn("Error sending notification: %s" % str(e)) + + def notify_multiple(self, path_list): + if isinstance(path_list, list): + for path in path_list: + self.notify(path) \ No newline at end of file diff --git a/headphones/postprocessor.py b/headphones/postprocessor.py index 70b19288..5bf44dc1 100644 --- a/headphones/postprocessor.py +++ b/headphones/postprocessor.py @@ -294,6 +294,10 @@ def doPostProcessing(albumid, albumpath, release, tracks, downloaded_track_list) if headphones.NMA_ENABLED: nma = notifiers.NMA() nma.notify(release['ArtistName'], release['AlbumTitle']) + + if headphones.SYNOINDEX_ENABLED: + syno = notifiers.Synoindex() + syno.notify(albumpath) def embedAlbumArt(artwork, downloaded_track_list): logger.info('Embedding album art') diff --git a/headphones/webserve.py b/headphones/webserve.py index c477888e..bcced9eb 100644 --- a/headphones/webserve.py +++ b/headphones/webserve.py @@ -441,6 +441,7 @@ class WebInterface(object): "nma_enabled": checked(headphones.NMA_ENABLED), "nma_apikey": headphones.NMA_APIKEY, "nma_priority": int(headphones.NMA_PRIORITY), + "synoindex_enabled": checked(headphones.SYNOINDEX_ENABLED), "mirror_list": headphones.MIRRORLIST, "mirror": headphones.MIRROR, "customhost": headphones.CUSTOMHOST, @@ -461,7 +462,7 @@ class WebInterface(object): rename_files=0, correct_metadata=0, cleanup_files=0, add_album_art=0, embed_album_art=0, embed_lyrics=0, destination_dir=None, folder_format=None, file_format=None, include_extras=0, autowant_upcoming=False, autowant_all=False, interface=None, log_dir=None, music_encoder=0, encoder=None, bitrate=None, samplingfrequency=None, encoderfolder=None, advancedencoder=None, encoderoutputformat=None, encodervbrcbr=None, encoderquality=None, encoderlossless=0, prowl_enabled=0, prowl_onsnatch=0, prowl_keys=None, prowl_priority=0, xbmc_enabled=0, xbmc_host=None, xbmc_username=None, xbmc_password=None, xbmc_update=0, xbmc_notify=0, - nma_enabled=False, nma_apikey=None, nma_priority=0, mirror=None, customhost=None, customport=None, customsleep=None, hpuser=None, hppass=None): + nma_enabled=False, nma_apikey=None, nma_priority=0, synoindex_enabled=False, mirror=None, customhost=None, customport=None, customsleep=None, hpuser=None, hppass=None): headphones.HTTP_HOST = http_host headphones.HTTP_PORT = http_port @@ -544,6 +545,7 @@ class WebInterface(object): headphones.NMA_ENABLED = nma_enabled headphones.NMA_APIKEY = nma_apikey headphones.NMA_PRIORITY = nma_priority + headphones.SYNOINDEX_ENABLED = synoindex_enabled headphones.MIRROR = mirror headphones.CUSTOMHOST = customhost headphones.CUSTOMPORT = customport