From bda4f24abbf0f432cf21408bae06a4f63fee9968 Mon Sep 17 00:00:00 2001 From: Michel Roux Date: Sat, 24 Dec 2022 13:49:15 +0000 Subject: [PATCH] Fix encoding --- commands/pygg.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/commands/pygg.py b/commands/pygg.py index e3844c9..00148a0 100755 --- a/commands/pygg.py +++ b/commands/pygg.py @@ -37,11 +37,12 @@ class FlareRequests(requests.Session): raise requests.RequestException(response) url += "&" if len(url.split("?")) > 1 else "?" + url = f"{url}{urllib.parse.urlencode(params)}" post_data = { "cmd": f"request.{method.lower()}", "session": FLARESESSION, - "url": f"{url}{urllib.parse.urlencode(params)}", + "url": url, } if data: @@ -56,12 +57,22 @@ class FlareRequests(requests.Session): solution = response.json() if "solution" in solution: + if "content-type" in solution["solution"]["headers"]: + content_type = solution["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.raw = io.BytesIO(solution["solution"]["response"].encode()) resolved.status_code = solution["solution"]["status"] resolved.headers = solution["solution"]["headers"] + resolved.raw = io.BytesIO(solution["solution"]["response"].encode()) resolved.url = url + resolved.encoding = encoding or None resolved.reason = solution["status"] resolved.cookies = solution["solution"]["cookies"] @@ -128,7 +139,10 @@ def search_ygg(query, multi, full): ygg_params["option_langue:multiple[]"] = "4" req = session.get(f"{YGGTORRENT_BASE_URL}/engine/search", params=ygg_params) - html = bs4.BeautifulSoup(req.text, "html.parser") + html = bs4.BeautifulSoup( + req.text, + "html.parser", + ) trs = html.select("table.table tr") if len(trs) > 1: