From 3a00c7a79ad68707885b9e5d6891ea1d27c64088 Mon Sep 17 00:00:00 2001 From: NovaXeros Date: Tue, 8 Apr 2014 02:02:50 +0100 Subject: [PATCH 1/6] Add Logitech Media Server stuff --- headphones/__init__.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/headphones/__init__.py b/headphones/__init__.py index 8a4637bc..2e313147 100644 --- a/headphones/__init__.py +++ b/headphones/__init__.py @@ -229,6 +229,8 @@ XBMC_USERNAME = None XBMC_PASSWORD = None XBMC_UPDATE = False XBMC_NOTIFY = False +LMS_ENABLED = False +LMS_HOST = None PLEX_ENABLED = False PLEX_SERVER_HOST = None PLEX_CLIENT_HOST = None @@ -342,7 +344,7 @@ def initialize(): TWITTER_ENABLED, TWITTER_ONSNATCH, TWITTER_USERNAME, TWITTER_PASSWORD, TWITTER_PREFIX, \ PUSHBULLET_ENABLED, PUSHBULLET_APIKEY, PUSHBULLET_DEVICEID, PUSHBULLET_ONSNATCH, \ MIRROR, CUSTOMHOST, CUSTOMPORT, CUSTOMSLEEP, HPUSER, HPPASS, XBMC_ENABLED, XBMC_HOST, XBMC_USERNAME, XBMC_PASSWORD, XBMC_UPDATE, \ - XBMC_NOTIFY, NMA_ENABLED, NMA_APIKEY, NMA_PRIORITY, NMA_ONSNATCH, SYNOINDEX_ENABLED, ALBUM_COMPLETION_PCT, PREFERRED_BITRATE_HIGH_BUFFER, \ + XBMC_NOTIFY, LMS_ENABLED, LMS_HOST, NMA_ENABLED, NMA_APIKEY, NMA_PRIORITY, NMA_ONSNATCH, SYNOINDEX_ENABLED, ALBUM_COMPLETION_PCT, PREFERRED_BITRATE_HIGH_BUFFER, \ PREFERRED_BITRATE_LOW_BUFFER, PREFERRED_BITRATE_ALLOW_LOSSLESS, CACHE_SIZEMB, JOURNAL_MODE, UMASK, ENABLE_HTTPS, HTTPS_CERT, HTTPS_KEY, \ PLEX_ENABLED, PLEX_SERVER_HOST, PLEX_CLIENT_HOST, PLEX_USERNAME, PLEX_PASSWORD, PLEX_UPDATE, PLEX_NOTIFY, PUSHALOT_ENABLED, PUSHALOT_APIKEY, \ PUSHALOT_ONSNATCH, SONGKICK_ENABLED, SONGKICK_APIKEY, SONGKICK_LOCATION, SONGKICK_FILTER_ENABLED @@ -369,6 +371,7 @@ def initialize(): CheckSection('Pushover') CheckSection('PushBullet') CheckSection('XBMC') + CheckSection('LMS') CheckSection('Plex') CheckSection('NMA') CheckSection('Pushalot') @@ -548,6 +551,9 @@ def initialize(): XBMC_UPDATE = bool(check_setting_int(CFG, 'XBMC', 'xbmc_update', 0)) XBMC_NOTIFY = bool(check_setting_int(CFG, 'XBMC', 'xbmc_notify', 0)) + LMS_ENABLED = bool(check_setting_int(CFG, 'LMS', 'lms_enabled', 0)) + LMS_HOST = check_setting_str(CFG, 'LMS', 'lms_host', '') + PLEX_ENABLED = bool(check_setting_int(CFG, 'Plex', 'plex_enabled', 0)) PLEX_SERVER_HOST = check_setting_str(CFG, 'Plex', 'plex_server_host', '') PLEX_CLIENT_HOST = check_setting_str(CFG, 'Plex', 'plex_client_host', '') @@ -942,6 +948,10 @@ def config_write(): new_config['XBMC']['xbmc_update'] = int(XBMC_UPDATE) new_config['XBMC']['xbmc_notify'] = int(XBMC_NOTIFY) + new_config['LMS'] = {} + new_config['LMS']['lms_enabled'] = int(LMS_ENABLED) + new_config['LMS']['lms_host'] = LMS_HOST + new_config['Plex'] = {} new_config['Plex']['plex_enabled'] = int(PLEX_ENABLED) new_config['Plex']['plex_server_host'] = PLEX_SERVER_HOST From 856bed9337c1b2a21bcff0f72e0a75f3c9216e60 Mon Sep 17 00:00:00 2001 From: NovaXeros Date: Tue, 8 Apr 2014 02:03:53 +0100 Subject: [PATCH 2/6] Add checks for LMS Enabled or not, and act upon it --- headphones/postprocessor.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/headphones/postprocessor.py b/headphones/postprocessor.py index 492b69c0..6d1b037a 100644 --- a/headphones/postprocessor.py +++ b/headphones/postprocessor.py @@ -419,7 +419,11 @@ def doPostProcessing(albumid, albumpath, release, tracks, downloaded_track_list, xbmc.update() if headphones.XBMC_NOTIFY: xbmc.notify(release['ArtistName'], release['AlbumTitle'], album_art_path) - + + if headphones.LMS_ENABLED: + lms = notifiers.LMS() + lms.update() + if headphones.PLEX_ENABLED: plex = notifiers.Plex() if headphones.PLEX_UPDATE: From a43df2b27573ce9f4d355d70f08ee1b6c374422b Mon Sep 17 00:00:00 2001 From: NovaXeros Date: Tue, 8 Apr 2014 02:04:53 +0100 Subject: [PATCH 3/6] Add class and functions for updating an LMS server --- headphones/notifiers.py | 45 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/headphones/notifiers.py b/headphones/notifiers.py index 3da78a6e..4db68ee4 100644 --- a/headphones/notifiers.py +++ b/headphones/notifiers.py @@ -192,6 +192,51 @@ class XBMC: except: logger.warn('Error sending notification request to XBMC') +class LMS: + +#Class for updating a Logitech Media Server + + def __init__(self): + + self.hosts = headphones.LMS_HOST + + def _sendjson(self, host): + data = {'id': 1, 'method': 'slim.request', 'params': ["",["rescan"]]} #Had a lot of trouble with simplejson, but this works. + data = simplejson.JSONEncoder().encode(data) + + content = {'Content-Type': 'application/json', 'Content-Length': len(data)} + + req = urllib2.Request(host+'/jsonrpc.js', data, content) + + try: + handle = urllib2.urlopen(req) + except Exception, e: + logger.warn('Error opening LMS url: %s' % e) + return + + response = simplejson.JSONDecoder().decode(handle.read()) + server_result = simplejson.dumps(response) + + try: + return response[0]['result'] + except: + logger.warn('LMS returned error: %s' % response[0]['error']) + return + + def update(self): + + #Send the ["rescan"] command to an LMS server. + #Note that the command must be prefixed with the 'player' that the command is aimed at, + #But with this being a request for the server to update its library, the player is blank, so "" + + hosts = [x.strip() for x in self.hosts.split(',')] + + for host in hosts: + logger.info('Sending library rescan command to LMS @ '+host) + request = self._sendjson(host) + + if not request: + logger.warn('Error sending rescan request to LMS') class Plex: From 9416d185e7b7725417a564b178f5f1e9a379526f Mon Sep 17 00:00:00 2001 From: NovaXeros Date: Tue, 8 Apr 2014 02:07:28 +0100 Subject: [PATCH 4/6] Added LMS config options --- data/interfaces/default/config.html | 33 +++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/data/interfaces/default/config.html b/data/interfaces/default/config.html index 486f79f7..697830d8 100644 --- a/data/interfaces/default/config.html +++ b/data/interfaces/default/config.html @@ -644,6 +644,19 @@ +
+

LMS

+
+ +
+
+
+ + + e.g. http://localhost:9000. Seperate hosts with commas +
+
+
@@ -1217,6 +1230,26 @@ } }); + if ($("#lms").is(":checked")) + { + $("#lmsoptions").show(); + } + else + { + $("#lmsoptions").hide(); + } + + $("#lms").click(function(){ + if ($("#lms").is(":checked")) + { + $("#lmsoptions").slideDown(); + } + else + { + $("#lmsoptions").slideUp(); + } + }); + if ($("#plex").is(":checked")) { $("#plexoptions").show(); From 001404d5c4a65dd0e5143cf72e60272336a8b2eb Mon Sep 17 00:00:00 2001 From: NovaXeros Date: Tue, 8 Apr 2014 02:08:46 +0100 Subject: [PATCH 5/6] Update webserve.py --- headphones/webserve.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/headphones/webserve.py b/headphones/webserve.py index ca8ad578..b02c52ac 100644 --- a/headphones/webserve.py +++ b/headphones/webserve.py @@ -941,6 +941,8 @@ class WebInterface(object): "xbmc_password": headphones.XBMC_PASSWORD, "xbmc_update": checked(headphones.XBMC_UPDATE), "xbmc_notify": checked(headphones.XBMC_NOTIFY), + "lms_enabled": checked(headphones.LMS_ENABLED), + "lms_host": headphones.LMS_HOST, "plex_enabled": checked(headphones.PLEX_ENABLED), "plex_server_host": headphones.PLEX_SERVER_HOST, "plex_client_host": headphones.PLEX_CLIENT_HOST, @@ -1011,7 +1013,7 @@ class WebInterface(object): remix=0, spokenword=0, audiobook=0, autowant_upcoming=False, autowant_all=False, keep_torrent_files=False, interface=None, log_dir=None, cache_dir=None, music_encoder=0, encoder=None, xldprofile=None, bitrate=None, samplingfrequency=None, encoderfolder=None, advancedencoder=None, encoderoutputformat=None, encodervbrcbr=None, encoderquality=None, encoderlossless=0, delete_lossless_files=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, nma_onsnatch=0, pushalot_enabled=False, pushalot_apikey=None, pushalot_onsnatch=0, synoindex_enabled=False, + xbmc_update=0, xbmc_notify=0, lms_enabled=0, lms_host=None, nma_enabled=False, nma_apikey=None, nma_priority=0, nma_onsnatch=0, pushalot_enabled=False, pushalot_apikey=None, pushalot_onsnatch=0, synoindex_enabled=False, pushover_enabled=0, pushover_onsnatch=0, pushover_keys=None, pushover_priority=0, pushbullet_enabled=0, pushbullet_onsnatch=0, pushbullet_apikey=None, pushbullet_deviceid=None, twitter_enabled=0, twitter_onsnatch=0, mirror=None, customhost=None, customport=None, customsleep=None, hpuser=None, hppass=None, preferred_bitrate_high_buffer=None, preferred_bitrate_low_buffer=None, preferred_bitrate_allow_lossless=0, cache_sizemb=None, enable_https=0, https_cert=None, https_key=None, file_permissions=None, folder_permissions=None, plex_enabled=0, plex_server_host=None, plex_client_host=None, plex_username=None, @@ -1134,6 +1136,8 @@ class WebInterface(object): headphones.XBMC_PASSWORD = xbmc_password headphones.XBMC_UPDATE = xbmc_update headphones.XBMC_NOTIFY = xbmc_notify + headphones.LMS_ENABLED = lms_enabled + headphones.LMS_HOST = lms_host headphones.PLEX_ENABLED = plex_enabled headphones.PLEX_SERVER_HOST = plex_server_host headphones.PLEX_CLIENT_HOST = plex_client_host From aab4461ab65f1dc94e0b6037122108b1245c7a89 Mon Sep 17 00:00:00 2001 From: NovaXeros Date: Tue, 8 Apr 2014 12:24:09 +0100 Subject: [PATCH 6/6] Added a User-Agent to PirateBay searching. --- headphones/searcher.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/headphones/searcher.py b/headphones/searcher.py index bb7fadda..a07e67da 100644 --- a/headphones/searcher.py +++ b/headphones/searcher.py @@ -1147,7 +1147,8 @@ def searchTorrent(albumid=None, new=False, losslessOnly=False): # Pirate Bay if headphones.PIRATEBAY: - provider = "The Pirate Bay" + provider = "The Pirate Bay" + headers = { 'User-Agent' : 'Mozilla/5.0 (Linux; Android 4.1.1; Nexus 7 Build/JRO03D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Safari/535.19' } if headphones.PIRATEBAY_PROXY_URL: #Might need to clean up the user submitted url pirate_proxy = headphones.PIRATEBAY_PROXY_URL @@ -1175,7 +1176,8 @@ def searchTorrent(albumid=None, new=False, losslessOnly=False): searchURL = providerurl + category try: - data = urllib2.urlopen(searchURL, timeout=20).read() + tpbreq = urllib2.Request(searchURL, '', headers) + data = urllib2.urlopen(tpbreq, timeout=20).read() except urllib2.URLError, e: logger.warn('Error fetching data from The Pirate Bay: %s' % e) data = False