Private GIT

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

Merge pull request #2972 from ncksol/branch-fix_torrentbytes

Torrentbytes provider fixes
parents 25b3bcf9 6d75a489
No related branches found
No related tags found
No related merge requests found
# Author: Idan Gutman
# Author: Idan Gutman
# URL: http://code.google.com/p/sickbeard/
#
# This file is part of SickRage.
......@@ -98,17 +98,18 @@ class TorrentBytesProvider(generic.TorrentProvider):
try:
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
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)
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:]:
cells = result.find_all('td')
size = None
link = cells[1].find('a', attrs={'class': 'index'})
full_id = link['href'].replace('details.php?id=', '')
......@@ -122,8 +123,14 @@ class TorrentBytesProvider(generic.TorrentProvider):
download_url = self.urls['download'] % (torrent_id, link.contents[0])
seeders = int(cells[8].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
except (AttributeError, TypeError):
continue
......@@ -155,6 +162,20 @@ class TorrentBytesProvider(generic.TorrentProvider):
def seedRatio(self):
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):
def __init__(self, provider_obj):
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment