Fix YGG (thx Az)
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Michel Roux 2023-01-05 22:55:43 +01:00
parent 954b019ef2
commit ed7448196f

View File

@ -1,6 +1,5 @@
#!/usr/bin/env python3
import argparse
import io
import json
import os
import re
@ -10,55 +9,8 @@ import bs4
import requests
YGGTORRENT_BASE_URL = "https://www6.yggtorrent.lol"
CLOUDPROXY_ENDPOINT = os.getenv("CLOUDPROXY_ENDPOINT")
class FlareRequests(requests.Session):
def request(self, method, url, params=None, data=None, **kwargs):
if not CLOUDPROXY_ENDPOINT:
return super().request(method, url, params, data, **kwargs)
if params:
url += "&" if len(url.split("?")) > 1 else "?"
url = f"{url}{urllib.parse.urlencode(params)}"
post_data = {
"cmd": f"request.{method.lower()}",
"url": url,
}
if data:
post_data["postData"] = urllib.parse.urlencode(data)
response = requests.post(
CLOUDPROXY_ENDPOINT,
json=post_data,
)
content = response.json()
if "solution" in content:
encoding = None
solution = content["solution"]
if "content-type" in solution["headers"]:
content_type = solution["headers"]["content-type"].split(";")
if len(content_type) > 1:
charset = content_type[1].split("=")
if len(charset) > 1:
encoding = charset[1]
resolved = requests.Response()
resolved.status_code = solution["status"]
resolved.headers = solution["headers"]
resolved.raw = io.BytesIO(solution["response"].encode())
resolved.url = url
resolved.encoding = encoding
resolved.reason = content["status"]
resolved.cookies = solution["cookies"]
return resolved
YGG_DOMAIN = "www6.yggtorrent.lol"
YGG_IP = os.getenv("YGG_IP")
parser = argparse.ArgumentParser()
@ -79,15 +31,14 @@ def parse_size(size):
return int(float(number) * units[unit])
session = FlareRequests()
def check_files(id):
req = session.get(f"{YGGTORRENT_BASE_URL}/engine/get_files", params={"torrent": id})
res = bs4.BeautifulSoup(req.text, "html.parser")
pre = res.select_one("pre")
jhtml = json.loads(pre.get_text())
html = bs4.BeautifulSoup(jhtml["html"], "html.parser")
req = requests.get(
f"http://{YGG_IP}/engine/get_files",
params={"torrent": id},
headers={"Host": YGG_DOMAIN},
)
res = json.loads(req.text)
html = bs4.BeautifulSoup(res["html"], "html.parser")
trs = html.select("tr")
return len(trs) == 1 and "mkv" in trs[0].get_text().lower()
@ -111,7 +62,11 @@ def search_ygg(query, multi, full):
if multi:
ygg_params["option_langue:multiple[]"] = "4"
req = session.get(f"{YGGTORRENT_BASE_URL}/engine/search", params=ygg_params)
req = requests.get(
f"http://{YGG_IP}/engine/search",
params=ygg_params,
headers={"Host": YGG_DOMAIN},
)
html = bs4.BeautifulSoup(
req.text,
"html.parser",