mirror of
https://github.com/SickGear/SickGear.git
synced 2024-12-12 14:13:38 +00:00
d02c0bd6eb
Fixed charmap issues for anime show names. Fixed issues with display show page and epCat key errors. Fixed duplicate log messages for clearing provider caches. Fixed issues with email notifier ep names not properly being encoded to UTF-8. TVDB<->TVRAGE Indexer ID mapping is now performed on demand to be used when needed such as newznab providers can be searched with tvrage_id's and some will return tvrage_id's that later can be used to create show objects from for faster and more accurate name parsing, mapping is done via Trakt API calls. Added stop event signals to schedualed tasks, SR now waits indefinate till task has been fully stopped before completing a restart or shutdown event. NameParserCache is now persistent and stores 200 parsed results at any given time for quicker lookups and better performance, this helps maintain results between updates or shutdown/startup events. Black and White lists for anime now only get used for anime shows as intended, performance gain for non-anime shows that dont need to load these lists. Internal name cache now builds it self on demand when needed per show request plus checks if show is already in cache and if true exits routine to save time. Schedualer and QueueItems classes are now a sub-class of threading.Thread and a stop threading event signal has been added to each. If I forgot to list something it doesn't mean its not fixed so please test and report back if anything is wrong or has been corrected by this new release.
162 lines
No EOL
5 KiB
Python
162 lines
No EOL
5 KiB
Python
# Author: Nic Wolfe <nic@wolfeden.ca>
|
|
# URL: http://code.google.com/p/sickbeard/
|
|
#
|
|
# This file is part of SickRage.
|
|
#
|
|
# SickRage 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.
|
|
#
|
|
# SickRage 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 SickRage. 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
|
|
|
|
|
|
class NZBsProvider(generic.NZBProvider):
|
|
def __init__(self):
|
|
|
|
generic.NZBProvider.__init__(self, "NZBs.org Old")
|
|
|
|
self.supportsBacklog = True
|
|
|
|
self.cache = NZBsCache(self)
|
|
|
|
self.url = 'https://secure.nzbs.org/'
|
|
|
|
def isEnabled(self):
|
|
return sickbeard.NZBS
|
|
|
|
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")
|
|
|
|
def _get_season_search_strings(self, ep_obj):
|
|
return ['^' + x for x in show_name_helpers.makeSceneSeasonSearchString(self.show, ep_obj)]
|
|
|
|
def _get_episode_search_strings(self, ep_obj, add_string=''):
|
|
return ['^' + x for x in show_name_helpers.makeSceneSearchString(self.show, ep_obj)]
|
|
|
|
def _doSearch(self, curString, show=None, age=None):
|
|
|
|
curString = curString.replace('.', ' ')
|
|
|
|
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}
|
|
|
|
searchURL = self.url + "rss.php?" + urllib.urlencode(params)
|
|
|
|
logger.log(u"Search string: " + searchURL, logger.DEBUG)
|
|
|
|
data = self.cache.getRSSFeed(searchURL)
|
|
|
|
# Pause to avoid 503's
|
|
time.sleep(5)
|
|
|
|
if data is None:
|
|
logger.log(u"Error trying to load NZBs.org RSS feed: " + searchURL, logger.ERROR)
|
|
return []
|
|
|
|
items = data.entries
|
|
|
|
results = []
|
|
|
|
for curItem in items:
|
|
(title, url) = self._get_title_and_url(curItem)
|
|
|
|
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
|
|
|
|
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")
|
|
|
|
results.append(curItem)
|
|
|
|
return results
|
|
|
|
def findPropers(self, date=None):
|
|
|
|
results = []
|
|
|
|
for curString in (".PROPER.", ".REPACK."):
|
|
|
|
for curResult in self._doSearch(curString):
|
|
|
|
(title, url) = self._get_title_and_url(curResult)
|
|
|
|
pubDate_node = curResult.getElementsByTagName('pubDate')[0]
|
|
pubDate = helpers.get_xml_text(pubDate_node)
|
|
|
|
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
|
|
|
|
resultDate = datetime.datetime.strptime(match.group(1), "%a, %d %b %Y %H:%M:%S")
|
|
|
|
if date is None or resultDate > date:
|
|
results.append(classes.Proper(title, url, resultDate, self.show))
|
|
|
|
return results
|
|
|
|
|
|
class NZBsCache(tvcache.TVCache):
|
|
def __init__(self, provider):
|
|
tvcache.TVCache.__init__(self, provider)
|
|
|
|
# only poll NZBs.org every 15 minutes max
|
|
self.minTime = 15
|
|
|
|
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}
|
|
|
|
url += urllib.urlencode(urlArgs)
|
|
|
|
logger.log(u"NZBs cache update URL: " + url, logger.DEBUG)
|
|
|
|
return self.provider.getURL(url)
|
|
|
|
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")
|
|
|
|
|
|
provider = NZBsProvider() |