fix: 🐛 fix bad nb_files
This commit is contained in:
parent
94109da87d
commit
f05fd79dd9
@ -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):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user