2014-03-10 01:18:05 -04:00
|
|
|
# Author: Jordon Smith <smith@jordon.me.uk>
|
|
|
|
# URL: http://code.google.com/p/sickbeard/
|
|
|
|
#
|
2014-05-23 08:37:22 -04:00
|
|
|
# This file is part of SickRage.
|
2014-03-10 01:18:05 -04:00
|
|
|
#
|
2014-05-23 08:37:22 -04:00
|
|
|
# SickRage is free software: you can redistribute it and/or modify
|
2014-03-10 01:18:05 -04:00
|
|
|
# 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.
|
|
|
|
#
|
2014-05-23 08:37:22 -04:00
|
|
|
# SickRage is distributed in the hope that it will be useful,
|
2014-03-10 01:18:05 -04:00
|
|
|
# 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
|
2014-05-23 08:37:22 -04:00
|
|
|
# along with SickRage. If not, see <http://www.gnu.org/licenses/>.
|
2014-03-10 01:18:05 -04:00
|
|
|
|
|
|
|
import urllib
|
|
|
|
import generic
|
|
|
|
import sickbeard
|
|
|
|
|
|
|
|
from sickbeard import tvcache
|
|
|
|
from sickbeard import helpers
|
|
|
|
from sickbeard import classes
|
|
|
|
from sickbeard import logger
|
|
|
|
from sickbeard.exceptions import ex, AuthException
|
|
|
|
from sickbeard import show_name_helpers
|
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
try:
|
|
|
|
import xml.etree.cElementTree as etree
|
|
|
|
except ImportError:
|
|
|
|
import elementtree.ElementTree as etree
|
|
|
|
|
|
|
|
try:
|
|
|
|
import json
|
|
|
|
except ImportError:
|
|
|
|
from lib import simplejson as json
|
|
|
|
|
|
|
|
|
|
|
|
class OmgwtfnzbsProvider(generic.NZBProvider):
|
|
|
|
def __init__(self):
|
|
|
|
generic.NZBProvider.__init__(self, "omgwtfnzbs")
|
2014-05-19 22:14:06 -04:00
|
|
|
self.enabled = False
|
|
|
|
self.username = None
|
|
|
|
self.api_key = None
|
2014-03-10 01:18:05 -04:00
|
|
|
self.cache = OmgwtfnzbsCache(self)
|
|
|
|
self.url = 'https://omgwtfnzbs.org/'
|
|
|
|
self.supportsBacklog = True
|
|
|
|
|
|
|
|
def isEnabled(self):
|
2014-05-19 22:14:06 -04:00
|
|
|
return self.enabled
|
2014-03-10 01:18:05 -04:00
|
|
|
|
|
|
|
def _checkAuth(self):
|
|
|
|
|
2014-05-19 22:14:06 -04:00
|
|
|
if not self.username or not self.api_key:
|
2014-03-10 01:18:05 -04:00
|
|
|
raise AuthException("Your authentication credentials for " + self.name + " are missing, check your config.")
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
def _checkAuthFromData(self, parsed_data, is_XML=True):
|
|
|
|
|
|
|
|
if parsed_data is None:
|
|
|
|
return self._checkAuth()
|
|
|
|
|
|
|
|
if is_XML:
|
|
|
|
# provider doesn't return xml on error
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
parsedJSON = parsed_data
|
|
|
|
|
|
|
|
if 'notice' in parsedJSON:
|
|
|
|
description_text = parsedJSON.get('notice')
|
|
|
|
|
|
|
|
if 'information is incorrect' in parsedJSON.get('notice'):
|
2014-03-25 01:57:24 -04:00
|
|
|
logger.log(u"Incorrect authentication credentials for " + self.name + " : " + str(description_text),
|
|
|
|
logger.DEBUG)
|
|
|
|
raise AuthException(
|
|
|
|
"Your authentication credentials for " + self.name + " are incorrect, check your config.")
|
2014-03-10 01:18:05 -04:00
|
|
|
|
|
|
|
elif '0 results matched your terms' in parsedJSON.get('notice'):
|
|
|
|
return True
|
|
|
|
|
|
|
|
else:
|
|
|
|
logger.log(u"Unknown error given from " + self.name + " : " + str(description_text), logger.DEBUG)
|
|
|
|
return False
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
2014-04-30 09:49:50 -04:00
|
|
|
def _get_season_search_strings(self, ep_obj):
|
|
|
|
return [x for x in show_name_helpers.makeSceneSeasonSearchString(self.show, ep_obj)]
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-04-30 09:49:50 -04:00
|
|
|
def _get_episode_search_strings(self, ep_obj, add_string=''):
|
|
|
|
return [x for x in show_name_helpers.makeSceneSearchString(self.show, ep_obj)]
|
2014-03-10 01:18:05 -04:00
|
|
|
|
|
|
|
def _get_title_and_url(self, item):
|
|
|
|
return (item['release'], item['getnzb'])
|
|
|
|
|
2014-05-26 02:29:22 -04:00
|
|
|
def _doSearch(self, search, epcount=0, retention=0):
|
2014-03-10 01:18:05 -04:00
|
|
|
|
|
|
|
self._checkAuth()
|
|
|
|
|
2014-05-19 22:14:06 -04:00
|
|
|
params = {'user': self.username,
|
|
|
|
'api': self.api_key,
|
2014-03-10 01:18:05 -04:00
|
|
|
'eng': 1,
|
|
|
|
'catid': '19,20', # SD,HD
|
|
|
|
'retention': sickbeard.USENET_RETENTION,
|
|
|
|
'search': search}
|
|
|
|
|
|
|
|
if retention or not params['retention']:
|
|
|
|
params['retention'] = retention
|
|
|
|
|
|
|
|
search_url = 'https://api.omgwtfnzbs.org/json/?' + urllib.urlencode(params)
|
|
|
|
logger.log(u"Search url: " + search_url, logger.DEBUG)
|
|
|
|
|
2014-04-25 23:42:35 -04:00
|
|
|
data = self.getURL(search_url, json=True)
|
2014-03-10 01:18:05 -04:00
|
|
|
|
|
|
|
if not data:
|
|
|
|
logger.log(u"No data returned from " + search_url, logger.ERROR)
|
|
|
|
return []
|
|
|
|
|
2014-04-25 23:42:35 -04:00
|
|
|
if self._checkAuthFromData(data, is_XML=False):
|
2014-03-10 01:18:05 -04:00
|
|
|
|
|
|
|
results = []
|
|
|
|
|
2014-04-25 23:42:35 -04:00
|
|
|
for item in data:
|
2014-03-10 01:18:05 -04:00
|
|
|
if 'release' in item and 'getnzb' in item:
|
|
|
|
results.append(item)
|
|
|
|
|
|
|
|
return results
|
|
|
|
|
|
|
|
return []
|
|
|
|
|
|
|
|
def findPropers(self, search_date=None):
|
|
|
|
search_terms = ['.PROPER.', '.REPACK.']
|
|
|
|
results = []
|
|
|
|
|
|
|
|
for term in search_terms:
|
|
|
|
for item in self._doSearch(term, retention=4):
|
|
|
|
if 'usenetage' in item:
|
|
|
|
|
|
|
|
title, url = self._get_title_and_url(item)
|
|
|
|
try:
|
2014-06-10 08:31:51 -04:00
|
|
|
result_date = datetime.fromtimestamp(int(item['usenetage']))
|
|
|
|
except:
|
2014-03-10 01:18:05 -04:00
|
|
|
result_date = None
|
|
|
|
|
|
|
|
if result_date:
|
2014-07-14 22:00:53 -04:00
|
|
|
results.append(classes.Proper(title, url, result_date, self.show))
|
2014-03-10 01:18:05 -04:00
|
|
|
|
|
|
|
return results
|
|
|
|
|
|
|
|
|
|
|
|
class OmgwtfnzbsCache(tvcache.TVCache):
|
|
|
|
def __init__(self, provider):
|
|
|
|
tvcache.TVCache.__init__(self, provider)
|
|
|
|
self.minTime = 20
|
|
|
|
|
|
|
|
def _getRSSData(self):
|
2014-05-19 22:14:06 -04:00
|
|
|
params = {'user': provider.username,
|
|
|
|
'api': provider.api_key,
|
2014-03-10 01:18:05 -04:00
|
|
|
'eng': 1,
|
|
|
|
'catid': '19,20'} # SD,HD
|
|
|
|
|
|
|
|
rss_url = 'https://rss.omgwtfnzbs.org/rss-download.php?' + urllib.urlencode(params)
|
|
|
|
|
|
|
|
logger.log(self.provider.name + u" cache update URL: " + rss_url, logger.DEBUG)
|
|
|
|
|
2014-05-04 08:05:27 -04:00
|
|
|
return self.getRSSFeed(rss_url)
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-04-25 21:49:38 -04:00
|
|
|
def _checkAuth(self, data):
|
|
|
|
return self.provider._checkAuthFromData(data)
|
2014-03-10 01:18:05 -04:00
|
|
|
|
|
|
|
provider = OmgwtfnzbsProvider()
|