mirror of
https://github.com/SickGear/SickGear.git
synced 2024-12-11 21:53:37 +00:00
0ead7771de
Add the improved error handling to torrent providers. Change cache_db to always include db upgrade statements when running SG for the first time. Change split newznab limit logic into a reusable function, hit_limit_update() and use in BTN prov. Change tweak CSS to make things a little neater with button spacings. Add the actual time when current limit will expire to the UI. Change instead of terminology "errors", use "failures". Change improve BTN error handling. Change ensure provider name is output to log at times where it wasn't. Change ensure failed request URLs and POST params are output to log. Add time of last failure + type to should_skip log message. Change code DRY and simplification for improved readability. Change occurrences of "error" to "fail" for consistency. Add tmr limit handling to omg and change log_failure_url level to warning. Change log the failed URL when an API hit limit is reached. Change "hit" to the more universally generic "tmr" - Too Many Requests. Change Db columns containing "hit_" are renamed "tmr_"
134 lines
5.2 KiB
Python
134 lines
5.2 KiB
Python
#
|
|
# This file is part of SickGear.
|
|
#
|
|
# SickGear 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.
|
|
#
|
|
# SickGear 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 SickGear. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
import re
|
|
import traceback
|
|
import urllib
|
|
|
|
from . import generic
|
|
from sickbeard import logger, show_name_helpers, tvcache
|
|
from sickbeard.helpers import tryInt
|
|
from sickbeard.bs4_parser import BS4Parser
|
|
|
|
|
|
class TokyoToshokanProvider(generic.TorrentProvider):
|
|
|
|
def __init__(self):
|
|
generic.TorrentProvider.__init__(self, 'TokyoToshokan', anime_only=True)
|
|
|
|
self.url_base = self.url = 'https://tokyotosho.info/'
|
|
|
|
self.cache = TokyoToshokanCache(self)
|
|
|
|
def _search_provider(self, search_string, search_mode='eponly', **kwargs):
|
|
|
|
results = []
|
|
if self.show and not self.show.is_anime:
|
|
return results
|
|
|
|
params = urllib.urlencode({'terms': search_string.encode('utf-8'),
|
|
'type': 1}) # get anime types
|
|
|
|
search_url = '%ssearch.php?%s' % (self.url, params)
|
|
mode = ('Episode', 'Season')['sponly' == search_mode]
|
|
|
|
rc = dict((k, re.compile('(?i)' + v)) for (k, v) in {
|
|
'stats': 'S:\s*?(\d)+\s*L:\s*(\d+)', 'size': 'size:\s*(\d+[.,]\d+\w+)'}.iteritems())
|
|
|
|
html = self.get_url(search_url)
|
|
if self.should_skip():
|
|
return self._sort_seeding(mode, results)
|
|
|
|
if html:
|
|
try:
|
|
with BS4Parser(html, features=['html5lib', 'permissive']) as soup:
|
|
torrent_table = soup.find('table', class_='listing')
|
|
torrent_rows = [] if not torrent_table else torrent_table.find_all('tr')
|
|
if torrent_rows:
|
|
a = (0, 1)[None is not torrent_rows[0].find('td', class_='centertext')]
|
|
|
|
for top, bottom in zip(torrent_rows[a::2], torrent_rows[a+1::2]):
|
|
try:
|
|
bottom_text = bottom.get_text() or ''
|
|
stats = rc['stats'].findall(bottom_text)
|
|
seeders, leechers = (0, 0) if not stats else [tryInt(n) for n in stats[0]]
|
|
|
|
size = rc['size'].findall(bottom_text)
|
|
size = size and size[0] or -1
|
|
|
|
info = top.find('td', class_='desc-top')
|
|
title = info and re.sub(r'[ .]{2,}', '.', info.get_text().strip())
|
|
urls = info and sorted([x.get('href') for x in info.find_all('a') or []])
|
|
download_url = urls and urls[0].startswith('http') and urls[0] or urls[1]
|
|
except (AttributeError, TypeError, ValueError, IndexError):
|
|
continue
|
|
|
|
if title and download_url:
|
|
results.append((title, download_url, seeders, self._bytesizer(size)))
|
|
|
|
except (StandardError, Exception):
|
|
logger.log(u'Failed to parse. Traceback: %s' % traceback.format_exc(), logger.ERROR)
|
|
|
|
self._log_search(mode, len(results), search_url)
|
|
|
|
return self._sort_seeding(mode, results)
|
|
|
|
def _season_strings(self, ep_obj, **kwargs):
|
|
|
|
return [x.replace('.', ' ') for x in show_name_helpers.makeSceneSeasonSearchString(self.show, ep_obj)]
|
|
|
|
def _episode_strings(self, ep_obj, **kwargs):
|
|
|
|
return [x.replace('.', ' ') for x in show_name_helpers.makeSceneSearchString(self.show, ep_obj)]
|
|
|
|
|
|
class TokyoToshokanCache(tvcache.TVCache):
|
|
|
|
def __init__(self, this_provider):
|
|
tvcache.TVCache.__init__(self, this_provider)
|
|
|
|
self.update_freq = 15
|
|
|
|
def _cache_data(self, **kwargs):
|
|
|
|
mode = 'Cache'
|
|
search_url = '%srss.php?%s' % (self.provider.url, urllib.urlencode({'filter': '1'}))
|
|
data = self.get_rss(search_url)
|
|
|
|
results = []
|
|
if data and 'entries' in data:
|
|
|
|
rc = dict((k, re.compile('(?i)' + v)) for (k, v) in {'size': 'size:\s*(\d+[.,]\d+\w+)'}.iteritems())
|
|
|
|
for cur_item in data.get('entries', []):
|
|
try:
|
|
title, download_url = self._title_and_url(cur_item)
|
|
size = rc['size'].findall(cur_item.get('summary_detail', {'value': ''}).get('value', ''))
|
|
size = size and size[0] or -1
|
|
|
|
except (AttributeError, TypeError, ValueError):
|
|
continue
|
|
|
|
if title and download_url:
|
|
# feed does not carry seed, leech counts
|
|
results.append((title, download_url, 0, self.provider._bytesizer(size)))
|
|
|
|
self.provider._log_search(mode, len(results), search_url)
|
|
|
|
return results
|
|
|
|
|
|
provider = TokyoToshokanProvider()
|