From f05fd79dd9c4065e88c2c164d329b7761a908db2 Mon Sep 17 00:00:00 2001 From: Michel Roux Date: Fri, 27 Dec 2024 21:34:22 +0100 Subject: [PATCH] fix: :bug: fix bad nb_files --- commands/2hdp.py | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/commands/2hdp.py b/commands/2hdp.py index ac724fa..6a6f745 100755 --- a/commands/2hdp.py +++ b/commands/2hdp.py @@ -7,7 +7,7 @@ from time import sleep from xml.etree import ElementTree from bs4 import BeautifulSoup -from requests import get +from requests import JSONDecodeError, get parser = ArgumentParser() parser.add_argument( @@ -31,25 +31,28 @@ args = parser.parse_args() def nb_files(id: int): - response = get( - f"https://www.ygg.re/engine/get_files?torrent={id}", - headers={"Cookie": args.cookie, "User-Agent": args.user_agent}, - ) - sleep(1) + try: + response = get( + f"https://www.ygg.re/engine/get_files?torrent={id}", + headers={"Cookie": args.cookie, "User-Agent": args.user_agent}, + ) + sleep(1) - json = response.json() - soup = BeautifulSoup(json["html"], "html.parser") - rows = soup.find_all("tr") - is_mkv = False + json = response.json() + soup = BeautifulSoup(json["html"], "html.parser") + rows = soup.find_all("tr") + is_mkv = False - for row in rows: - columns = row.find_all("td") + for row in rows: + columns = row.find_all("td") - if columns[1].text.strip()[-3:] == "mkv": - is_mkv = True - break + if columns[1].text.strip()[-3:] == "mkv": + is_mkv = True + break - return is_mkv and len(rows) == 1 + return is_mkv and len(rows) == 1 + except JSONDecodeError: + return False def parse_size(size): @@ -122,7 +125,7 @@ for feed in args.feed: ): column = columns break - + if column: break