From e97c990f000d8c8f5120eeb13a20bdf0d90be0ce Mon Sep 17 00:00:00 2001 From: sjengfred Date: Sun, 23 Jun 2013 22:19:16 +0200 Subject: [PATCH 1/2] added nzbget support --- data/interfaces/brink/config.html | 42 ++++++++++++++- data/interfaces/classic/config.html | 28 +++++++++- data/interfaces/default/config.html | 25 ++++++++- data/interfaces/remix/config.html | 28 +++++++++- headphones/__init__.py | 19 ++++++- headphones/nzbget.py | 84 +++++++++++++++++++++++++++++ headphones/searcher.py | 15 ++++-- headphones/webserve.py | 10 +++- 8 files changed, 240 insertions(+), 11 deletions(-) create mode 100644 headphones/nzbget.py diff --git a/data/interfaces/brink/config.html b/data/interfaces/brink/config.html index 7ce73c8e..5e7aa91a 100644 --- a/data/interfaces/brink/config.html +++ b/data/interfaces/brink/config.html @@ -187,7 +187,7 @@

uDownload Settings

- Setup SABnzbd or BitTorrent + Setup SABnzbd, NZBGET or BitTorrent
@@ -230,7 +230,7 @@ -
Full path to the directory where SAB downloads your music. +
Full path to the directory where SAB or NZBget downloads your music. @@ -238,6 +238,44 @@
+ +
+ + + + + + + + + + + + + + + + + + + + + +
+

NZBget

+ +
+
Usually http://localhost:9092 +
+
Type the user name for NZBget +
+
Enter the password for NZBget +
+ Write the category label name from NZBget +
+
+ +
diff --git a/data/interfaces/classic/config.html b/data/interfaces/classic/config.html index 88f6554e..0af437c5 100644 --- a/data/interfaces/classic/config.html +++ b/data/interfaces/classic/config.html @@ -116,10 +116,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/data/interfaces/classic/config.html b/data/interfaces/classic/config.html index 0af437c5..eb024f5c 100644 --- a/data/interfaces/classic/config.html +++ b/data/interfaces/classic/config.html @@ -130,7 +130,7 @@

Music Download Directory:


- Full path to the directory where SAB downloads your music
+ Full path to the directory where SAB or NZBget downloads your music
e.g. /Users/name/Downloads/music
+

NZBget:

+
+

NZBget Host:


+ + usually http://localhost:9092 +
+

NZBget Username:

+
+

NZBget Password:

+
+

NZBget Category:

+
diff --git a/data/interfaces/default/config.html b/data/interfaces/default/config.html index 5fc7b026..7d219c5e 100644 --- a/data/interfaces/default/config.html +++ b/data/interfaces/default/config.html @@ -134,10 +134,33 @@
- Full path where SAB downloads your music. e.g. /Users/name/Downloads/music + Full path where SAB or NZBget downloads your music. e.g. /Users/name/Downloads/music
+
+ NZBget +
+ + + usually http://localhost:9092 +
+
+ + +
+
+ + +
+
+ + +
+
+
diff --git a/data/interfaces/remix/config.html b/data/interfaces/remix/config.html index 88f6554e..d03a6a5e 100644 --- a/data/interfaces/remix/config.html +++ b/data/interfaces/remix/config.html @@ -116,10 +116,36 @@

Music Download Directory:


- Full path to the directory where SAB downloads your music
+ Full path to the directory where SAB or NZBget downloads your music
e.g. /Users/name/Downloads/music
+

NZBget:

+
+

NZBget Host:


+ + usually http://localhost:9092 +
+

NZBget Username:

+
+

NZBget Password:

+
+

NZBget Category:

