-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from DobyTang/master
updating local
- Loading branch information
Showing
7 changed files
with
367 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.