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 #!/usr/bin/env python3
import argparse import argparse
import io
import json import json
import os import os
import re import re
@ -10,55 +9,8 @@ import bs4
import requests import requests
YGGTORRENT_BASE_URL = "https://www6.yggtorrent.lol" YGG_DOMAIN = "www6.yggtorrent.lol"
CLOUDPROXY_ENDPOINT = os.getenv("CLOUDPROXY_ENDPOINT") YGG_IP = os.getenv("YGG_IP")
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
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
@ -79,15 +31,14 @@ def parse_size(size):
return int(float(number) * units[unit]) return int(float(number) * units[unit])
session = FlareRequests()
def check_files(id): def check_files(id):
req = session.get(f"{YGGTORRENT_BASE_URL}/engine/get_files", params={"torrent": id}) req = requests.get(
res = bs4.BeautifulSoup(req.text, "html.parser") f"http://{YGG_IP}/engine/get_files",
pre = res.select_one("pre") params={"torrent": id},
jhtml = json.loads(pre.get_text()) headers={"Host": YGG_DOMAIN},
html = bs4.BeautifulSoup(jhtml["html"], "html.parser") )
res = json.loads(req.text)
html = bs4.BeautifulSoup(res["html"], "html.parser")
trs = html.select("tr") trs = html.select("tr")
return len(trs) == 1 and "mkv" in trs[0].get_text().lower() return len(trs) == 1 and "mkv" in trs[0].get_text().lower()
@ -111,7 +62,11 @@ def search_ygg(query, multi, full):
if multi: if multi:
ygg_params["option_langue:multiple[]"] = "4" 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( html = bs4.BeautifulSoup(
req.text, req.text,
"html.parser", "html.parser",