1
0
mirror of https://github.com/moparisthebest/SickRage synced 2024-12-12 11:02:21 -05:00

JSON parsed by requests lib instead of helper function

This commit is contained in:
echel0n 2014-04-25 20:58:24 -07:00
parent 83bcc63683
commit 754cc8e791

View File

@ -18,7 +18,6 @@ import generic
import sickbeard import sickbeard
from sickbeard import logger, tvcache, exceptions from sickbeard import logger, tvcache, exceptions
from sickbeard import helpers
from sickbeard.common import Quality from sickbeard.common import Quality
from sickbeard.exceptions import ex, AuthException from sickbeard.exceptions import ex, AuthException
from sickbeard.name_parser.parser import NameParser, InvalidNameException from sickbeard.name_parser.parser import NameParser, InvalidNameException
@ -53,16 +52,17 @@ class HDBitsProvider(generic.TorrentProvider):
return True return True
def _checkAuthFromData(self, data): def _checkAuthFromData(self, parsedJSON):
if data is None: if parsedJSON is None:
return self._checkAuth() return self._checkAuth()
if data.status == 5: if 'status' in parsedJSON and 'message' in parsedJSON:
logger.log(u"Incorrect authentication credentials for " + self.name + " : " + data.feed.title, if parsedJSON.get('status') == 5:
logger.DEBUG) logger.log(u"Incorrect authentication credentials for " + self.name + " : " + parsedJSON['message'],
raise AuthException( logger.DEBUG)
"Your authentication credentials for " + self.name + " are incorrect, check your config.") raise AuthException(
"Your authentication credentials for " + self.name + " are incorrect, check your config.")
return True return True
@ -80,19 +80,20 @@ class HDBitsProvider(generic.TorrentProvider):
if results or not manualSearch: if results or not manualSearch:
return results return results
data = self.getRSSFeed(self.search_url, post_data=self._make_post_data_JSON(show=episode.show, episode=episode)) parsedJSON = self.getURL(self.search_url, post_data=self._make_post_data_JSON(show=episode.show, episode=episode), json=True)
if not data: if not parsedJSON:
logger.log(u"No data returned from " + self.search_url, logger.ERROR) logger.log(u"No data returned from " + self.search_url, logger.ERROR)
return [] return []
if self._checkAuthFromData(data): if self._checkAuthFromData(parsedJSON):
results = [] results = []
items = data.entries if parsedJSON and 'data' in parsedJSON:
if not len(items) > 0: items = parsedJSON['data']
else:
logger.log(u"Resulting JSON from " + self.name + " isn't correct, not parsing it", logger.ERROR) logger.log(u"Resulting JSON from " + self.name + " isn't correct, not parsing it", logger.ERROR)
return [] items = []
for item in items: for item in items:
@ -136,8 +137,8 @@ class HDBitsProvider(generic.TorrentProvider):
def _get_title_and_url(self, item): def _get_title_and_url(self, item):
title = item.title title = item['name']
url = self.download_url + urllib.urlencode({'id': item.id, 'passkey': sickbeard.HDBITS_PASSKEY}) url = self.download_url + urllib.urlencode({'id': item['id'], 'passkey': sickbeard.HDBITS_PASSKEY})
return (title, url) return (title, url)
@ -180,10 +181,10 @@ class HDBitsCache(tvcache.TVCache):
if self._checkAuth(None): if self._checkAuth(None):
data = self._getRSSData() parsedJSON = self._getRSSData()
# As long as we got something from the provider we count it as an update # As long as we got something from the provider we count it as an update
if data: if parsedJSON:
self.setLastUpdate() self.setLastUpdate()
else: else:
return [] return []
@ -191,9 +192,16 @@ class HDBitsCache(tvcache.TVCache):
logger.log(u"Clearing " + self.provider.name + " cache and updating with new information") logger.log(u"Clearing " + self.provider.name + " cache and updating with new information")
self._clearCache() self._clearCache()
if self._checkAuth(data): if parsedJSON is None:
items = data.entries logger.log(u"Error trying to load " + self.provider.name + " JSON feed", logger.ERROR)
if not len(items) > 0: return []
if self._checkAuth(parsedJSON):
if parsedJSON and 'data' in parsedJSON:
items = parsedJSON['data']
else:
logger.log(u"Resulting JSON from " + self.provider.name + " isn't correct, not parsing it",
logger.ERROR)
return [] return []
cl = [] cl = []
@ -214,7 +222,7 @@ class HDBitsCache(tvcache.TVCache):
return [] return []
def _getRSSData(self): def _getRSSData(self):
return self.provider.getRSSFeed(self.provider.rss_url, post_data=self.provider._make_post_data_JSON()) return self.provider.getURL(self.provider.rss_url, post_data=self.provider._make_post_data_JSON(), json=True)
def _parseItem(self, item): def _parseItem(self, item):
@ -231,4 +239,5 @@ class HDBitsCache(tvcache.TVCache):
def _checkAuth(self, data): def _checkAuth(self, data):
return self.provider._checkAuthFromData(data) return self.provider._checkAuthFromData(data)
provider = HDBitsProvider() provider = HDBitsProvider()