Merge pull request #49 from JuanjoSalvador/dev

Fixed error parsing Sukebei and added "type" attr.
This commit is contained in:
Juanjo Salvador
2019-10-04 21:33:39 +02:00
committed by GitHub

View File

@@ -89,6 +89,14 @@ def parse_nyaa(table_rows, limit):
if td.text.rstrip(): if td.text.rstrip():
block.append(td.text.rstrip()) block.append(td.text.rstrip())
if row.has_attr('class'):
if row['class'][0] == 'danger':
block.append("remake")
elif row['class'][0] == 'success':
block.append("trusted")
else:
block.append("default")
try: try:
torrent = { torrent = {
'id': block[1].replace("/view/", ""), 'id': block[1].replace("/view/", ""),
@@ -102,6 +110,7 @@ def parse_nyaa(table_rows, limit):
'seeders': block[8], 'seeders': block[8],
'leechers': block[9], 'leechers': block[9],
'completed_downloads': block[10], 'completed_downloads': block[10],
'type': block[11],
} }
torrents.append(torrent) torrents.append(torrent)
@@ -143,43 +152,45 @@ def parse_single(content):
return torrent return torrent
# def parse_sukebei(table_rows, limit): def parse_sukebei(table_rows, limit):
# if limit == 0: if limit == 0:
# limit = len(table_rows) limit = len(table_rows)
# torrents = [] torrents = []
# for row in table_rows[:limit]: for row in table_rows[:limit]:
# block = [] block = []
# for td in row.find_all('td'): for td in row.find_all('td'):
# for link in td.find_all('a'): for link in td.find_all('a'):
# if link.get('href')[-9:] != '#comments': if link.get('href')[-9:] != '#comments':
# block.append(link.get('href')) block.append(link.get('href'))
# block.append(link.text.rstrip()) block.append(link.text.rstrip())
# if td.text.rstrip(): if td.text.rstrip():
# block.append(td.text.rstrip()) block.append(td.text.rstrip())
# try: try:
# torrent = { torrent = {
# 'id': block[1].replace("/view/", ""), 'id': block[1].replace("/view/", ""),
# 'category': sukebei_categories(block[0]), 'category': sukebei_categories(block[0]),
# 'url': "http://sukebei.nyaa.si{}".format(block[1]), 'url': "http://sukebei.nyaa.si{}".format(block[1]),
# 'name': block[2], 'name': block[2],
# 'download_url': "http://sukebei.nyaa.si{}".format( 'download_url': "http://sukebei.nyaa.si{}".format(
# block[4]), block[4]),
# 'magnet': block[5], 'magnet': block[5],
# 'size': block[6], 'size': block[6],
# 'date': block[7], 'date': block[7],
# 'seeders': block[8], 'seeders': block[8],
# 'leechers': block[9], 'leechers': block[9],
# 'completed_downloads': block[10], 'completed_downloads': block[10],
# } }
except IndexError as ie:
pass
# torrents.append(torrent) torrents.append(torrent)
# return torrents return torrents
def sukebei_categories(b): def sukebei_categories(b):
c = b.replace('/?c=', '') c = b.replace('/?c=', '')