+
diff --git a/headphones/__init__.py b/headphones/__init__.py index 6d555f48..d14e0232 100644 --- a/headphones/__init__.py +++ b/headphones/__init__.py @@ -128,6 +128,11 @@ SAB_PASSWORD = None SAB_APIKEY = None SAB_CATEGORY = None +NZBGET_USERNAME = None +NZBGET_PASSWORD = None +NZBGET_CATEGORY = None +NZBGET_HOST = None + NZBMATRIX = False NZBMATRIX_USERNAME = None NZBMATRIX_APIKEY = None @@ -285,7 +290,7 @@ def initialize(): TORRENTBLACKHOLE_DIR, NUMBEROFSEEDERS, ISOHUNT, KAT, MININOVA, WAFFLES, WAFFLES_UID, WAFFLES_PASSKEY, \ RUTRACKER, RUTRACKER_USER, RUTRACKER_PASSWORD, WHATCD, WHATCD_USERNAME, WHATCD_PASSWORD, DOWNLOAD_TORRENT_DIR, \ LIBRARYSCAN, LIBRARYSCAN_INTERVAL, DOWNLOAD_SCAN_INTERVAL, SAB_HOST, SAB_USERNAME, SAB_PASSWORD, SAB_APIKEY, SAB_CATEGORY, \ - NZBMATRIX, NZBMATRIX_USERNAME, NZBMATRIX_APIKEY, NEWZNAB, NEWZNAB_HOST, NEWZNAB_APIKEY, NEWZNAB_ENABLED, EXTRA_NEWZNABS, \ + NZBGET_USERNAME, NZBGET_PASSWORD, NZBGET_CATEGORY, NZBGET_HOST, NZBMATRIX, NZBMATRIX_USERNAME, NZBMATRIX_APIKEY, NEWZNAB, NEWZNAB_HOST, NEWZNAB_APIKEY, NEWZNAB_ENABLED, EXTRA_NEWZNABS, \ NZBSORG, NZBSORG_UID, NZBSORG_HASH, NEWZBIN, NEWZBIN_UID, NEWZBIN_PASSWORD, NZBSRUS, NZBSRUS_UID, NZBSRUS_APIKEY, NZBX, \ PREFERRED_WORDS, REQUIRED_WORDS, IGNORED_WORDS, \ LASTFM_USERNAME, INTERFACE, FOLDER_PERMISSIONS, ENCODERFOLDER, ENCODER_PATH, ENCODER, XLDPROFILE, BITRATE, SAMPLINGFREQUENCY, \ @@ -302,6 +307,7 @@ def initialize(): # Make sure all the config sections exist CheckSection('General') CheckSection('SABnzbd') + CheckSection('NZBget') CheckSection('NZBMatrix') CheckSection('Newznab') CheckSection('NZBsorg') @@ -407,6 +413,11 @@ def initialize(): SAB_APIKEY = check_setting_str(CFG, 'SABnzbd', 'sab_apikey', '') SAB_CATEGORY = check_setting_str(CFG, 'SABnzbd', 'sab_category', '') + NZBGET_USERNAME = check_setting_str(CFG, 'NZBget', 'nzbget_username', '') + NZBGET_PASSWORD = check_setting_str(CFG, 'NZBget', 'nzbget_password', '') + NZBGET_CATEGORY = check_setting_str(CFG, 'NZBget', 'nzbget_category', '') + NZBGET_HOST = check_setting_str(CFG, 'NZBget', 'nzbget_host', '') + NZBMATRIX = bool(check_setting_int(CFG, 'NZBMatrix', 'nzbmatrix', 0)) NZBMATRIX_USERNAME = check_setting_str(CFG, 'NZBMatrix', 'nzbmatrix_username', '') NZBMATRIX_APIKEY = check_setting_str(CFG, 'NZBMatrix', 'nzbmatrix_apikey', '') @@ -742,6 +753,12 @@ def config_write(): new_config['SABnzbd']['sab_password'] = SAB_PASSWORD new_config['SABnzbd']['sab_apikey'] = SAB_APIKEY new_config['SABnzbd']['sab_category'] = SAB_CATEGORY + + new_config['NZBget'] = {} + new_config['NZBget']['nzbget_username'] = NZBGET_USERNAME + new_config['NZBget']['nzbget_password'] = NZBGET_PASSWORD + new_config['NZBget']['nzbget_category'] = NZBGET_CATEGORY + new_config['NZBget']['nzbget_host'] = NZBGET_HOST new_config['NZBMatrix'] = {} new_config['NZBMatrix']['nzbmatrix'] = int(NZBMATRIX) diff --git a/headphones/nzbget.py b/headphones/nzbget.py new file mode 100644 index 00000000..cd0c3315 --- /dev/null +++ b/headphones/nzbget.py @@ -0,0 +1,84 @@ +# This file is part of Headphones. +# +# Headphones is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Headphones is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Headphones. If not, see . + +##################################### +## Stolen from Sick-Beard's nzbget.py ## +##################################### + + + +import httplib +import datetime + +import headphones + +from base64 import standard_b64encode +import xmlrpclib + +#from headphones.providers.generic import GenericProvider + +from headphones import logger + +def sendNZB(nzb): + + addToTop = False + nzbgetXMLrpc = "http://%(username)s:%(password)s@%(host)s/xmlrpc" + + if headphones.NZBGET_HOST == None: + logger.error(u"No NZBget host found in configuration. Please configure it.") + return False + + url = nzbgetXMLrpc % {"host": headphones.NZBGET_HOST, "username": headphones.NZBGET_USERNAME, "password": headphones.NZBGET_PASSWORD} + + nzbGetRPC = xmlrpclib.ServerProxy(url) + try: + if nzbGetRPC.writelog("INFO", "headphones connected to drop of %s any moment now." % (nzb.name + ".nzb")): + logger.debug(u"Successful connected to NZBget") + else: + logger.error(u"Successful connected to NZBget, but unable to send a message" % (nzb.name + ".nzb")) + + except httplib.socket.error: + logger.error(u"Please check your NZBget host and port (if it is running). NZBget is not responding to this combination") + return False + + except xmlrpclib.ProtocolError, e: + if (e.errmsg == "Unauthorized"): + logger.error(u"NZBget password is incorrect.") + else: + logger.error(u"Protocol Error: " + e.errmsg) + return False + + # if it's a normal result need to download the NZB content + if nzb.resultType == "nzb": + genProvider = GenericProvider("") + data = genProvider.getURL(nzb.url) + if (data == None): + return False + + # if we get a raw data result thats even better + elif nzb.resultType == "nzbdata": + data = nzb.extraInfo[0] + + nzbcontent64 = standard_b64encode(data) + + logger.error(u"Sending NZB to NZBget") + logger.debug(u"URL: " + url) + + if nzbGetRPC.append(nzb.name + ".nzb", headphones.NZBGET_CATEGORY, addToTop, nzbcontent64): + logger.debug(u"NZB sent to NZBget successfully") + return True + else: + logger.error(u"NZBget could not add %s to the queue" % (nzb.name + ".nzb")) + return False diff --git a/headphones/searcher.py b/headphones/searcher.py index 05f7506f..041cb30b 100644 --- a/headphones/searcher.py +++ b/headphones/searcher.py @@ -29,7 +29,7 @@ import os, re, time import string import headphones, exceptions -from headphones import logger, db, helpers, classes, sab +from headphones import logger, db, helpers, classes, sab, nzbget import lib.bencode as bencode @@ -109,7 +109,7 @@ def searchforalbum(albumid=None, new=False, lossless=False): for result in results: foundNZB = "none" - if (headphones.NEWZNAB or headphones.NZBSORG or headphones.NZBX or headphones.NZBSRUS) and (headphones.SAB_HOST or headphones.BLACKHOLE): + if (headphones.NEWZNAB or headphones.NZBSORG or headphones.NZBX or headphones.NZBSRUS) and (headphones.SAB_HOST or headphones.BLACKHOLE or headphones.NZBGET_HOST): if result['Status'] == "Wanted Lossless": foundNZB = searchNZB(result['AlbumID'], new, losslessOnly=True) else: @@ -125,7 +125,7 @@ def searchforalbum(albumid=None, new=False, lossless=False): else: foundNZB = "none" - if (headphones.NZBMATRIX or headphones.NEWZNAB or headphones.NZBSORG or headphones.NEWZBIN or headphones.NZBX or headphones.NZBSRUS) and (headphones.SAB_HOST or headphones.BLACKHOLE): + if (headphones.NZBMATRIX or headphones.NEWZNAB or headphones.NZBSORG or headphones.NEWZBIN or headphones.NZBX or headphones.NZBSRUS) and (headphones.SAB_HOST or headphones.BLACKHOLE or headphones.NZBGET_HOST): foundNZB = searchNZB(albumid, new, lossless) if (headphones.KAT or headphones.ISOHUNT or headphones.MININOVA or headphones.WAFFLES or headphones.RUTRACKER or headphones.WHATCD) and foundNZB == "none": @@ -533,7 +533,14 @@ def searchNZB(albumid=None, new=False, losslessOnly=False): logger.info(u'Found best result: %s - %s' % (bestqual[2], bestqual[0], helpers.bytes_to_mb(bestqual[1]))) # Get rid of any dodgy chars here so we can prevent sab from renaming our downloads nzb_folder_name = helpers.sab_sanitize_foldername(bestqual[0]) - if headphones.SAB_HOST and not headphones.BLACKHOLE: + if headphones.NZBGET_HOST and not headphones.BLACKHOLE and not headphones.SAB_HOST: + + nzb = classes.NZBDataSearchResult() + nzb.extraInfo.append(data) + nzb.name = nzb_folder_name + nzbget.sendNZB(nzb) + + elif headphones.SAB_HOST and not headphones.BLACKHOLE and not headphones.NZBGET_HOST: nzb = classes.NZBDataSearchResult() nzb.extraInfo.append(data) diff --git a/headphones/webserve.py b/headphones/webserve.py index 349e95b1..9e732e6b 100644 --- a/headphones/webserve.py +++ b/headphones/webserve.py @@ -573,6 +573,10 @@ class WebInterface(object): "sab_api" : headphones.SAB_APIKEY, "sab_pass" : headphones.SAB_PASSWORD, "sab_cat" : headphones.SAB_CATEGORY, + "nzbget_host" : headphones.NZBGET_HOST, + "nzbget_user" : headphones.NZBGET_USERNAME, + "nzbget_pass" : headphones.NZBGET_PASSWORD, + "nzbget_cat" : headphones.NZBGET_CATEGORY, "download_dir" : headphones.DOWNLOAD_DIR, "use_blackhole" : checked(headphones.BLACKHOLE), "blackhole_dir" : headphones.BLACKHOLE_DIR, @@ -702,7 +706,7 @@ class WebInterface(object): def configUpdate(self, http_host='0.0.0.0', http_username=None, http_port=8181, http_password=None, launch_browser=0, api_enabled=0, api_key=None, download_scan_interval=None, nzb_search_interval=None, libraryscan_interval=None, sab_host=None, sab_username=None, sab_apikey=None, sab_password=None, - sab_category=None, download_dir=None, blackhole=0, blackhole_dir=None, usenet_retention=None, newznab=0, newznab_host=None, newznab_apikey=None, + sab_category=None, nzbget_host=None, nzbget_username=None, nzbget_password=None, nzbget_category=None, download_dir=None, blackhole=0, blackhole_dir=None, usenet_retention=None, newznab=0, newznab_host=None, newznab_apikey=None, newznab_enabled=0, nzbsorg=0, nzbsorg_uid=None, nzbsorg_hash=None, nzbsrus=0, nzbsrus_uid=None, nzbsrus_apikey=None, nzbx=0, preferred_words=None, required_words=None, ignored_words=None, preferred_quality=0, preferred_bitrate=None, detect_bitrate=0, move_files=0, torrentblackhole_dir=None, download_torrent_dir=None, numberofseeders=10, use_isohunt=0, use_kat=0, use_mininova=0, waffles=0, waffles_uid=None, waffles_passkey=None, whatcd=0, whatcd_username=None, whatcd_password=None, @@ -730,6 +734,10 @@ class WebInterface(object): headphones.SAB_PASSWORD = sab_password headphones.SAB_APIKEY = sab_apikey headphones.SAB_CATEGORY = sab_category + headphones.NZBGET_HOST = nzbget_host + headphones.NZBGET_USERNAME = nzbget_username + headphones.NZBGET_PASSWORD = nzbget_password + headphones.NZBGET_CATEGORY = nzbget_category headphones.DOWNLOAD_DIR = download_dir headphones.BLACKHOLE = blackhole headphones.BLACKHOLE_DIR = blackhole_dir From 2771ca7dcfbf5afee24bc14eab3cbecd7048ac6e Mon Sep 17 00:00:00 2001 From: sjengfred Date: Mon, 24 Jun 2013 20:54:41 +0200 Subject: [PATCH 2/2] changed from xbian default to normal default + fixed license notifications --- data/interfaces/brink/config.html | 2 +- data/interfaces/classic/config.html | 2 +- data/interfaces/default/config.html | 2 +- data/interfaces/remix/config.html | 2 +- headphones/__init__.py | 4 +++- headphones/nzbget.py | 35 +++++++++++++++-------------- headphones/searcher.py | 2 ++ headphones/webserve.py | 4 +++- 8 files changed, 30 insertions(+), 23 deletions(-) diff --git a/data/interfaces/brink/config.html b/data/interfaces/brink/config.html index 5e7aa91a..44d50e09 100644 --- a/data/interfaces/brink/config.html +++ b/data/interfaces/brink/config.html @@ -250,7 +250,7 @@
-
Usually http://localhost:9092 +
Usually http://localhost:6789

NZBget Host:


- usually http://localhost:9092 + usually http://localhost:6789
diff --git a/data/interfaces/default/config.html b/data/interfaces/default/config.html index 7d219c5e..0979904d 100644 --- a/data/interfaces/default/config.html +++ b/data/interfaces/default/config.html @@ -145,7 +145,7 @@
- usually http://localhost:9092 + usually http://localhost:6789
diff --git a/data/interfaces/remix/config.html b/data/interfaces/remix/config.html index d03a6a5e..7f78d03e 100644 --- a/data/interfaces/remix/config.html +++ b/data/interfaces/remix/config.html @@ -130,7 +130,7 @@

NZBget Host:


- usually http://localhost:9092 + usually http://localhost:6789
diff --git a/headphones/__init__.py b/headphones/__init__.py index d14e0232..3dce3f57 100644 --- a/headphones/__init__.py +++ b/headphones/__init__.py @@ -13,6 +13,8 @@ # You should have received a copy of the GNU General Public License # along with Headphones. If not, see . +# NZBGet support added by CurlyMo as a part of XBian - XBMC on the Raspberry Pi + from __future__ import with_statement import os, sys, subprocess @@ -413,7 +415,7 @@ def initialize(): SAB_APIKEY = check_setting_str(CFG, 'SABnzbd', 'sab_apikey', '') SAB_CATEGORY = check_setting_str(CFG, 'SABnzbd', 'sab_category', '') - NZBGET_USERNAME = check_setting_str(CFG, 'NZBget', 'nzbget_username', '') + NZBGET_USERNAME = check_setting_str(CFG, 'NZBget', 'nzbget_username', 'nzbget') NZBGET_PASSWORD = check_setting_str(CFG, 'NZBget', 'nzbget_password', '') NZBGET_CATEGORY = check_setting_str(CFG, 'NZBget', 'nzbget_category', '') NZBGET_HOST = check_setting_str(CFG, 'NZBget', 'nzbget_host', '') diff --git a/headphones/nzbget.py b/headphones/nzbget.py index cd0c3315..5176c9f3 100644 --- a/headphones/nzbget.py +++ b/headphones/nzbget.py @@ -1,21 +1,22 @@ -# This file is part of Headphones. -# -# Headphones is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Headphones is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Headphones. If not, see . +# This file is modified to work with headphones by CurlyMo as a part of XBian - XBMC on the Raspberry Pi -##################################### -## Stolen from Sick-Beard's nzbget.py ## -##################################### +# Author: Nic Wolfe +# URL: http://code.google.com/p/sickbeard/ +# +# This file is part of Sick Beard. +# +# Sick Beard is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sick Beard is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Sick Beard. If not, see . diff --git a/headphones/searcher.py b/headphones/searcher.py index 041cb30b..100c485b 100644 --- a/headphones/searcher.py +++ b/headphones/searcher.py @@ -13,6 +13,8 @@ # You should have received a copy of the GNU General Public License # along with Headphones. If not, see . +# NZBGet support added by CurlyMo as a part of XBian - XBMC on the Raspberry Pi + import urllib, urllib2, urlparse, httplib import lib.feedparser as feedparser from lib.pygazelle import api as gazelleapi diff --git a/headphones/webserve.py b/headphones/webserve.py index 9e732e6b..66ff59e1 100644 --- a/headphones/webserve.py +++ b/headphones/webserve.py @@ -13,6 +13,8 @@ # You should have received a copy of the GNU General Public License # along with Headphones. If not, see . +# NZBGet support added by CurlyMo as a part of XBian - XBMC on the Raspberry Pi + import os import cherrypy @@ -706,7 +708,7 @@ class WebInterface(object): def configUpdate(self, http_host='0.0.0.0', http_username=None, http_port=8181, http_password=None, launch_browser=0, api_enabled=0, api_key=None, download_scan_interval=None, nzb_search_interval=None, libraryscan_interval=None, sab_host=None, sab_username=None, sab_apikey=None, sab_password=None, - sab_category=None, nzbget_host=None, nzbget_username=None, nzbget_password=None, nzbget_category=None, download_dir=None, blackhole=0, blackhole_dir=None, usenet_retention=None, newznab=0, newznab_host=None, newznab_apikey=None, + sab_category=None, nzbget_host=None, nzbget_username='nzbget', nzbget_password=None, nzbget_category=None, download_dir=None, blackhole=0, blackhole_dir=None, usenet_retention=None, newznab=0, newznab_host=None, newznab_apikey=None, newznab_enabled=0, nzbsorg=0, nzbsorg_uid=None, nzbsorg_hash=None, nzbsrus=0, nzbsrus_uid=None, nzbsrus_apikey=None, nzbx=0, preferred_words=None, required_words=None, ignored_words=None, preferred_quality=0, preferred_bitrate=None, detect_bitrate=0, move_files=0, torrentblackhole_dir=None, download_torrent_dir=None, numberofseeders=10, use_isohunt=0, use_kat=0, use_mininova=0, waffles=0, waffles_uid=None, waffles_passkey=None, whatcd=0, whatcd_username=None, whatcd_password=None,