Private GIT

Skip to content
Snippets Groups Projects
Commit 6d75a489 authored by Nick Sologoub's avatar Nick Sologoub
Browse files

[*] Fixed no results detection for Torrentbytes

[*] Added torrent size parsing for Torrentbytes
parent 25b3bcf9
Branches
Tags
No related merge requests found
# Author: Idan Gutman # Author: Idan Gutman
# URL: http://code.google.com/p/sickbeard/ # URL: http://code.google.com/p/sickbeard/
# #
# This file is part of SickRage. # This file is part of SickRage.
...@@ -98,17 +98,18 @@ class TorrentBytesProvider(generic.TorrentProvider): ...@@ -98,17 +98,18 @@ class TorrentBytesProvider(generic.TorrentProvider):
try: try:
with BS4Parser(data, features=["html5lib", "permissive"]) as html: with BS4Parser(data, features=["html5lib", "permissive"]) as html:
torrent_table = html.find('table', attrs={'border': '1'})
torrent_rows = torrent_table.find_all('tr') if torrent_table else []
#Continue only if one Release is found #Continue only if one Release is found
if len(torrent_rows) < 2: empty = html.find('Nothing found!')
if empty:
logger.log(u"Data returned from provider does not contain any torrents", logger.DEBUG) logger.log(u"Data returned from provider does not contain any torrents", logger.DEBUG)
continue continue
torrent_table = html.find('table', attrs={'border': '1'})
torrent_rows = torrent_table.find_all('tr') if torrent_table else []
for result in torrent_rows[1:]: for result in torrent_rows[1:]:
cells = result.find_all('td') cells = result.find_all('td')
size = None
link = cells[1].find('a', attrs={'class': 'index'}) link = cells[1].find('a', attrs={'class': 'index'})
full_id = link['href'].replace('details.php?id=', '') full_id = link['href'].replace('details.php?id=', '')
...@@ -122,8 +123,14 @@ class TorrentBytesProvider(generic.TorrentProvider): ...@@ -122,8 +123,14 @@ class TorrentBytesProvider(generic.TorrentProvider):
download_url = self.urls['download'] % (torrent_id, link.contents[0]) download_url = self.urls['download'] % (torrent_id, link.contents[0])
seeders = int(cells[8].find('span').contents[0]) seeders = int(cells[8].find('span').contents[0])
leechers = int(cells[9].find('span').contents[0]) leechers = int(cells[9].find('span').contents[0])
#FIXME
# Need size for failed downloads handling
if size is None:
if re.match(r'[0-9]+,?\.?[0-9]*[KkMmGg]+[Bb]+', cells[6].text):
size = self._convertSize(cells[6].text)
if not size:
size = -1 size = -1
except (AttributeError, TypeError): except (AttributeError, TypeError):
continue continue
...@@ -155,6 +162,20 @@ class TorrentBytesProvider(generic.TorrentProvider): ...@@ -155,6 +162,20 @@ class TorrentBytesProvider(generic.TorrentProvider):
def seedRatio(self): def seedRatio(self):
return self.ratio return self.ratio
def _convertSize(self, sizeString):
size = sizeString[:-2]
modifier = sizeString[-2:]
size = float(size)
if modifier in 'KB':
size = size * 1024
elif modifier in 'MB':
size = size * 1024**2
elif modifier in 'GB':
size = size * 1024**3
elif modifier in 'TB':
size = size * 1024**4
return int(size)
class TorrentBytesCache(tvcache.TVCache): class TorrentBytesCache(tvcache.TVCache):
def __init__(self, provider_obj): def __init__(self, provider_obj):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment