fix: 🐛 fix bad nb_files
All checks were successful
dl / lint (push) Successful in 1m34s
dl / docker (push) Successful in 4m20s

This commit is contained in:
Michel Roux 2024-12-27 21:34:22 +01:00
parent 94109da87d
commit f05fd79dd9

View File

@ -7,7 +7,7 @@ from time import sleep
from xml.etree import ElementTree from xml.etree import ElementTree
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
from requests import get from requests import JSONDecodeError, get
parser = ArgumentParser() parser = ArgumentParser()
parser.add_argument( parser.add_argument(
@ -31,25 +31,28 @@ args = parser.parse_args()
def nb_files(id: int): def nb_files(id: int):
response = get( try:
f"https://www.ygg.re/engine/get_files?torrent={id}", response = get(
headers={"Cookie": args.cookie, "User-Agent": args.user_agent}, f"https://www.ygg.re/engine/get_files?torrent={id}",
) headers={"Cookie": args.cookie, "User-Agent": args.user_agent},
sleep(1) )
sleep(1)
json = response.json() json = response.json()
soup = BeautifulSoup(json["html"], "html.parser") soup = BeautifulSoup(json["html"], "html.parser")
rows = soup.find_all("tr") rows = soup.find_all("tr")
is_mkv = False is_mkv = False
for row in rows: for row in rows:
columns = row.find_all("td") columns = row.find_all("td")
if columns[1].text.strip()[-3:] == "mkv": if columns[1].text.strip()[-3:] == "mkv":
is_mkv = True is_mkv = True
break break
return is_mkv and len(rows) == 1 return is_mkv and len(rows) == 1
except JSONDecodeError:
return False
def parse_size(size): def parse_size(size):
@ -122,7 +125,7 @@ for feed in args.feed:
): ):
column = columns column = columns
break break
if column: if column:
break break