fix(allanime): move graphql headers to constants.py

This commit is contained in:
Type-Delta
2026-04-06 11:31:31 +07:00
parent a32221f639
commit 0b7b2694a3
3 changed files with 10 additions and 6 deletions

View File

@@ -40,14 +40,9 @@ def execute_graphql_query_with_get_request(
def execute_graphql(
url: str, httpx_client: Client, graphql_file: Path, variables: dict
url: str, httpx_client: Client, graphql_file: Path, variables: dict, headers: dict | None = None
) -> Response:
query = load_graphql_from_file(graphql_file)
json_body = {"query": query, "variables": variables}
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
"Content-Type": "application/json",
"Origin": "https://allanime.to",
}
response = httpx_client.post(url, json=json_body, headers=headers, timeout=TIMEOUT)
return response

View File

@@ -14,6 +14,11 @@ SERVERS_AVAILABLE = [
API_BASE_URL = "allanime.day"
API_GRAPHQL_REFERER = "https://allanime.to/"
API_GRAPHQL_ENDPOINT = f"https://api.{API_BASE_URL}/api/"
API_GRAPHQL_HEADERS= {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
"Content-Type": "application/json",
"Origin": f"{API_GRAPHQL_REFERER}",
}
# search constants
DEFAULT_COUNTRY_OF_ORIGIN = "all"

View File

@@ -7,6 +7,7 @@ from ..utils.debug import debug_provider
from .constants import (
ANIME_GQL,
API_GRAPHQL_ENDPOINT,
API_GRAPHQL_HEADERS,
API_GRAPHQL_REFERER,
EPISODE_GQL,
SEARCH_GQL,
@@ -41,6 +42,7 @@ class AllAnime(BaseAnimeProvider):
"translationtype": params.translation_type,
"countryorigin": params.country_of_origin,
},
headers=API_GRAPHQL_HEADERS
)
return map_to_search_results(response)
@@ -51,6 +53,7 @@ class AllAnime(BaseAnimeProvider):
self.client,
ANIME_GQL,
variables={"showId": params.id},
headers=API_GRAPHQL_HEADERS
)
return map_to_anime_result(response)
@@ -67,6 +70,7 @@ class AllAnime(BaseAnimeProvider):
"translationType": params.translation_type,
"episodeString": params.episode,
},
headers=API_GRAPHQL_HEADERS
)
episode: AllAnimeEpisode = episode_response.json()["data"]["episode"]
for source in episode["sourceUrls"]: