2014-03-10 05:18:05 +00:00
|
|
|
# Author: Jordon Smith <smith@jordon.me.uk>
|
|
|
|
# URL: http://code.google.com/p/sickbeard/
|
|
|
|
#
|
2014-11-12 16:43:14 +00:00
|
|
|
# This file is part of SickGear.
|
2014-03-10 05:18:05 +00:00
|
|
|
#
|
2014-11-12 16:43:14 +00:00
|
|
|
# SickGear is free software: you can redistribute it and/or modify
|
2014-03-10 05:18:05 +00: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-11-12 16:43:14 +00:00
|
|
|
# SickGear is distributed in the hope that it will be useful,
|
2014-03-10 05:18:05 +00: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-11-12 16:43:14 +00:00
|
|
|
# along with SickGear. If not, see <http://www.gnu.org/licenses/>.
|
2014-03-10 05:18:05 +00:00
|
|
|
|
2015-04-18 04:55:04 +00:00
|
|
|
from datetime import datetime
|
2015-09-18 00:06:34 +00:00
|
|
|
import re
|
2015-07-13 09:39:20 +00:00
|
|
|
import time
|
|
|
|
import traceback
|
2015-09-18 00:06:34 +00:00
|
|
|
import urllib
|
2015-04-18 04:55:04 +00:00
|
|
|
|
2018-01-24 02:24:00 +00:00
|
|
|
import feedparser
|
2014-03-10 05:18:05 +00:00
|
|
|
import sickbeard
|
2015-09-18 00:06:34 +00:00
|
|
|
|
|
|
|
from . import generic
|
|
|
|
from sickbeard import classes, logger, show_name_helpers, tvcache
|
|
|
|
from sickbeard.bs4_parser import BS4Parser
|
2015-04-18 04:55:04 +00:00
|
|
|
from sickbeard.exceptions import AuthException
|
2017-08-02 21:13:02 +00:00
|
|
|
from sickbeard.common import neededQualities
|
2014-03-10 05:18:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
class OmgwtfnzbsProvider(generic.NZBProvider):
|
2015-07-13 09:39:20 +00:00
|
|
|
|
2014-03-10 05:18:05 +00:00
|
|
|
def __init__(self):
|
2015-07-13 09:39:20 +00:00
|
|
|
generic.NZBProvider.__init__(self, 'omgwtfnzbs')
|
|
|
|
|
2016-10-24 23:04:02 +00:00
|
|
|
self.url = 'https://omgwtfnzbs.me/'
|
|
|
|
self.url_base = 'https://omgwtfnzbs.me/'
|
|
|
|
self.url_api = 'https://api.omgwtfnzbs.me/'
|
2015-07-13 09:39:20 +00:00
|
|
|
self.urls = {'config_provider_home_uri': self.url_base,
|
2018-01-24 02:24:00 +00:00
|
|
|
'cache': self.url_api + 'xml/?%s',
|
2016-06-20 09:29:26 +00:00
|
|
|
'search': self.url_api + 'json/?%s',
|
2015-07-13 09:39:20 +00:00
|
|
|
'cache_html': self.url_base + 'browse.php?cat=tv%s',
|
|
|
|
'search_html': self.url_base + 'browse.php?cat=tv&search=%s'}
|
2014-03-10 05:18:05 +00:00
|
|
|
|
2015-07-13 09:39:20 +00:00
|
|
|
self.needs_auth = True
|
|
|
|
self.username, self.api_key, self.cookies = 3 * [None]
|
|
|
|
self.cache = OmgwtfnzbsCache(self)
|
2014-03-10 05:18:05 +00:00
|
|
|
|
2017-08-02 21:13:02 +00:00
|
|
|
cat_sd = ['19']
|
|
|
|
cat_hd = ['20']
|
|
|
|
cat_uhd = ['30']
|
|
|
|
|
2015-07-13 09:39:20 +00:00
|
|
|
def _check_auth_from_data(self, parsed_data, is_xml=True):
|
2014-03-10 05:18:05 +00:00
|
|
|
|
|
|
|
if parsed_data is None:
|
2015-07-13 09:39:20 +00:00
|
|
|
return self._check_auth()
|
2014-03-10 05:18:05 +00:00
|
|
|
|
2015-07-13 09:39:20 +00:00
|
|
|
if is_xml:
|
2014-03-10 05:18:05 +00:00
|
|
|
# provider doesn't return xml on error
|
|
|
|
return True
|
|
|
|
else:
|
2015-07-13 09:39:20 +00:00
|
|
|
data_json = parsed_data
|
2014-03-10 05:18:05 +00:00
|
|
|
|
2015-07-13 09:39:20 +00:00
|
|
|
if 'notice' in data_json:
|
|
|
|
description_text = data_json.get('notice')
|
2014-03-10 05:18:05 +00:00
|
|
|
|
2018-01-24 02:24:00 +00:00
|
|
|
if re.search('(?i)(information is incorrect|in(?:valid|correct).*?(?:username|api))',
|
|
|
|
data_json.get('notice')):
|
2015-07-13 09:39:20 +00:00
|
|
|
logger.log(u'Incorrect authentication credentials for ' + self.name + ' : ' + str(description_text),
|
2014-03-25 05:57:24 +00:00
|
|
|
logger.DEBUG)
|
|
|
|
raise AuthException(
|
2015-07-13 09:39:20 +00:00
|
|
|
'Your authentication credentials for ' + self.name + ' are incorrect, check your config.')
|
2014-03-10 05:18:05 +00:00
|
|
|
|
2015-07-13 09:39:20 +00:00
|
|
|
elif '0 results matched your terms' in data_json.get('notice'):
|
2014-03-10 05:18:05 +00:00
|
|
|
return True
|
|
|
|
|
|
|
|
else:
|
2015-07-13 09:39:20 +00:00
|
|
|
logger.log(u'Unknown error given from ' + self.name + ' : ' + str(description_text), logger.DEBUG)
|
2014-03-10 05:18:05 +00:00
|
|
|
return False
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
def _season_strings(self, ep_obj):
|
2015-07-13 09:39:20 +00:00
|
|
|
|
2014-04-30 13:49:50 +00:00
|
|
|
return [x for x in show_name_helpers.makeSceneSeasonSearchString(self.show, ep_obj)]
|
2014-03-10 05:18:05 +00:00
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
def _episode_strings(self, ep_obj):
|
2015-07-13 09:39:20 +00:00
|
|
|
|
2014-04-30 13:49:50 +00:00
|
|
|
return [x for x in show_name_helpers.makeSceneSearchString(self.show, ep_obj)]
|
2014-03-10 05:18:05 +00:00
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
def _title_and_url(self, item):
|
2014-03-10 05:18:05 +00:00
|
|
|
|
2016-06-17 18:59:46 +00:00
|
|
|
return item['release'].replace('_', '.'), item['getnzb']
|
2014-03-10 05:18:05 +00:00
|
|
|
|
2017-02-13 20:00:55 +00:00
|
|
|
def get_data(self, url):
|
|
|
|
result = None
|
|
|
|
if url and False is self._init_api():
|
2018-01-15 17:54:36 +00:00
|
|
|
data = self.get_url(url, timeout=90)
|
|
|
|
if self.should_skip():
|
|
|
|
return result
|
2017-02-13 20:00:55 +00:00
|
|
|
if data:
|
|
|
|
if re.search('(?i)limit.*?reached', data):
|
2018-01-15 17:54:36 +00:00
|
|
|
self.tmr_limit_update('1', 'h', 'Your 24 hour limit of 10 NZBs has been reached')
|
|
|
|
self.log_failure_url(url)
|
2017-02-13 20:00:55 +00:00
|
|
|
elif '</nzb>' not in data or 'seem to be logged in' in data:
|
|
|
|
logger.log('Failed nzb data response: %s' % data, logger.DEBUG)
|
|
|
|
else:
|
|
|
|
result = data
|
|
|
|
return result
|
|
|
|
|
2015-07-13 09:39:20 +00:00
|
|
|
def get_result(self, episodes, url):
|
2014-03-10 05:18:05 +00:00
|
|
|
|
2015-07-13 09:39:20 +00:00
|
|
|
result = None
|
|
|
|
if url and False is self._init_api():
|
2016-01-07 16:17:36 +00:00
|
|
|
result = classes.NZBDataSearchResult(episodes)
|
2017-02-13 20:00:55 +00:00
|
|
|
result.get_data_func = self.get_data
|
|
|
|
result.url = url
|
2014-03-10 05:18:05 +00:00
|
|
|
|
2015-07-13 09:39:20 +00:00
|
|
|
if None is result:
|
|
|
|
result = classes.NZBSearchResult(episodes)
|
|
|
|
result.url = url
|
2014-03-10 05:18:05 +00:00
|
|
|
|
2015-07-13 09:39:20 +00:00
|
|
|
result.provider = self
|
2014-03-10 05:18:05 +00:00
|
|
|
|
2015-07-13 09:39:20 +00:00
|
|
|
return result
|
2014-03-10 05:18:05 +00:00
|
|
|
|
2018-01-24 02:24:00 +00:00
|
|
|
@staticmethod
|
|
|
|
def _get_cats(needed):
|
2017-08-02 21:13:02 +00:00
|
|
|
cats = []
|
|
|
|
if needed.need_sd:
|
|
|
|
cats.extend(OmgwtfnzbsProvider.cat_sd)
|
|
|
|
if needed.need_hd:
|
|
|
|
cats.extend(OmgwtfnzbsProvider.cat_hd)
|
|
|
|
if needed.need_uhd:
|
|
|
|
cats.extend(OmgwtfnzbsProvider.cat_uhd)
|
|
|
|
return cats
|
|
|
|
|
|
|
|
def cache_data(self, needed=neededQualities(need_all=True), **kwargs):
|
2014-03-10 05:18:05 +00:00
|
|
|
|
2017-11-02 18:30:05 +00:00
|
|
|
if self.should_skip():
|
|
|
|
return []
|
|
|
|
|
2015-07-13 09:39:20 +00:00
|
|
|
api_key = self._init_api()
|
|
|
|
if False is api_key:
|
2017-08-02 21:13:02 +00:00
|
|
|
return self.search_html(needed=needed, **kwargs)
|
2018-01-24 02:24:00 +00:00
|
|
|
results = []
|
2017-08-02 21:13:02 +00:00
|
|
|
cats = self._get_cats(needed=needed)
|
2015-07-13 09:39:20 +00:00
|
|
|
if None is not api_key:
|
2018-01-24 02:24:00 +00:00
|
|
|
params = {'search': '',
|
|
|
|
'user': self.username,
|
2015-07-13 09:39:20 +00:00
|
|
|
'api': api_key,
|
|
|
|
'eng': 1,
|
2017-08-02 21:13:02 +00:00
|
|
|
'catid': ','.join(cats)} # SD,HD
|
2014-03-10 05:18:05 +00:00
|
|
|
|
2018-01-24 02:24:00 +00:00
|
|
|
url = self.urls['cache'] % urllib.urlencode(params)
|
2015-07-13 09:39:20 +00:00
|
|
|
|
2018-01-24 02:24:00 +00:00
|
|
|
response = self.get_url(url)
|
2018-01-15 17:54:36 +00:00
|
|
|
if self.should_skip():
|
|
|
|
return results
|
2014-03-10 05:18:05 +00:00
|
|
|
|
2018-01-24 02:24:00 +00:00
|
|
|
data = feedparser.parse(response.replace('<xml', '<?xml').replace('>\n<info>', '?>\n<feed>\n<info>')
|
|
|
|
.replace('<search_req>\n', '').replace('</search_req>\n', '')
|
|
|
|
.replace('post>\n', 'entry>\n').replace('</xml>', '</feed>'))
|
2015-07-13 09:39:20 +00:00
|
|
|
if data and 'entries' in data:
|
2018-01-24 02:24:00 +00:00
|
|
|
results = data.entries
|
|
|
|
|
|
|
|
self._log_search('Cache', len(results), url)
|
|
|
|
return results
|
2014-03-10 05:18:05 +00:00
|
|
|
|
2017-08-02 21:13:02 +00:00
|
|
|
def _search_provider(self, search, search_mode='eponly', epcount=0, retention=0,
|
|
|
|
needed=neededQualities(need_all=True), **kwargs):
|
2015-07-13 09:39:20 +00:00
|
|
|
|
|
|
|
api_key = self._init_api()
|
|
|
|
if False is api_key:
|
2017-08-02 21:13:02 +00:00
|
|
|
return self.search_html(search, search_mode, needed=needed, **kwargs)
|
2015-07-13 09:39:20 +00:00
|
|
|
results = []
|
2017-08-02 21:13:02 +00:00
|
|
|
cats = self._get_cats(needed=needed)
|
2015-07-13 09:39:20 +00:00
|
|
|
if None is not api_key:
|
|
|
|
params = {'user': self.username,
|
|
|
|
'api': api_key,
|
|
|
|
'eng': 1,
|
2016-06-17 18:59:46 +00:00
|
|
|
'nukes': 1,
|
2017-08-02 21:13:02 +00:00
|
|
|
'catid': ','.join(cats), # SD,HD
|
2018-01-24 02:24:00 +00:00
|
|
|
'retention': retention or sickbeard.USENET_RETENTION or 0,
|
2015-07-13 09:39:20 +00:00
|
|
|
'search': search}
|
|
|
|
|
|
|
|
search_url = self.urls['search'] % urllib.urlencode(params)
|
|
|
|
|
2018-01-15 17:54:36 +00:00
|
|
|
data_json = self.get_url(search_url, json=True)
|
|
|
|
if self.should_skip():
|
|
|
|
return results
|
2015-07-13 09:39:20 +00:00
|
|
|
if data_json and self._check_auth_from_data(data_json, is_xml=False):
|
|
|
|
for item in data_json:
|
|
|
|
if 'release' in item and 'getnzb' in item:
|
2016-06-17 18:59:46 +00:00
|
|
|
if item.get('nuked', '').startswith('1'):
|
|
|
|
continue
|
2015-07-13 09:39:20 +00:00
|
|
|
results.append(item)
|
2018-01-24 02:24:00 +00:00
|
|
|
|
|
|
|
mode = search_mode
|
|
|
|
if 'eponly' == search_mode:
|
|
|
|
mode = 'Episode'
|
|
|
|
elif 'sponly' == search_mode:
|
|
|
|
mode = 'Season'
|
|
|
|
self._log_search(mode, len(results), search_url)
|
2015-07-13 09:39:20 +00:00
|
|
|
return results
|
|
|
|
|
2017-08-02 21:13:02 +00:00
|
|
|
def search_html(self, search='', search_mode='', needed=neededQualities(need_all=True), **kwargs):
|
2015-07-13 09:39:20 +00:00
|
|
|
|
|
|
|
results = []
|
|
|
|
if None is self.cookies:
|
|
|
|
return results
|
|
|
|
|
2017-08-02 21:13:02 +00:00
|
|
|
cats = self._get_cats(needed=needed)
|
|
|
|
|
2015-07-13 09:39:20 +00:00
|
|
|
rc = dict((k, re.compile('(?i)' + v)) for (k, v) in {'info': 'detail', 'get': r'send\?', 'nuked': r'\bnuked',
|
2017-08-02 21:13:02 +00:00
|
|
|
'cat': 'cat=(?:%s)' % '|'.join(cats)}.items())
|
2015-07-13 09:39:20 +00:00
|
|
|
mode = ('search', 'cache')['' == search]
|
|
|
|
search_url = self.urls[mode + '_html'] % search
|
2018-01-15 17:54:36 +00:00
|
|
|
html = self.get_url(search_url)
|
|
|
|
if self.should_skip():
|
|
|
|
return results
|
2015-07-13 09:39:20 +00:00
|
|
|
cnt = len(results)
|
|
|
|
try:
|
|
|
|
if not html:
|
|
|
|
raise generic.HaltParseException
|
|
|
|
|
|
|
|
with BS4Parser(html, features=['html5lib', 'permissive']) as soup:
|
|
|
|
torrent_table = soup.find('table', attrs={'id': 'table_table'})
|
|
|
|
torrent_rows = []
|
|
|
|
if torrent_table:
|
|
|
|
torrent_rows = torrent_table.find('tbody').find_all('tr')
|
|
|
|
|
|
|
|
if 1 > len(torrent_rows):
|
|
|
|
raise generic.HaltParseException
|
|
|
|
|
|
|
|
for tr in torrent_rows:
|
|
|
|
try:
|
|
|
|
if tr.find('img', src=rc['nuked']) or not tr.find('a', href=rc['cat']):
|
|
|
|
continue
|
|
|
|
|
2017-02-13 20:00:55 +00:00
|
|
|
title = tr.find('a', href=rc['info']).get_text().strip()
|
2015-07-13 09:39:20 +00:00
|
|
|
download_url = tr.find('a', href=rc['get'])
|
|
|
|
age = tr.find_all('td')[-1]['data-sort']
|
2015-09-18 00:06:34 +00:00
|
|
|
except (AttributeError, TypeError, ValueError):
|
2015-07-13 09:39:20 +00:00
|
|
|
continue
|
|
|
|
|
|
|
|
if title and download_url and age:
|
2017-10-15 00:19:10 +00:00
|
|
|
results.append({'release': title, 'getnzb': self._link(download_url['href']),
|
2015-07-13 09:39:20 +00:00
|
|
|
'usenetage': int(age.strip())})
|
|
|
|
|
|
|
|
except generic.HaltParseException:
|
|
|
|
time.sleep(1.1)
|
|
|
|
pass
|
2016-08-26 23:36:01 +00:00
|
|
|
except (StandardError, Exception):
|
2015-07-13 09:39:20 +00:00
|
|
|
logger.log(u'Failed to parse. Traceback: %s' % traceback.format_exc(), logger.ERROR)
|
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
mode = (mode, search_mode)['Propers' == search_mode]
|
|
|
|
self._log_search(mode, len(results) - cnt, search_url)
|
2015-07-13 09:39:20 +00:00
|
|
|
return results
|
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
def find_propers(self, **kwargs):
|
2015-07-13 09:39:20 +00:00
|
|
|
|
2017-09-13 17:18:59 +00:00
|
|
|
search_terms = ['.PROPER.', '.REPACK.', '.REAL.']
|
2014-03-10 05:18:05 +00:00
|
|
|
results = []
|
2017-11-02 18:30:05 +00:00
|
|
|
if self.should_skip():
|
|
|
|
return results
|
2014-03-10 05:18:05 +00:00
|
|
|
|
|
|
|
for term in search_terms:
|
2015-09-18 00:06:34 +00:00
|
|
|
for item in self._search_provider(term, search_mode='Propers', retention=4):
|
2014-03-10 05:18:05 +00:00
|
|
|
if 'usenetage' in item:
|
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
title, url = self._title_and_url(item)
|
2014-03-10 05:18:05 +00:00
|
|
|
try:
|
2014-06-10 12:31:51 +00:00
|
|
|
result_date = datetime.fromtimestamp(int(item['usenetage']))
|
2016-08-26 23:36:01 +00:00
|
|
|
except (StandardError, Exception):
|
2014-03-10 05:18:05 +00:00
|
|
|
result_date = None
|
|
|
|
|
|
|
|
if result_date:
|
2014-07-15 02:00:53 +00:00
|
|
|
results.append(classes.Proper(title, url, result_date, self.show))
|
2014-03-10 05:18:05 +00:00
|
|
|
|
|
|
|
return results
|
|
|
|
|
2015-07-13 09:39:20 +00:00
|
|
|
def _init_api(self):
|
2014-03-10 05:18:05 +00:00
|
|
|
|
2017-11-02 18:30:05 +00:00
|
|
|
if self.should_skip():
|
|
|
|
return None
|
|
|
|
|
2015-07-13 09:39:20 +00:00
|
|
|
try:
|
|
|
|
api_key = self._check_auth()
|
|
|
|
if not api_key.startswith('cookie:'):
|
|
|
|
return api_key
|
2016-08-26 23:36:01 +00:00
|
|
|
except (StandardError, Exception):
|
2015-07-13 09:39:20 +00:00
|
|
|
return None
|
2014-03-10 05:18:05 +00:00
|
|
|
|
2015-07-13 09:39:20 +00:00
|
|
|
self.cookies = re.sub(r'(?i)([\s\']+|cookie\s*:)', '', api_key)
|
|
|
|
success, msg = self._check_cookie()
|
|
|
|
if not success:
|
|
|
|
logger.log(u'%s: %s' % (msg, self.cookies), logger.WARNING)
|
|
|
|
self.cookies = None
|
|
|
|
return None
|
|
|
|
return False
|
2014-08-15 03:43:11 +00:00
|
|
|
|
2015-07-13 09:39:20 +00:00
|
|
|
@staticmethod
|
|
|
|
def ui_string(key):
|
2015-09-18 00:06:34 +00:00
|
|
|
|
|
|
|
return 'omgwtfnzbs_api_key' == key and 'Or use... \'cookie: cookname=xx; cookpass=yy\'' or ''
|
2014-08-15 03:43:11 +00:00
|
|
|
|
|
|
|
|
2015-07-13 09:39:20 +00:00
|
|
|
class OmgwtfnzbsCache(tvcache.TVCache):
|
2014-08-15 03:43:11 +00:00
|
|
|
|
2015-07-13 09:39:20 +00:00
|
|
|
def __init__(self, this_provider):
|
|
|
|
tvcache.TVCache.__init__(self, this_provider)
|
2014-08-15 03:43:11 +00:00
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
self.update_freq = 20
|
|
|
|
|
2017-08-02 21:13:02 +00:00
|
|
|
def _cache_data(self, **kwargs):
|
2014-08-15 03:43:11 +00:00
|
|
|
|
2017-08-02 21:13:02 +00:00
|
|
|
return self.provider.cache_data(**kwargs)
|
2014-03-10 05:18:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
provider = OmgwtfnzbsProvider()
|