Use charset-normalizer to detect from FlareRequests
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Michel Roux 2023-01-20 16:41:23 +01:00
parent 5c05aff14a
commit d7556f84b4
2 changed files with 6 additions and 11 deletions

View File

@ -6,7 +6,7 @@ RUN apt-get update && \
openssh-client transmission-cli python3-pip \ openssh-client transmission-cli python3-pip \
python3-requests python3-bs4 && \ python3-requests python3-bs4 && \
rm -rf /var/lib/apt/lists/* 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://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 && \ 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 update-alternatives --set editor /usr/bin/vim.basic

View File

@ -7,6 +7,7 @@ import re
import urllib import urllib
import bs4 import bs4
import charset_normalizer
import requests import requests
@ -54,22 +55,16 @@ class FlareRequests(requests.Session):
content = response.json() content = response.json()
if "solution" in content: if "solution" in content:
encoding = None
solution = content["solution"] solution = content["solution"]
if "content-type" in solution["headers"]: raw = solution["response"].encode()
content_type = solution["headers"]["content-type"].split(";") encoding = charset_normalizer.detect(raw)
if len(content_type) > 1:
charset = content_type[1].split("=")
if len(charset) > 1:
encoding = charset[1]
resolved = requests.Response() resolved = requests.Response()
resolved.status_code = solution["status"] resolved.status_code = solution["status"]
resolved.headers = solution["headers"] resolved.headers = solution["headers"]
resolved.raw = io.BytesIO(solution["response"].encode()) resolved.raw = io.BytesIO(raw)
resolved.url = url resolved.url = url
resolved.encoding = encoding resolved.encoding = encoding["encoding"]
resolved.reason = content["status"] resolved.reason = content["status"]
resolved.cookies = solution["cookies"] resolved.cookies = solution["cookies"]