feat: use curl_cffi to enable browser impersonation

This commit is contained in:
Benex254
2024-08-05 09:47:02 +03:00
parent 26d483c047
commit 8754fec2d1
6 changed files with 38 additions and 5 deletions

View File

@@ -32,7 +32,7 @@ def write_search_results(
): ):
import textwrap import textwrap
import requests from curl_cffi import requests
for anime in search_results: for anime in search_results:
if not os.path.exists(SEARCH_RESULTS_CACHE): if not os.path.exists(SEARCH_RESULTS_CACHE):

View File

@@ -2,7 +2,7 @@
This is the core module availing all the abstractions of the anilist api This is the core module availing all the abstractions of the anilist api
""" """
import requests from curl_cffi import requests
from .anilist_data_schema import AnilistDataSchema from .anilist_data_schema import AnilistDataSchema
from .queries_graphql import ( from .queries_graphql import (

View File

@@ -2,7 +2,7 @@ import json
import logging import logging
from typing import Generator from typing import Generator
import requests from curl_cffi import requests
from requests.exceptions import Timeout from requests.exceptions import Timeout
from rich import print from rich import print
from rich.progress import Progress from rich.progress import Progress
@@ -41,6 +41,7 @@ class AllAnimeAPI:
}, },
headers={"Referer": ALLANIME_REFERER, "User-Agent": USER_AGENT}, headers={"Referer": ALLANIME_REFERER, "User-Agent": USER_AGENT},
timeout=10, timeout=10,
impersonate="chrome",
) )
return response.json()["data"] return response.json()["data"]
except Timeout as e: except Timeout as e:
@@ -152,6 +153,7 @@ class AllAnimeAPI:
"User-Agent": USER_AGENT, "User-Agent": USER_AGENT,
}, },
timeout=10, timeout=10,
impersonate="chrome",
) )
if resp.status_code == 200: if resp.status_code == 200:
match embed["sourceName"]: match embed["sourceName"]:

View File

@@ -1,5 +1,7 @@
from yt_dlp.utils.networking import random_user_agent
ALLANIME_BASE = "allanime.day" ALLANIME_BASE = "allanime.day"
ALLANIME_REFERER = "https://allanime.to/" ALLANIME_REFERER = "https://allanime.to/"
ALLANIME_API_ENDPOINT = "https://api.{}/api/".format(ALLANIME_BASE) ALLANIME_API_ENDPOINT = "https://api.{}/api/".format(ALLANIME_BASE)
USER_AGENT = "Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0" USER_AGENT = random_user_agent()
SERVERS_AVAILABLE = ["sharepoint", "dropbox", "gogoanime", "weTransfer"] SERVERS_AVAILABLE = ["sharepoint", "dropbox", "gogoanime", "weTransfer"]

30
poetry.lock generated
View File

@@ -468,6 +468,34 @@ files = [
{file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"}, {file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"},
] ]
[[package]]
name = "curl-cffi"
version = "0.7.1"
description = "libcurl ffi bindings for Python, with impersonation support."
optional = false
python-versions = ">=3.8"
files = [
{file = "curl_cffi-0.7.1-cp38-abi3-macosx_10_9_x86_64.whl", hash = "sha256:54edae42b25f30048fd6c2de06ed9df37bbe6ffdce14cc8a27c79f8c7d47977a"},
{file = "curl_cffi-0.7.1-cp38-abi3-macosx_11_0_arm64.whl", hash = "sha256:5c347e221ddbbde2275aa7cde00933402638c2062a3984104f66b1bb20528545"},
{file = "curl_cffi-0.7.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:99a5cc1d9ca59692cc5c175da0b397104283a0fea7515045fd22a7296296d82b"},
{file = "curl_cffi-0.7.1-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:0719fec4b5e1c300bf58411b1cea26cb91c44492fcf5a14ef684fe085f4d8b6e"},
{file = "curl_cffi-0.7.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:1e53ab76259b575017d3260854456ba6a3fbe31cee9b44edd275d4ea9f0f20e1"},
{file = "curl_cffi-0.7.1-cp38-abi3-musllinux_1_1_aarch64.whl", hash = "sha256:39d04ee1fc5f668ce53234051153031b3a3714300b772379e276565ad7cd244c"},
{file = "curl_cffi-0.7.1-cp38-abi3-musllinux_1_1_x86_64.whl", hash = "sha256:e60f0dca3a55298898c62c21f0d8461e61aab96d033a7e9cead6160462728f7f"},
{file = "curl_cffi-0.7.1-cp38-abi3-win32.whl", hash = "sha256:318a9a21f69e720ca904a0edc80bcbb7bbb75a4bab7b31341a202f07d5378c8e"},
{file = "curl_cffi-0.7.1-cp38-abi3-win_amd64.whl", hash = "sha256:0eb5b08f562749639529e6990ff1b10a40e53ed45115e15f00b239230eabb927"},
{file = "curl_cffi-0.7.1.tar.gz", hash = "sha256:8a64b12432146a3f178c4792c91188c18f50cc4b76e908ffc3206442c4610894"},
]
[package.dependencies]
certifi = ">=2024.2.2"
cffi = ">=1.12.0"
[package.extras]
build = ["cibuildwheel", "wheel"]
dev = ["charset-normalizer (>=3.3.2,<4.0)", "coverage (>=6.4.1,<7.0)", "cryptography (>=42.0.5,<43.0)", "httpx (==0.23.1)", "mypy (>=1.9.0,<2.0)", "pytest (>=8.1.1,<9.0)", "pytest-asyncio (>=0.23.6,<1.0)", "pytest-trio (>=0.8.0,<1.0)", "ruff (>=0.3.5,<1.0)", "trio (>=0.25.0,<1.0)", "trustme (>=1.1.0,<2.0)", "uvicorn (>=0.29.0,<1.0)", "websockets (>=12.0,<13.0)"]
test = ["charset-normalizer (>=3.3.2,<4.0)", "cryptography (>=42.0.5,<43.0)", "fastapi (==0.110.0)", "httpx (==0.23.1)", "proxy.py (>=2.4.3,<3.0)", "pytest (>=8.1.1,<9.0)", "pytest-asyncio (>=0.23.6,<1.0)", "pytest-trio (>=0.8.0,<1.0)", "python-multipart (>=0.0.9,<1.0)", "trio (>=0.25.0,<1.0)", "trustme (>=1.1.0,<2.0)", "uvicorn (>=0.29.0,<1.0)", "websockets (>=12.0,<13.0)"]
[[package]] [[package]]
name = "distlib" name = "distlib"
version = "0.3.8" version = "0.3.8"
@@ -1640,4 +1668,4 @@ test = ["pytest (>=8.1,<9.0)"]
[metadata] [metadata]
lock-version = "2.0" lock-version = "2.0"
python-versions = "^3.10" python-versions = "^3.10"
content-hash = "8067cb57131dda364172fc1433b46936b3cf19af227ee2505facd7dc2a2f32b2" content-hash = "02aedc9c5ab19b6c56ab24281e7b144826831baf787eb1739b37a9e3a73ff78b"

View File

@@ -16,6 +16,7 @@ platformdirs = "^4.2.2"
art = "^6.2" art = "^6.2"
python-dotenv = "^1.0.1" python-dotenv = "^1.0.1"
thefuzz = "^0.22.1" thefuzz = "^0.22.1"
curl-cffi = "^0.7.1"
[tool.poetry.group.dev] [tool.poetry.group.dev]
optional = true optional = true
[tool.poetry.group.dev.dependencies] [tool.poetry.group.dev.dependencies]