mirror of
https://github.com/moparisthebest/SickRage
synced 2025-01-05 19:08:02 -05:00
Removed a extra space that may have caused issues in future
This commit is contained in:
parent
22ec1a4418
commit
12b8fc9990
@ -14,29 +14,28 @@
|
|||||||
# along with Sick Beard. If not, see <http://www.gnu.org/licenses/>.
|
# along with Sick Beard. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import time
|
import time
|
||||||
import datetime
|
import datetime
|
||||||
import urllib
|
import urllib
|
||||||
import generic
|
import generic
|
||||||
import sickbeard
|
import sickbeard
|
||||||
|
|
||||||
from sickbeard import classes
|
from sickbeard import classes
|
||||||
from sickbeard import logger, tvcache, exceptions
|
from sickbeard import logger, tvcache, exceptions
|
||||||
from sickbeard import helpers
|
from sickbeard import helpers
|
||||||
from sickbeard.common import cpu_presets
|
from sickbeard.common import cpu_presets
|
||||||
from sickbeard.exceptions import ex, AuthException
|
from sickbeard.exceptions import ex, AuthException
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import json
|
import json
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from lib import simplejson as json
|
from lib import simplejson as json
|
||||||
|
|
||||||
|
|
||||||
class HDBitsProvider(generic.TorrentProvider):
|
class HDBitsProvider(generic.TorrentProvider):
|
||||||
|
def __init__(self):
|
||||||
def __init__(self):
|
|
||||||
|
generic.TorrentProvider.__init__(self, "HDBits")
|
||||||
generic.TorrentProvider.__init__(self, "HDBits")
|
|
||||||
|
|
||||||
self.supportsBacklog = True
|
self.supportsBacklog = True
|
||||||
|
|
||||||
self.enabled = False
|
self.enabled = False
|
||||||
@ -44,119 +43,122 @@ class HDBitsProvider(generic.TorrentProvider):
|
|||||||
self.password = None
|
self.password = None
|
||||||
self.ratio = None
|
self.ratio = None
|
||||||
|
|
||||||
self.cache = HDBitsCache(self)
|
self.cache = HDBitsCache(self)
|
||||||
|
|
||||||
self.url = 'https://hdbits.org'
|
self.url = 'https://hdbits.org'
|
||||||
self.search_url = 'https://hdbits.org/api/torrents'
|
self.search_url = 'https://hdbits.org/api/torrents'
|
||||||
self.rss_url = 'https://hdbits.org/api/torrents'
|
self.rss_url = 'https://hdbits.org/api/torrents'
|
||||||
self.download_url = 'http://hdbits.org/download.php?'
|
self.download_url = 'http://hdbits.org/download.php?'
|
||||||
|
|
||||||
def isEnabled(self):
|
def isEnabled(self):
|
||||||
return self.enabled
|
return self.enabled
|
||||||
|
|
||||||
def _checkAuth(self):
|
def _checkAuth(self):
|
||||||
|
|
||||||
if not self.username or not self.password:
|
if not self.username or not self.password:
|
||||||
raise AuthException("Your authentication credentials for " + self.name + " are missing, check your config.")
|
raise AuthException("Your authentication credentials for " + self.name + " are missing, check your config.")
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def _checkAuthFromData(self, parsedJSON):
|
def _checkAuthFromData(self, parsedJSON):
|
||||||
|
|
||||||
if parsedJSON is None:
|
if parsedJSON is None:
|
||||||
return self._checkAuth()
|
return self._checkAuth()
|
||||||
|
|
||||||
if 'status' in parsedJSON and 'message' in parsedJSON:
|
if 'status' in parsedJSON and 'message' in parsedJSON:
|
||||||
if parsedJSON.get('status') == 5:
|
if parsedJSON.get('status') == 5:
|
||||||
logger.log(u"Incorrect authentication credentials for " + self.name + " : " + parsedJSON['message'], logger.DEBUG)
|
logger.log(u"Incorrect authentication credentials for " + self.name + " : " + parsedJSON['message'],
|
||||||
raise AuthException("Your authentication credentials for " + self.name + " are incorrect, check your config.")
|
logger.DEBUG)
|
||||||
|
raise AuthException(
|
||||||
return True
|
"Your authentication credentials for " + self.name + " are incorrect, check your config.")
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
def _get_season_search_strings(self, ep_obj):
|
def _get_season_search_strings(self, ep_obj):
|
||||||
season_search_string = [self._make_post_data_JSON(show=ep_obj.show, season=ep_obj.scene_season)]
|
season_search_string = [self._make_post_data_JSON(show=ep_obj.show, season=ep_obj.scene_season)]
|
||||||
return season_search_string
|
return season_search_string
|
||||||
|
|
||||||
def _get_episode_search_strings(self, ep_obj, add_string=''):
|
def _get_episode_search_strings(self, ep_obj, add_string=''):
|
||||||
episode_search_string = [self._make_post_data_JSON(show=ep_obj.show, episode=ep_obj)]
|
episode_search_string = [self._make_post_data_JSON(show=ep_obj.show, episode=ep_obj)]
|
||||||
return episode_search_string
|
return episode_search_string
|
||||||
|
|
||||||
def _get_title_and_url(self, item):
|
def _get_title_and_url(self, item):
|
||||||
|
|
||||||
title = item['name']
|
title = item['name']
|
||||||
if title:
|
if title:
|
||||||
title = title.replace(' ', '.')
|
title = title.replace(' ', '.')
|
||||||
|
|
||||||
url = self.download_url + urllib.urlencode({'id': item['id'], 'passkey': self.password})
|
url = self.download_url + urllib.urlencode({'id': item['id'], 'passkey': self.password})
|
||||||
|
|
||||||
return (title, url)
|
return (title, url)
|
||||||
|
|
||||||
def _doSearch(self, search_params, epcount=0, age=0):
|
def _doSearch(self, search_params, epcount=0, age=0):
|
||||||
results = []
|
results = []
|
||||||
|
|
||||||
self._checkAuth()
|
self._checkAuth()
|
||||||
|
|
||||||
logger.log(u"Search url: " + self.search_url + " search_params: " + search_params, logger.DEBUG)
|
logger.log(u"Search url: " + self.search_url + " search_params: " + search_params, logger.DEBUG)
|
||||||
|
|
||||||
data = self.getURL(self.search_url, post_data=search_params)
|
data = self.getURL(self.search_url, post_data=search_params)
|
||||||
|
|
||||||
if not data:
|
if not data:
|
||||||
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 []
|
||||||
|
|
||||||
parsedJSON = helpers.parse_json(data)
|
parsedJSON = helpers.parse_json(data)
|
||||||
|
|
||||||
if parsedJSON is None:
|
if parsedJSON is None:
|
||||||
logger.log(u"Error trying to load " + self.name + " JSON data", logger.ERROR)
|
logger.log(u"Error trying to load " + self.name + " JSON data", logger.ERROR)
|
||||||
return []
|
return []
|
||||||
|
|
||||||
if self._checkAuthFromData(parsedJSON):
|
if self._checkAuthFromData(parsedJSON):
|
||||||
if parsedJSON and 'data' in parsedJSON:
|
if parsedJSON and 'data' in parsedJSON:
|
||||||
items = parsedJSON['data']
|
items = parsedJSON['data']
|
||||||
else:
|
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)
|
||||||
items = []
|
items = []
|
||||||
|
|
||||||
for item in items:
|
for item in items:
|
||||||
results.append(item)
|
results.append(item)
|
||||||
|
|
||||||
return results
|
return results
|
||||||
|
|
||||||
def findPropers(self, search_date=None):
|
def findPropers(self, search_date=None):
|
||||||
results = []
|
results = []
|
||||||
|
|
||||||
search_terms = [' proper ', ' repack ']
|
search_terms = [' proper ', ' repack ']
|
||||||
|
|
||||||
for term in search_terms:
|
for term in search_terms:
|
||||||
for item in self._doSearch(self._make_post_data_JSON(search_term=term)):
|
for item in self._doSearch(self._make_post_data_JSON(search_term=term)):
|
||||||
if item['utadded']:
|
if item['utadded']:
|
||||||
try:
|
try:
|
||||||
result_date = datetime.datetime.fromtimestamp(int(item['utadded']))
|
result_date = datetime.datetime.fromtimestamp(int(item['utadded']))
|
||||||
except:
|
except:
|
||||||
result_date = None
|
result_date = None
|
||||||
|
|
||||||
if result_date:
|
if result_date:
|
||||||
if not search_date or result_date > search_date:
|
if not search_date or result_date > search_date:
|
||||||
title, url = self._get_title_and_url(item)
|
title, url = self._get_title_and_url(item)
|
||||||
results.append(classes.Proper(title, url, result_date))
|
results.append(classes.Proper(title, url, result_date))
|
||||||
|
|
||||||
return results
|
return results
|
||||||
|
|
||||||
def _make_post_data_JSON(self, show=None, episode=None, season=None, search_term=None):
|
def _make_post_data_JSON(self, show=None, episode=None, season=None, search_term=None):
|
||||||
|
|
||||||
post_data = {
|
post_data = {
|
||||||
'username': self.username,
|
'username': self.username,
|
||||||
'passkey': self.password,
|
'passkey': self.password,
|
||||||
'category': [2], # TV Category
|
'category': [2],
|
||||||
}
|
# TV Category
|
||||||
|
}
|
||||||
if episode:
|
|
||||||
post_data['tvdb'] = {
|
if episode:
|
||||||
'id': show.indexerid,
|
post_data['tvdb'] = {
|
||||||
|
'id': show.indexerid,
|
||||||
'season': episode.scene_season,
|
'season': episode.scene_season,
|
||||||
'episode': episode.scene_episode
|
'episode': episode.scene_episode
|
||||||
}
|
}
|
||||||
|
|
||||||
if season:
|
if season:
|
||||||
if show.air_by_date or show.sports:
|
if show.air_by_date or show.sports:
|
||||||
post_data['tvdb'] = {
|
post_data['tvdb'] = {
|
||||||
@ -169,55 +171,55 @@ class HDBitsProvider(generic.TorrentProvider):
|
|||||||
'season': season,
|
'season': season,
|
||||||
}
|
}
|
||||||
|
|
||||||
if search_term:
|
if search_term:
|
||||||
post_data['search'] = search_term
|
post_data['search'] = search_term
|
||||||
|
|
||||||
return json.dumps(post_data)
|
return json.dumps(post_data)
|
||||||
|
|
||||||
def seedRatio(self):
|
def seedRatio(self):
|
||||||
return self.ratio
|
return self.ratio
|
||||||
|
|
||||||
|
|
||||||
class HDBitsCache(tvcache.TVCache):
|
class HDBitsCache(tvcache.TVCache):
|
||||||
|
def __init__(self, provider):
|
||||||
def __init__(self, provider):
|
|
||||||
|
tvcache.TVCache.__init__(self, provider)
|
||||||
tvcache.TVCache.__init__(self, provider)
|
|
||||||
|
|
||||||
# only poll HDBits every 15 minutes max
|
# only poll HDBits every 15 minutes max
|
||||||
self.minTime = 15
|
self.minTime = 15
|
||||||
|
|
||||||
def updateCache(self):
|
def updateCache(self):
|
||||||
|
|
||||||
if not self.shouldUpdate():
|
if not self.shouldUpdate():
|
||||||
return
|
return
|
||||||
|
|
||||||
if self._checkAuth(None):
|
if self._checkAuth(None):
|
||||||
|
|
||||||
data = self._getRSSData()
|
data = 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 data:
|
||||||
self.setLastUpdate()
|
self.setLastUpdate()
|
||||||
else:
|
else:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
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()
|
||||||
|
|
||||||
parsedJSON = helpers.parse_json(data)
|
parsedJSON = helpers.parse_json(data)
|
||||||
|
|
||||||
if parsedJSON is None:
|
if parsedJSON is None:
|
||||||
logger.log(u"Error trying to load " + self.provider.name + " JSON feed", logger.ERROR)
|
logger.log(u"Error trying to load " + self.provider.name + " JSON feed", logger.ERROR)
|
||||||
return []
|
return []
|
||||||
|
|
||||||
if self._checkAuth(parsedJSON):
|
if self._checkAuth(parsedJSON):
|
||||||
if parsedJSON and 'data' in parsedJSON:
|
if parsedJSON and 'data' in parsedJSON:
|
||||||
items = parsedJSON['data']
|
items = parsedJSON['data']
|
||||||
else:
|
else:
|
||||||
logger.log(u"Resulting JSON from " + self.provider.name + " isn't correct, not parsing it", logger.ERROR)
|
logger.log(u"Resulting JSON from " + self.provider.name + " isn't correct, not parsing it",
|
||||||
return []
|
logger.ERROR)
|
||||||
|
return []
|
||||||
|
|
||||||
ql = []
|
ql = []
|
||||||
for item in items:
|
for item in items:
|
||||||
|
|
||||||
@ -231,26 +233,29 @@ class HDBitsCache(tvcache.TVCache):
|
|||||||
myDB.mass_action(ql)
|
myDB.mass_action(ql)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise exceptions.AuthException("Your authentication info for " + self.provider.name + " is incorrect, check your config")
|
raise exceptions.AuthException(
|
||||||
|
"Your authentication info for " + self.provider.name + " is incorrect, check your config")
|
||||||
else:
|
|
||||||
return []
|
else:
|
||||||
|
return []
|
||||||
def _getRSSData(self):
|
|
||||||
return self.provider.getURL(self.provider.rss_url, post_data=self.provider._make_post_data_JSON())
|
def _getRSSData(self):
|
||||||
|
return self.provider.getURL(self.provider.rss_url, post_data=self.provider._make_post_data_JSON())
|
||||||
def _parseItem(self, item):
|
|
||||||
|
def _parseItem(self, item):
|
||||||
(title, url) = self.provider._get_title_and_url(item)
|
|
||||||
|
(title, url) = self.provider._get_title_and_url(item)
|
||||||
if title and url:
|
|
||||||
logger.log(u"Adding item to results: " + title, logger.DEBUG)
|
if title and url:
|
||||||
return self._addCacheEntry(title, url)
|
logger.log(u"Adding item to results: " + title, logger.DEBUG)
|
||||||
else:
|
return self._addCacheEntry(title, url)
|
||||||
logger.log(u"The data returned from the " + self.provider.name + " is incomplete, this result is unusable", logger.ERROR)
|
else:
|
||||||
return None
|
logger.log(u"The data returned from the " + self.provider.name + " is incomplete, this result is unusable",
|
||||||
|
logger.ERROR)
|
||||||
def _checkAuth(self, data):
|
return None
|
||||||
return self.provider._checkAuthFromData(data)
|
|
||||||
|
def _checkAuth(self, data):
|
||||||
|
return self.provider._checkAuthFromData(data)
|
||||||
|
|
||||||
|
|
||||||
provider = HDBitsProvider()
|
provider = HDBitsProvider()
|
||||||
|
Loading…
Reference in New Issue
Block a user