diff --git a/Dockerfile b/Dockerfile index a400c79..e05652a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/commands/pygg.py b/commands/pygg.py index 5e56fb4..1af6a17 100755 --- a/commands/pygg.py +++ b/commands/pygg.py @@ -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"]