Use charset-normalizer to detect from FlareRequests
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
5c05aff14a
commit
d7556f84b4
@ -6,7 +6,7 @@ RUN apt-get update && \
|
||||
openssh-client transmission-cli python3-pip \
|
||||
python3-requests python3-bs4 && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
RUN pip3 install yt-dlp && \
|
||||
RUN pip3 install yt-dlp charset-normalizer && \
|
||||
curl -sSL https://raw.githubusercontent.com/tremc/tremc/master/tremc -o /usr/local/bin/tremc && \
|
||||
curl -sSL https://github.com/drone/drone-cli/releases/latest/download/drone_linux_amd64.tar.gz | tar xzC /usr/local/bin && \
|
||||
update-alternatives --set editor /usr/bin/vim.basic
|
||||
|
@ -7,6 +7,7 @@ import re
|
||||
import urllib
|
||||
|
||||
import bs4
|
||||
import charset_normalizer
|
||||
import requests
|
||||
|
||||
|
||||
@ -54,22 +55,16 @@ class FlareRequests(requests.Session):
|
||||
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]
|
||||
raw = solution["response"].encode()
|
||||
encoding = charset_normalizer.detect(raw)
|
||||
|
||||
resolved = requests.Response()
|
||||
|
||||
resolved.status_code = solution["status"]
|
||||
resolved.headers = solution["headers"]
|
||||
resolved.raw = io.BytesIO(solution["response"].encode())
|
||||
resolved.raw = io.BytesIO(raw)
|
||||
resolved.url = url
|
||||
resolved.encoding = encoding
|
||||
resolved.encoding = encoding["encoding"]
|
||||
resolved.reason = content["status"]
|
||||
resolved.cookies = solution["cookies"]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user