Skip to content

Commit

Permalink
Merge pull request #1 from DobyTang/master
Browse files Browse the repository at this point in the history
updating local
  • Loading branch information
daktak committed May 18, 2015
2 parents c20364a + 61dda7f commit e22b33e
Show file tree
Hide file tree
Showing 7 changed files with 367 additions and 3 deletions.
47 changes: 47 additions & 0 deletions data/interfaces/default/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,34 @@ <h3>Usenet</h3>
<input type="text" name="usenet_retention" value="${config['usenet_retention']}" size="30">
</div>
</fieldset>

<div class="row checkbox">
<input type="checkbox" name="nzb_downloader_nzbget" id="nzb_downloader_nzbget" value="1" ${config['nzb_downloader_nzbget']} />
<label>Use NZBGet</label>
</div>
<fieldset id="nzbget_options">
<div class="row">
<label>NZBGet Host:</label>
<input type="text" name="nzbget_host" value="${config['nzbget_host']}" size="30" align="right">
</div>
<div class="row">
<label>NZBGet Username</label>
<input type="text" name="nzbget_user" value="${config['nzbget_user']}" size="30">
</div>
<div class="row">
<label>NZBGet Password:</label>
<input type="password" name="nzbget_pass" value="${config['nzbget_pass']}" size="30">
</div>
<div class="row">
<label>NZBGet Category:</label>
<input type="text" name="nzbget_cat" value="${config['nzbget_cat']}" size="30">
</div>
<div class="row">
<label>NZBGet Priority:</label>
<input type="text" name="nzbget_priority" value="${config['nzbget_priority']}" size="30">
</div>
</fieldset>

<div class="row checkbox">
<input type="checkbox" name="nzb_downloader_blackhole" id="nzb_downloader_blackhole" value="1" ${config['nzb_downloader_blackhole']} />
<label>Use NZB Blackhole</label>
Expand Down Expand Up @@ -698,6 +726,25 @@ <h3>NotifyMyAndroid</h3>
}
});

if ($("#nzb_downloader_nzbget").is(":checked"))
{
$("#nzbget_options").show();
}
else
{
$("#nzbget_options").hide();
}
$("#nzb_downloader_nzbget").click(function(){
if ($("#nzb_downloader_nzbget").is(":checked"))
{
$("#nzbget_options").slideDown();
}
else
{
$("#nzbget_options").slideUp();
}
});

if ($("#twitter").is(":checked"))
{
$("#twitteroptions").show();
Expand Down
22 changes: 22 additions & 0 deletions lazylibrarian/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@
SAB_API = None
SAB_CAT = None

NZBGET_HOST = None
NZBGET_USER = None
NZBGET_PASS = None
NZBGET_CATEGORY = None
NZBGET_PRIORITY = None

DESTINATION_COPY = False
DESTINATION_DIR = None
DOWNLOAD_DIR = None
Expand Down Expand Up @@ -117,6 +123,7 @@
USE_TOR = False

NZB_DOWNLOADER_SABNZBD = False
NZB_DOWNLOADER_NZBGET = False
NZB_DOWNLOADER_BLACKHOLE = False
NZB_BLACKHOLEDIR = None
USENET_RETENTION = None
Expand Down Expand Up @@ -247,6 +254,7 @@ def initialize():
global __INITIALIZED__, FULL_PATH, PROG_DIR, LOGLEVEL, DAEMON, DATADIR, CONFIGFILE, CFG, LOGDIR, HTTP_HOST, HTTP_PORT, HTTP_USER, HTTP_PASS, HTTP_ROOT, HTTP_LOOK, LAUNCH_BROWSER, LOGDIR, CACHEDIR, MATCH_RATIO, \
PROXY_HOST, PROXY_TYPE, \
IMP_ONLYISBN, IMP_PREFLANG, IMP_AUTOADD, SAB_HOST, SAB_PORT, SAB_SUBDIR, SAB_API, SAB_USER, SAB_PASS, DESTINATION_DIR, DESTINATION_COPY, DOWNLOAD_DIR, SAB_CAT, USENET_RETENTION, NZB_BLACKHOLEDIR, GR_API, GB_API, BOOK_API, \
NZBGET_HOST, NZBGET_USER, NZBGET_PASS, NZBGET_CATEGORY, NZBGET_PRIORITY, NZB_DOWNLOADER_NZBGET, \
NZBMATRIX, NZBMATRIX_USER, NZBMATRIX_API, NEWZNAB, NEWZNAB_HOST, NEWZNAB_API, NEWZBIN, NEWZBIN_UID, NEWZBIN_PASS, NEWZNAB2, NEWZNAB_HOST2, NEWZNAB_API2, EBOOK_TYPE, KAT, USENETCRAWLER, USENETCRAWLER_HOST, USENETCRAWLER_API, \
VERSIONCHECK_INTERVAL, SEARCH_INTERVAL, SCAN_INTERVAL, EBOOK_DEST_FOLDER, EBOOK_DEST_FILE, MAG_DEST_FOLDER, MAG_DEST_FILE, USE_TWITTER, TWITTER_NOTIFY_ONSNATCH, TWITTER_NOTIFY_ONDOWNLOAD, TWITTER_USERNAME, TWITTER_PASSWORD, TWITTER_PREFIX, \
USE_BOXCAR, BOXCAR_NOTIFY_ONSNATCH, BOXCAR_NOTIFY_ONDOWNLOAD, BOXCAR_TOKEN, TORRENT_DIR, TOR_DOWNLOADER_BLACKHOLE, TOR_DOWNLOADER_UTORRENT, USE_TOR, USE_NZB, NZB_DOWNLOADER_SABNZBD, NZB_DOWNLOADER_BLACKHOLE, \
Expand Down Expand Up @@ -333,6 +341,11 @@ def initialize():
SAB_API = check_setting_str(CFG, 'SABnzbd', 'sab_api', '')
SAB_CAT = check_setting_str(CFG, 'SABnzbd', 'sab_cat', '')

NZBGET_HOST = check_setting_str(CFG, 'NZBGet', 'nzbget_host', '')
NZBGET_USER = check_setting_str(CFG, 'NZBGet', 'nzbget_user', '')
NZBGET_PASS = check_setting_str(CFG, 'NZBGet', 'nzbget_pass', '')
NZBGET_CATEGORY = check_setting_str(CFG, 'NZBGet', 'nzbget_cat', '')
NZBGET_PRIORITY = check_setting_str(CFG, 'NZBGet', 'nzbget_priority', '')

DESTINATION_COPY = bool(check_setting_int(CFG, 'General', 'destination_copy', 0))
DESTINATION_DIR = check_setting_str(CFG, 'General','destination_dir', '')
Expand All @@ -342,6 +355,7 @@ def initialize():
USE_TOR = bool(check_setting_int(CFG, 'DLMethod', 'use_tor', 0))

NZB_DOWNLOADER_SABNZBD = bool(check_setting_int(CFG, 'USENET', 'nzb_downloader_sabnzbd', 0))
NZB_DOWNLOADER_NZBGET = bool(check_setting_int(CFG, 'USENET', 'nzb_downloader_nzbget', 0))
NZB_DOWNLOADER_BLACKHOLE = bool(check_setting_int(CFG, 'USENET', 'nzb_downloader_blackhole', 0))
NZB_BLACKHOLEDIR = check_setting_str(CFG, 'USENET', 'nzb_blackholedir', '')
USENET_RETENTION = check_setting_str(CFG, 'USENET', 'usenet_retention', '')
Expand Down Expand Up @@ -525,6 +539,7 @@ def config_write():

new_config['USENET'] = {}
new_config['USENET']['nzb_downloader_sabnzbd'] = NZB_DOWNLOADER_SABNZBD
new_config['USENET']['nzb_downloader_nzbget'] = NZB_DOWNLOADER_NZBGET
new_config['USENET']['nzb_downloader_blackhole'] = NZB_DOWNLOADER_BLACKHOLE
new_config['USENET']['nzb_blackholedir'] = NZB_BLACKHOLEDIR
new_config['USENET']['usenet_retention'] = USENET_RETENTION
Expand All @@ -538,6 +553,13 @@ def config_write():
new_config['SABnzbd']['sab_api'] = SAB_API
new_config['SABnzbd']['sab_cat'] = SAB_CAT

new_config['NZBGet'] = {}
new_config['NZBGet']['nzbget_host'] = NZBGET_HOST
new_config['NZBGet']['nzbget_user'] = NZBGET_USER
new_config['NZBGet']['nzbget_pass'] = NZBGET_PASS
new_config['NZBGet']['nzbget_cat'] = NZBGET_CATEGORY
new_config['NZBGet']['nzbget_priority'] = NZBGET_PRIORITY

new_config['General']['destination_dir'] = DESTINATION_DIR
new_config['General']['destination_copy'] = int(DESTINATION_COPY)
new_config['General']['download_dir'] = DOWNLOAD_DIR
Expand Down
136 changes: 136 additions & 0 deletions lazylibrarian/classes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
# This file is part of LazyLibrarian.
#
# LazyLibrarian 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.
#
# LazyLibrarian 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 LazyLibrarian. If not, see <http://www.gnu.org/licenses/>.

#########################################
## Stolen from Sick-Beard's classes.py ##
#########################################


import urllib

from common import USER_AGENT


class LazyLibrarianURLopener(urllib.FancyURLopener):
version = USER_AGENT


class AuthURLOpener(LazyLibrarianURLopener):
"""
URLOpener class that supports http auth without needing interactive password entry.
If the provided username/password don't work it simply fails.
user: username to use for HTTP auth
pw: password to use for HTTP auth
"""

def __init__(self, user, pw):
self.username = user
self.password = pw

# remember if we've tried the username/password before
self.numTries = 0

# call the base class
urllib.FancyURLopener.__init__(self)

def prompt_user_passwd(self, host, realm):
"""
Override this function and instead of prompting just give the
username/password that were provided when the class was instantiated.
"""

# if this is the first try then provide a username/password
if self.numTries == 0:
self.numTries = 1
return (self.username, self.password)

# if we've tried before then return blank which cancels the request
else:
return ('', '')

# this is pretty much just a hack for convenience
def openit(self, url):
self.numTries = 0
return LazyLibrarianURLopener.open(self, url)


class SearchResult:
"""
Represents a search result from an indexer.
"""

def __init__(self):
self.provider = -1

# URL to the NZB/torrent file
self.url = ""

# used by some providers to store extra info associated with the result
self.extraInfo = []

# quality of the release
self.quality = -1

# release name
self.name = ""

def __str__(self):

if self.provider is None:
return "Invalid provider, unable to print self"

myString = self.provider.name + " @ " + self.url + "\n"
myString += "Extra Info:\n"
for extra in self.extraInfo:
myString += " " + extra + "\n"
return myString


class NZBSearchResult(SearchResult):
"""
Regular NZB result with an URL to the NZB
"""
resultType = "nzb"


class NZBDataSearchResult(SearchResult):
"""
NZB result where the actual NZB XML data is stored in the extraInfo
"""
resultType = "nzbdata"


class TorrentSearchResult(SearchResult):
"""
Torrent result with an URL to the torrent
"""
resultType = "torrent"


class Proper:
def __init__(self, name, url, date):
self.name = name
self.url = url
self.date = date
self.provider = None
self.quality = -1

self.tvdbid = -1
self.season = -1
self.episode = -1

def __str__(self):
return str(self.date) + " " + self.name + " " + str(self.season) + "x" + str(self.episode) + " of " + str(self.tvdbid)
126 changes: 126 additions & 0 deletions lazylibrarian/nzbget.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# This file is modified to work with lazylibrarian by CurlyMo <[email protected]> as a part of XBian - XBMC on the Raspberry Pi

# Author: Nic Wolfe <[email protected]>
# URL: http://code.google.com/p/sickbeard/
#
# This file is part of LazyLibrarian.
#
# LazyLibrarian 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.
#
# LazyLibrarian 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 LazyLibrarian. If not, see <http://www.gnu.org/licenses/>.


import httplib

import lazylibrarian

from base64 import standard_b64encode
import xmlrpclib

from lazylibrarian import logger


def sendNZB(nzb):

addToTop = False
nzbgetXMLrpc = "%(username)s:%(password)s@%(host)s/xmlrpc"

if lazylibrarian.NZBGET_HOST is None:
logger.error(u"No NZBget host found in configuration. Please configure it.")
return False

if lazylibrarian.NZBGET_HOST.startswith('https://'):
nzbgetXMLrpc = 'https://' + nzbgetXMLrpc
lazylibrarian.NZBGET_HOST.replace('https://', '', 1)
else:
nzbgetXMLrpc = 'http://' + nzbgetXMLrpc
lazylibrarian.NZBGET_HOST.replace('http://', '', 1)

url = nzbgetXMLrpc % {"host": lazylibrarian.NZBGET_HOST, "username": lazylibrarian.NZBGET_USER, "password": lazylibrarian.NZBGET_PASS}

nzbGetRPC = xmlrpclib.ServerProxy(url)
try:
if nzbGetRPC.writelog("INFO", "lazylibrarian connected to drop of %s any moment now." % (nzb.name + ".nzb")):
logger.debug(u"Successfully connected to NZBget")
else:
logger.info(u"Successfully connected to NZBget, but unable to send a message" % (nzb.name + ".nzb"))

except httplib.socket.error, e:
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

nzbcontent64 = None
if nzb.resultType == "nzbdata":
data = nzb.extraInfo[0]
nzbcontent64 = standard_b64encode(data)

logger.info(u"Sending NZB to NZBget")
logger.debug(u"URL: " + url)

dupekey = ""
dupescore = 0

try:
# Find out if nzbget supports priority (Version 9.0+), old versions beginning with a 0.x will use the old command
nzbget_version_str = nzbGetRPC.version()
nzbget_version = int(nzbget_version_str[:nzbget_version_str.find(".")])
if nzbget_version == 0:
if nzbcontent64 is not None:
nzbget_result = nzbGetRPC.append(nzb.name + ".nzb", lazylibrarian.NZBGET_CATEGORY, addToTop, nzbcontent64)
else:
# from lazylibrarian.common.providers.generic import GenericProvider
# if nzb.resultType == "nzb":
# genProvider = GenericProvider("")
# data = genProvider.getURL(nzb.url)
# if (data is None):
# return False
# nzbcontent64 = standard_b64encode(data)
# nzbget_result = nzbGetRPC.append(nzb.name + ".nzb", lazylibrarian.NZBGET_CATEGORY, addToTop, nzbcontent64)
return False
elif nzbget_version == 12:
if nzbcontent64 is not None:
nzbget_result = nzbGetRPC.append(nzb.name + ".nzb", lazylibrarian.NZBGET_CATEGORY, lazylibrarian.NZBGET_PRIORITY, False,
nzbcontent64, False, dupekey, dupescore, "score")
else:
nzbget_result = nzbGetRPC.appendurl(nzb.name + ".nzb", lazylibrarian.NZBGET_CATEGORY, lazylibrarian.NZBGET_PRIORITY, False,
nzb.url, False, dupekey, dupescore, "score")
# v13+ has a new combined append method that accepts both (url and content)
# also the return value has changed from boolean to integer
# (Positive number representing NZBID of the queue item. 0 and negative numbers represent error codes.)
elif nzbget_version >= 13:
nzbget_result = True if nzbGetRPC.append(nzb.name + ".nzb", nzbcontent64 if nzbcontent64 is not None else nzb.url,
lazylibrarian.NZBGET_CATEGORY, lazylibrarian.NZBGET_PRIORITY, False, False, dupekey, dupescore,
"score") > 0 else False
else:
if nzbcontent64 is not None:
nzbget_result = nzbGetRPC.append(nzb.name + ".nzb", lazylibrarian.NZBGET_CATEGORY, lazylibrarian.NZBGET_PRIORITY, False,
nzbcontent64)
else:
nzbget_result = nzbGetRPC.appendurl(nzb.name + ".nzb", lazylibrarian.NZBGET_CATEGORY, lazylibrarian.NZBGET_PRIORITY, False,
nzb.url)

if nzbget_result:
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
except:
logger.error(u"Connect Error to NZBget: could not add %s to the queue" % (nzb.name + ".nzb"))
return False
Loading

0 comments on commit e22b33e

Please sign in to comment.