Private GIT

Skip to content
Snippets Groups Projects
Commit c1663a11 authored by miigotu's avatar miigotu
Browse files

Clean and simplify scenetime provider

parent b598bd6b
No related branches found
No related tags found
No related merge requests found
......@@ -26,6 +26,8 @@ from sickbeard import tvcache
from sickbeard.bs4_parser import BS4Parser
from sickrage.providers.torrent.TorrentProvider import TorrentProvider
from sickrage.helper.common import try_int
class SceneTimeProvider(TorrentProvider):
......@@ -89,10 +91,11 @@ class SceneTimeProvider(TorrentProvider):
if not data:
continue
try:
with BS4Parser(data, 'html5lib') as html:
torrent_table = html.select("#torrenttable table")
torrent_rows = torrent_table[0].select("tr") if torrent_table else []
torrent_table = html.find('div', id="torrenttable")
torrent_rows = []
if torrent_table:
torrent_rows = torrent_table.select("tr")
# Continue only if one Release is found
if len(torrent_rows) < 2:
......@@ -102,26 +105,23 @@ class SceneTimeProvider(TorrentProvider):
# Scenetime apparently uses different number of cells in #torrenttable based
# on who you are. This works around that by extracting labels from the first
# <tr> and using their index to find the correct download/seeders/leechers td.
labels = [label.get_text() for label in torrent_rows[0].find_all('td')]
labels = [label.get_text(strip=True) for label in torrent_rows[0].find_all('td')]
for result in torrent_rows[1:]:
try:
cells = result.find_all('td')
link = cells[labels.index('Name')].find('a')
torrent_id = link['href'].replace('details.php?id=', '').split("&")[0]
full_id = link['href'].replace('details.php?id=', '')
torrent_id = full_id.split("&")[0]
try:
title = link.contents[0].get_text() if link.contents[0].get_text() else None
filename = "%s.torrent" % title.replace(" ", ".") if title else None
download_url = self.urls['download'] % (torrent_id, filename) if torrent_id and filename else None
title = link.get_text(strip=True)
download_url = self.urls['download'] % (torrent_id, "%s.torrent" % title.replace(" ", "."))
seeders = int(cells[labels.index('Seeders')].get_text()) if cells[labels.index('Seeders')].get_text() else 1
leechers = int(cells[labels.index('Leechers')].get_text()) if cells[labels.index('Leechers')].get_text() else 0
size = self._convertSize(cells[labels.index('Size')].get_text()) if cells[labels.index('Size')].get_text() else -1
seeders = try_int(cells[labels.index('Seeders')].get_text(strip=True))
leechers = try_int(cells[labels.index('Leechers')].get_text(strip=True))
size = self._convertSize(cells[labels.index('Size')].get_text(strip=True))
except (AttributeError, TypeError):
except (AttributeError, TypeError, KeyError, ValueError):
continue
if not all([title, download_url]):
......@@ -139,9 +139,6 @@ class SceneTimeProvider(TorrentProvider):
items[mode].append(item)
except Exception as e:
logger.log(u"Failed parsing provider. Traceback: %s" % traceback.format_exc(), logger.ERROR)
# For each search mode sort all the items by seeders if available
items[mode].sort(key=lambda tup: tup[3], reverse=True)
......@@ -152,10 +149,10 @@ class SceneTimeProvider(TorrentProvider):
def seed_ratio(self):
return self.ratio
def _convertSize(sizeString):
size = sizeString[:-2].strip()
modifier = sizeString[-2:].upper()
@staticmethod
def _convertSize(size):
modifier = size[-2:].upper()
size = size[:-2].strip()
try:
size = float(size)
if modifier in 'KB':
......@@ -166,8 +163,11 @@ class SceneTimeProvider(TorrentProvider):
size *= 1024 ** 3
elif modifier in 'TB':
size *= 1024 ** 4
else:
raise
except Exception:
size = -1
return long(size)
class SceneTimeCache(tvcache.TVCache):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment