Commit f40c4719 authored by echel0n's avatar echel0n
Browse files

Refactored Zooqle torrent provider to use RSS

Fixed Attribute error for name parser
parent 7bb2095d
# Changelog
- * 33383e1 - 2018-09-16: Fixed performance issues with TheTVDB indexer
- * 03ad5fb - 2018-09-16: Refactored Zooqle torrent provider to use RSS Fixed Attribute error for name parser
- * 7bb2095 - 2018-09-16: Fixed performance issues with TheTVDB indexer
- * e8445dd - 2018-09-16: Fixed issue when displaying multiple modals same page, 2nd modal wasn't removing scrollbar.
- * 15f9781 - 2018-09-16: Pre-Release v9.3.79.dev2
- * f87f0b0 - 2018-09-16: Fixed search issue with Zooqle torrent provider.
......
......@@ -101,12 +101,14 @@ class Core(object):
self.naming_ep_type = ("%(seasonnumber)dx%(episodenumber)02d",
"s%(seasonnumber)02de%(episodenumber)02d",
"S%(seasonnumber)02dE%(episodenumber)02d",
"%(seasonnumber)02dx%(episodenumber)02d")
"%(seasonnumber)02dx%(episodenumber)02d",
"S%(seasonnumber)02d E%(episodenumber)02d")
self.sports_ep_type = ("%(seasonnumber)dx%(episodenumber)02d",
"s%(seasonnumber)02de%(episodenumber)02d",
"S%(seasonnumber)02dE%(episodenumber)02d",
"%(seasonnumber)02dx%(episodenumber)02d")
self.naming_ep_type_text = ("1x02", "s01e02", "S01E02", "01x02")
"%(seasonnumber)02dx%(episodenumber)02d",
"S%(seasonnumber)02 dE%(episodenumber)02d")
self.naming_ep_type_text = ("1x02", "s01e02", "S01E02", "01x02", "S01 E02",)
self.naming_multi_ep_type = {0: ["-%(episodenumber)02d"] * len(self.naming_ep_type),
1: [" - " + x for x in self.naming_ep_type],
2: [x + "%(episodenumber)02d" for x in ("x", "e", "E", "x")]}
......
......@@ -90,7 +90,7 @@ class TVCache(object):
return True
def getRSSFeed(self, url, params=None):
def get_rss_feed(self, url, params=None):
try:
if self.provider.login():
resp = WebSession().get(url, params=params).text
......
......@@ -511,8 +511,7 @@ class NameParser(object):
# if there's no useful info in it then raise an exception
if final_result.season_number is None and not final_result.episode_numbers and final_result.air_date is None and not final_result.ab_episode_numbers and not final_result.series_name:
raise InvalidNameException("Unable to parse {} to a valid episode of {}. Parser result: {}".format(
name, final_result.show.name, final_result))
raise InvalidNameException("Unable to parse {} to a valid episode. Parser result: {}".format(name, final_result))
if cache_result and final_result.show:
name_parser_cache.add(name, final_result)
......
......@@ -1286,7 +1286,7 @@ class TorrentRssCache(TVCache):
add_dict_to_cookiejar(self.provider.session.cookies,
dict(x.rsplit('=', 1) for x in self.provider.cookies.split(';')))
return self.getRSSFeed(self.provider.urls['base_url'])
return self.get_rss_feed(self.provider.urls['base_url'])
class SearchProviders(dict):
......
......@@ -89,7 +89,7 @@ class BinSearchCache(TVCache):
for group in ['alt.binaries.hdtv', 'alt.binaries.hdtv.x264', 'alt.binaries.tv', 'alt.binaries.tvseries']:
search_params = {'max': 50, 'g': group}
for item in self.getRSSFeed(self.provider.urls['rss'], search_params).get('entries', []):
for item in self.get_rss_feed(self.provider.urls['rss'], search_params).get('entries', []):
self._parseItem(item)
return True
......
......@@ -189,7 +189,7 @@ class ImmortalseedCache(TVCache):
'showrows': '50',
}
return self.getRSSFeed(self.provider.urls['rss'], params=params)
return self.get_rss_feed(self.provider.urls['rss'], params=params)
def _check_auth(self, data):
return self.provider._check_auth_from_data(data)
......@@ -243,7 +243,7 @@ class NewpctCache(TVCache):
def _get_rss_data(self):
results = {'entries': []}
for result in self.getRSSFeed(self.provider.urls['rss']).get('entries', []):
for result in self.get_rss_feed(self.provider.urls['rss']).get('entries', []):
if 'Series' in result.category:
title = self.provider._process_title(result.title, result.link)
link = self.provider._process_link(result.link)
......
......@@ -68,7 +68,7 @@ class NyaaProvider(TorrentProvider):
sickrage.app.log.debug('Search string: {}'.format(search_string))
search_params['q'] = search_string
data = self.cache.getRSSFeed(self.urls['base_url'], params=search_params)
data = self.cache.get_rss_feed(self.urls['base_url'], params=search_params)
if not data:
sickrage.app.log.debug('No data returned from provider')
continue
......
......@@ -59,7 +59,7 @@ class ShazbatCache(TVCache):
rss_url = self.provider.urls['base_url'] + '/rss/recent?passkey=' + self.provider.passkey + '&fname=true'
sickrage.app.log.debug("Cache update URL: %s" % rss_url)
return self.getRSSFeed(rss_url)
return self.get_rss_feed(rss_url)
def _check_auth(self, data):
return self.provider._check_auth_from_data(data)
......@@ -18,9 +18,11 @@
from __future__ import unicode_literals
import re
import sickrage
from sickrage.core.caches.tv_cache import TVCache
from sickrage.core.helpers import try_int, convert_size, bs4_parser
from sickrage.core.helpers import try_int, show_names, sanitizeSceneName
from sickrage.providers import TorrentProvider
......@@ -32,6 +34,7 @@ class ZooqleProvider(TorrentProvider):
# URLs
self.urls.update({
'search': '{base_url}/search'.format(**self.urls),
'api': '{base_url}/api/media/%s'.format(**self.urls),
})
# Proper Strings
......@@ -46,6 +49,55 @@ class ZooqleProvider(TorrentProvider):
# Cache
self.cache = TVCache(self, min_time=15)
def _get_season_search_strings(self, episode):
search_string = {'Season': []}
for show_name in set(show_names.allPossibleShowNames(episode.show)):
for sep in ' ', ' - ':
season_string = show_name + sep + 'Series '
if episode.show.air_by_date or episode.show.sports:
season_string += str(episode.airdate).split('-')[0]
elif episode.show.anime:
season_string += '%d' % episode.scene_absolute_number
else:
season_string += '%d' % int(episode.scene_season)
search_string['Season'].append(re.sub(r'\s+', ' ', season_string.replace('.', ' ').strip()))
return [search_string]
def _get_episode_search_strings(self, episode, add_string=''):
search_string = {'Episode': []}
if not episode:
return []
for show_name in set(show_names.allPossibleShowNames(episode.show)):
for sep in ' ', ' - ':
ep_string = sanitizeSceneName(show_name) + sep
if episode.show.air_by_date:
ep_string += str(episode.airdate)
elif episode.show.sports:
ep_string += str(episode.airdate) + '|' + episode.airdate.strftime('%b')
elif episode.show.anime:
ep_string += '%i' % int(episode.scene_absolute_number)
else:
ep_string += sickrage.app.naming_ep_type[4] % {'seasonnumber': episode.scene_season,
'episodenumber': episode.scene_episode}
if add_string:
ep_string += ' %s' % add_string
search_string['Episode'].append(re.sub(r'\s+', ' ', ep_string.replace('.', ' ').strip()))
return [search_string]
def _get_torrent_info(self, torrent_hash):
try:
return self.session.get(self.urls['api'] % torrent_hash).json()
except Exception:
return {}
def search(self, search_strings, age=0, ep_obj=None, **kwargs):
"""
Search a provider and parse the results.
......@@ -74,11 +126,14 @@ class ZooqleProvider(TorrentProvider):
sickrage.app.log.debug('Search string: {}'.format(search_string))
search_params = {'q': '{} category:TV'.format(search_string)}
try:
data = self.session.get(self.urls['search'], params=search_params).text
results += self.parse(data, mode)
except Exception:
search_params['fmt'] = 'rss'
data = self.cache.get_rss_feed(self.urls['search'], params=search_params)
if not data :
sickrage.app.log.debug('No data returned from provider')
continue
results += self.parse(data, mode)
return results
......@@ -93,44 +148,28 @@ class ZooqleProvider(TorrentProvider):
"""
results = []
with bs4_parser(data) as html:
torrent_table = html.find(class_='table-torrents')
torrent_rows = torrent_table('tr') if torrent_table else []
# Continue only if at least one release is found
if len(torrent_rows) < 2:
sickrage.app.log.debug('Data returned from provider does not contain any torrents')
return results
# Skip column headers
for row in torrent_rows[1:]:
cells = row('td')
try:
title = cells[1].find('a').get_text()
download_url = cells[2].find('a', title='Magnet link')['href']
if not all([title, download_url]):
continue
seeders = 1
leechers = 0
if len(cells) > 5:
peers = cells[5].find('div')
if peers and peers.get('title'):
peers = peers['title'].replace(',', '').split(' | ', 1)
seeders = try_int(peers[0][9:])
leechers = try_int(peers[1][10:])
torrent_size = cells[3].get_text().replace(',', '')
size = convert_size(torrent_size, -1)
results += [
{'title': title, 'link': download_url, 'size': size, 'seeders': seeders, 'leechers': leechers}
]
if mode != 'RSS':
sickrage.app.log.debug('Found result: {}'.format(title))
except Exception:
sickrage.app.log.error("Failed parsing provider")
if not data.get('entries'):
sickrage.app.log.debug('Data returned from provider does not contain any torrents')
return results
for item in data['entries']:
try:
title = item['title']
download_url = item['torrent_magneturi']
if not all([title, download_url]):
continue
seeders = try_int(item['torrent_seeds'])
leechers = try_int(item['torrent_peers'])
size = try_int(item['torrent_contentlength'], -1)
results += [
{'title': title, 'link': download_url, 'size': size, 'seeders': seeders, 'leechers': leechers}
]
if mode != 'RSS':
sickrage.app.log.debug('Found result: {}'.format(title))
except Exception:
sickrage.app.log.error("Failed parsing provider")
return results
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment