diff --git a/viu_media/core/utils/graphql.py b/viu_media/core/utils/graphql.py index 752ba4f..a1d8781 100644 --- a/viu_media/core/utils/graphql.py +++ b/viu_media/core/utils/graphql.py @@ -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 diff --git a/viu_media/libs/provider/anime/allanime/constants.py b/viu_media/libs/provider/anime/allanime/constants.py index 15e3634..cbe3e4e 100644 --- a/viu_media/libs/provider/anime/allanime/constants.py +++ b/viu_media/libs/provider/anime/allanime/constants.py @@ -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" diff --git a/viu_media/libs/provider/anime/allanime/provider.py b/viu_media/libs/provider/anime/allanime/provider.py index e7507aa..d4bf579 100644 --- a/viu_media/libs/provider/anime/allanime/provider.py +++ b/viu_media/libs/provider/anime/allanime/provider.py @@ -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"]: