2014-03-10 01:18:05 -04:00
|
|
|
# Author: Nic Wolfe <nic@wolfeden.ca>
|
|
|
|
# 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 <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import datetime
|
|
|
|
import re
|
|
|
|
import time
|
|
|
|
import urllib
|
|
|
|
|
|
|
|
from xml.dom.minidom import parseString
|
|
|
|
|
|
|
|
import sickbeard
|
|
|
|
import generic
|
|
|
|
|
|
|
|
from sickbeard import classes, show_name_helpers, helpers
|
|
|
|
|
|
|
|
from sickbeard import exceptions, logger
|
|
|
|
from sickbeard import tvcache
|
|
|
|
from sickbeard.exceptions import ex
|
|
|
|
|
2014-03-25 01:57:24 -04:00
|
|
|
|
2014-03-10 01:18:05 -04:00
|
|
|
class NZBsProvider(generic.NZBProvider):
|
2014-03-25 01:57:24 -04:00
|
|
|
def __init__(self):
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-03-25 01:57:24 -04:00
|
|
|
generic.NZBProvider.__init__(self, "NZBs.org Old")
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-03-25 01:57:24 -04:00
|
|
|
self.supportsBacklog = True
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-03-25 01:57:24 -04:00
|
|
|
self.cache = NZBsCache(self)
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-03-25 01:57:24 -04:00
|
|
|
self.url = 'https://secure.nzbs.org/'
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-03-25 01:57:24 -04:00
|
|
|
def isEnabled(self):
|
|
|
|
return sickbeard.NZBS
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-03-25 01:57:24 -04:00
|
|
|
def _checkAuth(self):
|
|
|
|
if sickbeard.NZBS_UID in (None, "") or sickbeard.NZBS_HASH in (None, ""):
|
|
|
|
raise exceptions.AuthException("NZBs.org authentication details are empty, check your config")
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-04-27 06:31:54 -04:00
|
|
|
def _get_season_search_strings(self, show, season, episode, abd=False):
|
|
|
|
return ['^' + x for x in show_name_helpers.makeSceneSeasonSearchString(show, season, episode, abd)]
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-04-27 06:31:54 -04:00
|
|
|
def _get_episode_search_strings(self, show, season, episode, abd=False):
|
|
|
|
return ['^' + x for x in show_name_helpers.makeSceneSearchString(show, season, episode, abd)]
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-04-05 07:34:49 -04:00
|
|
|
def _doSearch(self, curString, show=None, age=None):
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-03-25 01:57:24 -04:00
|
|
|
curString = curString.replace('.', ' ')
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-03-25 01:57:24 -04:00
|
|
|
params = {"action": "search",
|
|
|
|
"q": curString.encode('utf-8'),
|
|
|
|
"dl": 1,
|
|
|
|
"i": sickbeard.NZBS_UID,
|
|
|
|
"h": sickbeard.NZBS_HASH,
|
|
|
|
"age": sickbeard.USENET_RETENTION,
|
|
|
|
"num": 100,
|
|
|
|
"type": 1}
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-03-25 01:57:24 -04:00
|
|
|
searchURL = self.url + "rss.php?" + urllib.urlencode(params)
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-03-25 01:57:24 -04:00
|
|
|
logger.log(u"Search string: " + searchURL, logger.DEBUG)
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-04-25 21:49:38 -04:00
|
|
|
data = self.getRSSFeed(searchURL)
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-03-25 01:57:24 -04:00
|
|
|
# Pause to avoid 503's
|
|
|
|
time.sleep(5)
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-03-25 01:57:24 -04:00
|
|
|
if data == None:
|
2014-04-25 21:49:38 -04:00
|
|
|
logger.log(u"Error trying to load NZBs.org RSS feed: " + searchURL, logger.ERROR)
|
2014-03-25 01:57:24 -04:00
|
|
|
return []
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-04-25 21:49:38 -04:00
|
|
|
items = data.entries
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-03-25 01:57:24 -04:00
|
|
|
results = []
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-03-25 01:57:24 -04:00
|
|
|
for curItem in items:
|
|
|
|
(title, url) = self._get_title_and_url(curItem)
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-03-25 01:57:24 -04:00
|
|
|
if not title or not url:
|
|
|
|
logger.log(
|
|
|
|
u"The XML returned from the NZBs.org RSS feed is incomplete, this result is unusable: " + data,
|
|
|
|
logger.ERROR)
|
|
|
|
continue
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-03-25 01:57:24 -04:00
|
|
|
if "&i=" not in url and "&h=" not in url:
|
|
|
|
raise exceptions.AuthException(
|
|
|
|
"The NZBs.org result URL has no auth info which means your UID/hash are incorrect, check your config")
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-03-25 01:57:24 -04:00
|
|
|
results.append(curItem)
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-03-25 01:57:24 -04:00
|
|
|
return results
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-03-25 01:57:24 -04:00
|
|
|
def findPropers(self, date=None):
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-03-25 01:57:24 -04:00
|
|
|
results = []
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-03-25 01:57:24 -04:00
|
|
|
for curString in (".PROPER.", ".REPACK."):
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-03-25 01:57:24 -04:00
|
|
|
for curResult in self._doSearch(curString):
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-03-25 01:57:24 -04:00
|
|
|
(title, url) = self._get_title_and_url(curResult)
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-03-25 01:57:24 -04:00
|
|
|
pubDate_node = curResult.getElementsByTagName('pubDate')[0]
|
|
|
|
pubDate = helpers.get_xml_text(pubDate_node)
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-03-25 01:57:24 -04:00
|
|
|
match = re.search('(\w{3}, \d{1,2} \w{3} \d{4} \d\d:\d\d:\d\d) [\+\-]\d{4}', pubDate)
|
|
|
|
if not match:
|
|
|
|
continue
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-03-25 01:57:24 -04:00
|
|
|
resultDate = datetime.datetime.strptime(match.group(1), "%a, %d %b %Y %H:%M:%S")
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-03-25 01:57:24 -04:00
|
|
|
if date == None or resultDate > date:
|
|
|
|
results.append(classes.Proper(title, url, resultDate))
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-03-25 01:57:24 -04:00
|
|
|
return results
|
2014-03-10 01:18:05 -04:00
|
|
|
|
|
|
|
|
|
|
|
class NZBsCache(tvcache.TVCache):
|
2014-03-25 01:57:24 -04:00
|
|
|
def __init__(self, provider):
|
|
|
|
tvcache.TVCache.__init__(self, provider)
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-03-25 01:57:24 -04:00
|
|
|
# only poll NZBs.org every 15 minutes max
|
|
|
|
self.minTime = 15
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-03-25 01:57:24 -04:00
|
|
|
def _getRSSData(self):
|
|
|
|
url = self.provider.url + 'rss.php?'
|
|
|
|
urlArgs = {'type': 1,
|
|
|
|
'dl': 1,
|
|
|
|
'num': 100,
|
|
|
|
'i': sickbeard.NZBS_UID,
|
|
|
|
'h': sickbeard.NZBS_HASH,
|
|
|
|
'age': sickbeard.USENET_RETENTION}
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-03-25 01:57:24 -04:00
|
|
|
url += urllib.urlencode(urlArgs)
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-03-25 01:57:24 -04:00
|
|
|
logger.log(u"NZBs cache update URL: " + url, logger.DEBUG)
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-03-25 01:57:24 -04:00
|
|
|
data = self.provider.getURL(url)
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-03-25 01:57:24 -04:00
|
|
|
return data
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-03-25 01:57:24 -04:00
|
|
|
def _checkItemAuth(self, title, url):
|
|
|
|
if "&i=" not in url and "&h=" not in url:
|
|
|
|
raise exceptions.AuthException(
|
|
|
|
"The NZBs.org result URL has no auth info which means your UID/hash are incorrect, check your config")
|
2014-03-10 01:18:05 -04:00
|
|
|
|
|
|
|
|
|
|
|
provider = NZBsProvider()
|