chore: clean up codebase

This commit is contained in:
Benex254
2024-08-23 16:05:26 +03:00
parent 6346ea7343
commit 7743b0423e
26 changed files with 525 additions and 523 deletions

View File

@@ -12,7 +12,6 @@ from .libs.anime_provider import anime_sources
if TYPE_CHECKING:
from typing import Iterator
from .libs.anilist.types import AnilistBaseMediaDataSchema
from .libs.anime_provider.types import Anime, SearchResults, Server
logger = logging.getLogger(__name__)
@@ -51,7 +50,6 @@ class AnimeProvider:
self,
user_query,
translation_type,
anilist_obj: "AnilistBaseMediaDataSchema | None" = None,
nsfw=True,
unknown=True,
) -> "SearchResults | None":
@@ -73,14 +71,14 @@ class AnimeProvider:
user_query, translation_type, nsfw, unknown
)
except Exception as e:
logger.error(e)
logger.error(f"[ANIMEPROVIDER-ERROR]: {e}")
results = None
return results
def get_anime(
self,
anime_id: str,
anilist_obj: "AnilistBaseMediaDataSchema | None" = None,
) -> "Anime | None":
"""core abstraction over getting info of an anime from all providers
@@ -95,7 +93,8 @@ class AnimeProvider:
try:
results = anime_provider.get_anime(anime_id)
except Exception as e:
logger.error(e)
logger.error(f"[ANIMEPROVIDER-ERROR]: {e}")
results = None
return results
@@ -104,7 +103,6 @@ class AnimeProvider:
anime,
episode: str,
translation_type: str,
anilist_obj: "AnilistBaseMediaDataSchema|None" = None,
) -> "Iterator[Server] | None":
"""core abstractions for getting juicy streams from all providers
@@ -123,6 +121,7 @@ class AnimeProvider:
anime, episode, translation_type
)
except Exception as e:
logger.error(e)
logger.error(f"[ANIMEPROVIDER-ERROR]: {e}")
results = None
return results # pyright:ignore
return results

View File

@@ -31,8 +31,6 @@ class YtDLPDownloader:
self._thread.daemon = True
self._thread.start()
# Function to download the file
# TODO: untpack the title to its actual values episode_title and anime_title
def _download_file(
self,
url: str,

View File

@@ -42,5 +42,5 @@ def completed(config: "Config", dump_json):
from ...interfaces import anilist_interfaces
fastanime_runtime_state = FastAnimeRuntimeState()
fastanime_runtime_state.anilist_data = anime_list[1]
fastanime_runtime_state.current_anilist_data = anime_list[1]
anilist_interfaces.anilist_results_menu(config, fastanime_runtime_state)

View File

@@ -42,5 +42,5 @@ def dropped(config: "Config", dump_json):
from ...utils.tools import FastAnimeRuntimeState
fastanime_runtime_state = FastAnimeRuntimeState()
fastanime_runtime_state.anilist_data = anime_list[1]
fastanime_runtime_state.current_anilist_data = anime_list[1]
anilist_interfaces.anilist_results_menu(config, fastanime_runtime_state)

View File

@@ -26,7 +26,7 @@ def favourites(config, dump_json):
from ...utils.tools import FastAnimeRuntimeState
fastanime_runtime_state = FastAnimeRuntimeState()
fastanime_runtime_state.anilist_data = anime_data[1]
fastanime_runtime_state.current_anilist_data = anime_data[1]
anilist_results_menu(config, fastanime_runtime_state)
else:
from sys import exit

View File

@@ -42,5 +42,5 @@ def planning(config: "Config", dump_json):
from ...utils.tools import FastAnimeRuntimeState
fastanime_runtime_state = FastAnimeRuntimeState()
fastanime_runtime_state.anilist_data = anime_list[1]
fastanime_runtime_state.current_anilist_data = anime_list[1]
anilist_interfaces.anilist_results_menu(config, fastanime_runtime_state)

View File

@@ -25,7 +25,7 @@ def popular(config, dump_json):
from ...utils.tools import FastAnimeRuntimeState
fastanime_runtime_state = FastAnimeRuntimeState()
fastanime_runtime_state.anilist_data = anime_data[1]
fastanime_runtime_state.current_anilist_data = anime_data[1]
anilist_results_menu(config, fastanime_runtime_state)
else:
from sys import exit

View File

@@ -33,7 +33,7 @@ def random_anime(config, dump_json):
from ...utils.tools import FastAnimeRuntimeState
fastanime_runtime_state = FastAnimeRuntimeState()
fastanime_runtime_state.anilist_data = anime_data[1]
fastanime_runtime_state.current_anilist_data = anime_data[1]
anilist_results_menu(config, fastanime_runtime_state)
else:
exit(1)

View File

@@ -26,7 +26,7 @@ def recent(config, dump_json):
from ...utils.tools import FastAnimeRuntimeState
fastanime_runtime_state = FastAnimeRuntimeState()
fastanime_runtime_state.anilist_data = anime_data[1]
fastanime_runtime_state.current_anilist_data = anime_data[1]
anilist_results_menu(config, fastanime_runtime_state)
else:
from sys import exit

View File

@@ -42,5 +42,5 @@ def rewatching(config: "Config", dump_json):
from ...utils.tools import FastAnimeRuntimeState
fastanime_runtime_state = FastAnimeRuntimeState()
fastanime_runtime_state.anilist_data = anime_list[1]
fastanime_runtime_state.current_anilist_data = anime_list[1]
anilist_interfaces.anilist_results_menu(config, fastanime_runtime_state)

View File

@@ -548,7 +548,7 @@ def search(
from ...utils.tools import FastAnimeRuntimeState
fastanime_runtime_state = FastAnimeRuntimeState()
fastanime_runtime_state.anilist_data = search_results
fastanime_runtime_state.current_anilist_data = search_results
anilist_results_menu(config, fastanime_runtime_state)
else:
from sys import exit

View File

@@ -26,7 +26,7 @@ def trending(config, dump_json):
from ...utils.tools import FastAnimeRuntimeState
fastanime_runtime_state = FastAnimeRuntimeState()
fastanime_runtime_state.anilist_data = data
fastanime_runtime_state.current_anilist_data = data
anilist_results_menu(config, fastanime_runtime_state)
else:
from sys import exit

View File

@@ -25,7 +25,7 @@ def upcoming(config, dump_json):
from ...utils.tools import FastAnimeRuntimeState
fastanime_runtime_state = FastAnimeRuntimeState()
fastanime_runtime_state.anilist_data = data
fastanime_runtime_state.current_anilist_data = data
anilist_results_menu(config, fastanime_runtime_state)
else:
from sys import exit

View File

@@ -42,5 +42,5 @@ def watching(config: "Config", dump_json):
from ...utils.tools import FastAnimeRuntimeState
fastanime_runtime_state = FastAnimeRuntimeState()
fastanime_runtime_state.anilist_data = anime_list[1]
fastanime_runtime_state.current_anilist_data = anime_list[1]
anilist_interfaces.anilist_results_menu(config, fastanime_runtime_state)

View File

@@ -370,7 +370,7 @@ def provider_anime_episode_servers_menu(
anime_id_anilist: int = fastanime_runtime_state.selected_anime_id_anilist
provider_anime: "Anime" = fastanime_runtime_state.provider_anime
server_name = None
server_name = ""
# get streams for episode from provider
with Progress() as progress:
progress.add_task("Fetching Episode Streams...", total=None)
@@ -378,7 +378,6 @@ def provider_anime_episode_servers_menu(
provider_anime,
current_episode_number,
translation_type,
fastanime_runtime_state.selected_anime_anilist,
)
if not episode_streams_generator:
if not config.use_rofi:
@@ -582,7 +581,7 @@ def provider_anime_episode_servers_menu(
# this will try to update the episode to be the next episode if delta has reached a specific threshhold
# this update will only apply locally
# the remote(anilist) is only updated when its certain you are going to open the player
available_episodes: list = sorted(
available_episodes: list[str] = sorted(
fastanime_runtime_state.provider_available_episodes, key=float
)
if stop_time == "0" or total_time == "0":
@@ -786,7 +785,6 @@ def anime_provider_search_results_menu(
provider_search_results = anime_provider.search_for_anime(
selected_anime_title,
translation_type,
selected_anime_anilist,
)
if not provider_search_results:
print(
@@ -1279,7 +1277,9 @@ def anilist_results_menu(
config: [TODO:description]
fastanime_runtime_state: [TODO:description]
"""
search_results = fastanime_runtime_state.anilist_data["data"]["Page"]["media"]
search_results = fastanime_runtime_state.current_anilist_data["data"]["Page"][
"media"
]
anime_data = {}
for anime in search_results:
@@ -1558,7 +1558,7 @@ def fastanime_main_menu(
# anilist data is a (bool,data)
# the bool indicated success
if anilist_data[0]:
fastanime_runtime_state.anilist_data = anilist_data[1]
fastanime_runtime_state.current_anilist_data = anilist_data[1]
anilist_results_menu(config, fastanime_runtime_state)
else:

View File

@@ -10,6 +10,7 @@ if TYPE_CHECKING:
from ...AnimeProvider import AnimeProvider
from ..config import Config
from .tools import FastAnimeRuntimeState
def format_time(duration_in_secs: float):
@@ -164,7 +165,7 @@ class MpvPlayer(object):
self,
stream_link,
anime_provider: "AnimeProvider",
fastanime_runtime_state,
fastanime_runtime_state: "FastAnimeRuntimeState",
config: "Config",
title,
start_time,

View File

@@ -1,17 +1,30 @@
# TODO: add typing
class FastAnimeRuntimeState(dict):
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from typing import Any
from ...libs.anilist.types import AnilistBaseMediaDataSchema
from ...libs.anime_provider.types import Anime, EpisodeStream, SearchResult, Server
class FastAnimeRuntimeState(object):
"""A class that manages fastanime runtime during anilist command runtime"""
def __getattr__(self, attr):
try:
return self.__getitem__(attr)
except KeyError:
raise AttributeError(
"%r object has no attribute %r" % (self.__class__.__name__, attr)
)
provider_current_episode_stream_link: str
provider_current_server: "Server"
provider_current_server_name: str
provider_available_episodes: list[str]
provider_current_episode_number: str
provider_server_episode_streams: list["EpisodeStream"]
provider_anime_title: str
provider_anime: "Anime"
provider_anime_search_result: "SearchResult"
def __setattr__(self, attr, value):
self.__setitem__(attr, value)
selected_anime_anilist: "AnilistBaseMediaDataSchema"
selected_anime_id_anilist: int
selected_anime_title_anilist: str
# current_anilist_data: "AnilistDataSchema | AnilistMediaList"
current_anilist_data: "Any"
def exit_app(exit_code=0, *args):

View File

@@ -3,7 +3,6 @@ This module contains all the preset queries for the sake of neatness and convini
Mostly for internal usage
"""
# TODO: Format the queries
mark_as_read_mutation = """
mutation{
UpdateUser{
@@ -17,7 +16,6 @@ query($id:Int){
pageInfo{
total
}
reviews(mediaId:$id){
summary
user{
@@ -62,7 +60,6 @@ query{
}
}
}
"""
get_medialist_item_query = """
@@ -77,7 +74,6 @@ delete_list_entry_query = """
mutation ($id: Int) {
DeleteMediaListEntry(id: $id) {
deleted
}
}
"""
@@ -98,8 +94,20 @@ query{
"""
media_list_mutation = """
mutation($mediaId:Int,$scoreRaw:Int,$repeat:Int,$progress:Int,$status:MediaListStatus){
SaveMediaListEntry(mediaId:$mediaId,scoreRaw:$scoreRaw,progress:$progress,repeat:$repeat,status:$status){
mutation (
$mediaId: Int
$scoreRaw: Int
$repeat: Int
$progress: Int
$status: MediaListStatus
) {
SaveMediaListEntry(
mediaId: $mediaId
scoreRaw: $scoreRaw
progress: $progress
repeat: $repeat
status: $status
) {
id
status
mediaId
@@ -116,7 +124,6 @@ mutation($mediaId:Int,$scoreRaw:Int,$repeat:Int,$progress:Int,$status:MediaListS
month
day
}
}
}
"""
@@ -130,7 +137,6 @@ query ($userId: Int, $status: MediaListStatus,$type:MediaType) {
}
mediaList(userId: $userId, status: $status, type: $type) {
mediaId
media {
id
idMal
@@ -151,7 +157,6 @@ query ($userId: Int, $status: MediaListStatus,$type:MediaType) {
title
thumbnail
}
favourites
averageScore
episodes
@@ -204,7 +209,6 @@ query ($userId: Int, $status: MediaListStatus,$type:MediaType) {
day
}
createdAt
}
}
}
@@ -236,8 +240,7 @@ $format_in:[MediaFormat],\
$type:MediaType\
$season:MediaSeason\
"
# FuzzyDateInt = (yyyymmdd)
# MediaStatus = (FINISHED,RELEASING,NOT_YET_RELEASED,CANCELLED,HIATUS)
search_query = (
"""
query($query:String,%s){
@@ -248,31 +251,30 @@ query($query:String,%s){
hasNextPage
}
media(
search:$query,
id_in:$id_in,
genre_in:$genre_in,
genre_not_in:$genre_not_in,
tag_in:$tag_in,
tag_not_in:$tag_not_in,
status_in:$status_in,
status:$status,
startDate:$startDate,
status_not_in:$status_not_in,
popularity_greater:$popularity_greater,
popularity_lesser:$popularity_lesser,
averageScore_greater:$averageScore_greater,
averageScore_lesser:$averageScore_lesser,
startDate_greater:$startDate_greater,
startDate_lesser:$startDate_lesser,
endDate_greater:$endDate_greater,
endDate_lesser:$endDate_lesser,
format_in:$format_in,
sort:$sort,
season:$season,
seasonYear:$seasonYear,
search: $query
id_in: $id_in
genre_in: $genre_in
genre_not_in: $genre_not_in
tag_in: $tag_in
tag_not_in: $tag_not_in
status_in: $status_in
status: $status
startDate: $startDate
status_not_in: $status_not_in
popularity_greater: $popularity_greater
popularity_lesser: $popularity_lesser
averageScore_greater: $averageScore_greater
averageScore_lesser: $averageScore_lesser
startDate_greater: $startDate_greater
startDate_lesser: $startDate_lesser
endDate_greater: $endDate_greater
endDate_lesser: $endDate_lesser
format_in: $format_in
sort: $sort
season: $season
seasonYear: $seasonYear
type: $type
)
{
) {
id
idMal
title {
@@ -286,7 +288,6 @@ query($query:String,%s){
trailer {
site
id
}
mediaListEntry {
status
@@ -298,7 +299,6 @@ query($query:String,%s){
title
thumbnail
}
favourites
averageScore
episodes
@@ -339,7 +339,6 @@ query($query:String,%s){
trending_query = """
query ($type: MediaType) {
Page(perPage: 15) {
media(sort: TRENDING_DESC, type: $type, genre_not_in: ["hentai"]) {
id
idMal
@@ -360,7 +359,6 @@ query($type:MediaType){
title
thumbnail
}
favourites
averageScore
genres
@@ -419,7 +417,6 @@ query($type:MediaType){
trailer {
site
id
}
mediaListEntry {
status
@@ -431,7 +428,6 @@ query($type:MediaType){
title
thumbnail
}
streamingEpisodes {
title
thumbnail
@@ -488,7 +484,6 @@ query($type:MediaType){
trailer {
site
id
}
mediaListEntry {
status
@@ -500,7 +495,6 @@ query($type:MediaType){
title
thumbnail
}
episodes
favourites
averageScore
@@ -553,14 +547,12 @@ query($type:MediaType){
trailer {
site
id
}
popularity
streamingEpisodes {
title
thumbnail
}
favourites
averageScore
description
@@ -604,7 +596,13 @@ query($type:MediaType){
most_recently_updated_query = """
query ($type: MediaType) {
Page(perPage: 15) {
media(sort:UPDATED_AT_DESC,type:$type,averageScore_greater:50,genre_not_in:["hentai"],status:RELEASING){
media(
sort: UPDATED_AT_DESC
type: $type
averageScore_greater: 50
genre_not_in: ["hentai"]
status: RELEASING
) {
id
idMal
title {
@@ -694,7 +692,6 @@ query($type:MediaType){
site
id
}
genres
averageScore
popularity
@@ -702,7 +699,6 @@ query($type:MediaType){
title
thumbnail
}
favourites
tags {
name
@@ -769,7 +765,12 @@ query($id:Int,$type:MediaType){
anime_relations_query = """
query ($id: Int, $type: MediaType) {
Page(perPage: 20) {
media(id: $id, sort: POPULARITY_DESC, type: $type,genre_not_in:["hentai"]) {
media(
id: $id
sort: POPULARITY_DESC
type: $type
genre_not_in: ["hentai"]
) {
relations {
nodes {
id
@@ -801,7 +802,6 @@ query ($id: Int,$type:MediaType) {
title
thumbnail
}
favourites
tags {
name
@@ -855,7 +855,12 @@ query ($page: Int,$type:MediaType) {
currentPage
hasNextPage
}
media(type: $type, status: NOT_YET_RELEASED,sort:POPULARITY_DESC,genre_not_in:["hentai"]) {
media(
type: $type
status: NOT_YET_RELEASED
sort: POPULARITY_DESC
genre_not_in: ["hentai"]
) {
id
idMal
title {
@@ -880,7 +885,6 @@ query ($page: Int,$type:MediaType) {
title
thumbnail
}
favourites
averageScore
genres
@@ -944,7 +948,6 @@ query($id:Int){
node {
name {
full
}
gender
dateOfBirth {

View File

@@ -15,10 +15,7 @@ from .constants import ALLANIME_API_ENDPOINT, ALLANIME_BASE, ALLANIME_REFERER
from .gql_queries import ALLANIME_EPISODES_GQL, ALLANIME_SEARCH_GQL, ALLANIME_SHOW_GQL
if TYPE_CHECKING:
from typing import Iterator
from ....libs.anime_provider.allanime.types import AllAnimeEpisode
from ....libs.anime_provider.types import Anime, Server
from .types import AllAnimeEpisode
logger = logging.getLogger(__name__)
@@ -54,18 +51,18 @@ class AllAnimeAPI(AnimeProvider):
},
timeout=10,
)
if response.status_code == 200:
if response.ok:
return response.json()["data"]
else:
logger.error("allanime(ERROR): ", response.text)
logger.error("[ALLANIME-ERROR]: ", response.text)
return {}
except Timeout:
logger.error(
"allanime(Error):Timeout exceeded this could mean allanime is down or you have lost internet connection"
"[ALLANIME-ERROR]: Timeout exceeded this could mean allanime is down or you have lost internet connection"
)
return {}
except Exception as e:
logger.error(f"allanime:Error: {e}")
logger.error(f"[ALLANIME-ERROR]: {e}")
return {}
def search_for_anime(
@@ -120,7 +117,7 @@ class AllAnimeAPI(AnimeProvider):
return normalized_search_results
except Exception as e:
logger.error(f"FA(AllAnime): {e}")
logger.error(f"[ALLANIME-ERROR]: {e}")
return {}
def get_anime(self, allanime_show_id: str):
@@ -147,8 +144,8 @@ class AllAnimeAPI(AnimeProvider):
}
return normalized_anime
except Exception as e:
logger.error(f"AllAnime(get_anime): {e}")
return None
logger.error(f"[ALLANIME-ERROR]: {e}")
return {}
def _get_anime_episode(
self, allanime_show_id: str, episode_string: str, translation_type: str = "sub"
@@ -172,12 +169,10 @@ class AllAnimeAPI(AnimeProvider):
episode = self._fetch_gql(ALLANIME_EPISODES_GQL, variables)
return episode["episode"]
except Exception as e:
logger.error(f"FA(AllAnime): {e}")
logger.error(f"[ALLANIME-ERROR]: {e}")
return {}
def get_episode_streams(
self, anime: "Anime", episode_number: str, translation_type="sub"
) -> "Iterator[Server] | None":
def get_episode_streams(self, anime, episode_number: str, translation_type="sub"):
"""get the streams of an episode
Args:
@@ -235,7 +230,7 @@ class AllAnimeAPI(AnimeProvider):
"quality": "1080",
}
],
} # pyright:ignore
}
continue
# get the stream url for an episode of the defined source names
@@ -247,7 +242,7 @@ class AllAnimeAPI(AnimeProvider):
timeout=10,
)
if resp.status_code == 200:
if resp.ok:
match embed["sourceName"]:
case "Luf-mp4":
logger.debug("allanime:Found streams from gogoanime")
@@ -260,7 +255,7 @@ class AllAnimeAPI(AnimeProvider):
)
+ f"; Episode {episode_number}",
"links": give_random_quality(resp.json()["links"]),
} # pyright:ignore
}
case "Kir":
logger.debug("allanime:Found streams from wetransfer")
yield {
@@ -272,7 +267,7 @@ class AllAnimeAPI(AnimeProvider):
)
+ f"; Episode {episode_number}",
"links": give_random_quality(resp.json()["links"]),
} # pyright:ignore
}
case "S-mp4":
logger.debug("allanime:Found streams from sharepoint")
yield {
@@ -284,7 +279,7 @@ class AllAnimeAPI(AnimeProvider):
)
+ f"; Episode {episode_number}",
"links": give_random_quality(resp.json()["links"]),
} # pyright:ignore
}
case "Sak":
logger.debug("allanime:Found streams from dropbox")
yield {
@@ -296,7 +291,7 @@ class AllAnimeAPI(AnimeProvider):
)
+ f"; Episode {episode_number}",
"links": give_random_quality(resp.json()["links"]),
} # pyright:ignore
}
case "Default":
logger.debug("allanime:Found streams from wixmp")
yield {
@@ -308,16 +303,13 @@ class AllAnimeAPI(AnimeProvider):
)
+ f"; Episode {episode_number}",
"links": give_random_quality(resp.json()["links"]),
} # pyright:ignore
}
except Timeout:
logger.error(
"Timeout has been exceeded this could mean allanime is down or you have lost internet connection"
"[ALLANIME-ERROR]: Timeout has been exceeded this could mean allanime is down or you have lost internet connection"
)
except Exception as e:
logger.error(f"FA(Allanime): {e}")
logger.error(f"[ALLANIME-ERROR]: {e}")
except Exception as e:
logger.error(f"FA(Allanime): {e}")
logger.error(f"[ALLANIME-ERROR]: {e}")
return []

View File

@@ -28,29 +28,29 @@ query(
ALLANIME_EPISODES_GQL = """\
query ($showId: String!, $translationType: VaildTranslationTypeEnumType!, $episodeString: String!) {
query (
$showId: String!
$translationType: VaildTranslationTypeEnumType!
$episodeString: String!
) {
episode(
showId: $showId
translationType: $translationType
episodeString: $episodeString
) {
episodeString
sourceUrls
notes
}
}"""
}
"""
ALLANIME_SHOW_GQL = """
query ($showId: String!) {
show(
_id: $showId
) {
show(_id: $showId) {
_id
name
availableEpisodesDetail
}
}
"""

View File

@@ -20,7 +20,6 @@ from .constants import (
from .utils import process_animepahe_embed_page
if TYPE_CHECKING:
from ..types import Anime
from .types import AnimePaheAnimePage, AnimePaheSearchPage, AnimeSearchResult
JUICY_STREAM_REGEX = re.compile(r"source='(.*)';")
logger = logging.getLogger(__name__)
@@ -40,7 +39,7 @@ class AnimePaheApi(AnimeProvider):
response = self.session.get(
url,
)
if not response.status_code == 200:
if not response.ok:
return
data: "AnimePaheSearchPage" = response.json()
self.search_page = data
@@ -68,7 +67,7 @@ class AnimePaheApi(AnimeProvider):
}
except Exception as e:
logger.error(f"AnimePahe(search): {e}")
logger.error(f"[ANIMEPAHE-ERROR]: {e}")
return {}
def get_anime(self, session_id: str, *args):
@@ -90,7 +89,7 @@ class AnimePaheApi(AnimeProvider):
response = self.session.get(
url,
)
if response.status_code == 200:
if response.ok:
if not data:
data.update(response.json())
else:
@@ -151,12 +150,10 @@ class AnimePaheApi(AnimeProvider):
],
}
except Exception as e:
logger.error(f"AnimePahe(anime): {e}")
logger.error(f"[ANIMEPAHE-ERROR]: {e}")
return {}
def get_episode_streams(
self, anime: "Anime", episode_number: str, translation_type, *args
):
def get_episode_streams(self, anime, episode_number: str, translation_type, *args):
try:
# extract episode details from memory
episode = [
@@ -167,7 +164,7 @@ class AnimePaheApi(AnimeProvider):
if not episode:
logger.error(
f"AnimePahe(streams): episode {episode_number} doesn't exist"
f"[ANIMEPAHE-ERROR]: episode {episode_number} doesn't exist"
)
return []
episode = episode[0]
@@ -207,24 +204,24 @@ class AnimePaheApi(AnimeProvider):
if not embed_url:
logger.warn(
"AnimePahe: embed url not found please report to the developers"
"[ANIMEPAHE-WARN]: embed url not found please report to the developers"
)
return []
# get embed page
embed_response = self.session.get(
embed_url, headers={"User-Agent": self.USER_AGENT, **SERVER_HEADERS}
)
if not response.status_code == 200:
if not response.ok:
continue
embed_page = embed_response.text
decoded_js = process_animepahe_embed_page(embed_page)
if not decoded_js:
logger.error("Animepahe: failed to decode embed page")
logger.error("[ANIMEPAHE-ERROR]: failed to decode embed page")
return
juicy_stream = JUICY_STREAM_REGEX.search(decoded_js)
if not juicy_stream:
logger.error("Animepahe: failed to find juicy stream")
logger.error("[ANIMEPAHE-ERROR]: failed to find juicy stream")
return
juicy_stream = juicy_stream.group(1)
# add the link
@@ -237,4 +234,4 @@ class AnimePaheApi(AnimeProvider):
)
yield streams
except Exception as e:
logger.error(f"Animepahe: {e}")
logger.error(f"[ANIMEPAHE-ERROR]: {e}")

View File

@@ -45,7 +45,7 @@ class AniWatchApi(AnimeProvider):
query = quote_plus(anime_title)
url = f"https://hianime.to/search?keyword={query}"
response = self.session.get(url)
if response.status_code != 200:
if not response.ok:
return
search_page = response.text
search_results_html_items = get_elements_by_class("flw-item", search_page)
@@ -88,7 +88,7 @@ class AniWatchApi(AnimeProvider):
return {"pageInfo": {}, "results": results}
except Exception as e:
logger.error(e)
logger.error(f"[ANIWATCH-ERROR]: {e}")
def get_anime(self, aniwatch_id, *args):
try:
@@ -99,7 +99,7 @@ class AniWatchApi(AnimeProvider):
break
anime_url = f"https://hianime.to/ajax/v2/episode/list/{aniwatch_id}"
response = self.session.get(anime_url, timeout=10)
if response.status_code == 200:
if response.ok:
response_json = response.json()
aniwatch_anime_page = response_json["html"]
episodes_info_container_html = get_element_html_by_class(
@@ -140,7 +140,7 @@ class AniWatchApi(AnimeProvider):
"episodes_info": self.episodes_info,
}
except Exception as e:
logger.error(e)
logger.error(f"[ANIWACTCH-ERROR]: {e}")
def get_episode_streams(self, anime, episode, translation_type, *args):
try:
@@ -154,7 +154,7 @@ class AniWatchApi(AnimeProvider):
episode_details = episode_details[0]
episode_url = f"https://hianime.to/ajax/v2/episode/servers?episodeId={episode_details['id']}"
response = self.session.get(episode_url)
if response.status_code == 200:
if response.ok:
response_json = response.json()
episode_page_html = response_json["html"]
servers_containers_html = get_elements_html_by_class(
@@ -194,7 +194,7 @@ class AniWatchApi(AnimeProvider):
servers_info = extract_attributes(server_html)
embed_url = f"https://hianime.to/ajax/v2/episode/sources?id={servers_info['data-id']}"
embed_response = self.session.get(embed_url)
if embed_response.status_code == 200:
if embed_response.ok:
embed_json = embed_response.json()
raw_link_to_streams = embed_json["link"]
match = LINK_TO_STREAMS_REGEX.match(raw_link_to_streams)
@@ -207,7 +207,7 @@ class AniWatchApi(AnimeProvider):
link_to_streams = f"https://{provider_domain}/embed-{embed_type}/ajax/e-{episode_number}/getSources?id={source_id}"
link_to_streams_response = self.session.get(link_to_streams)
if link_to_streams_response.status_code == 200:
if link_to_streams_response.ok:
juicy_streams_json: "AniWatchStream" = (
link_to_streams_response.json()
)
@@ -231,6 +231,6 @@ class AniWatchApi(AnimeProvider):
),
}
except Exception as e:
logger.error(e)
logger.error(f"[ANIWATCH_ERROR]: {e}")
except Exception as e:
logger.error(e)
logger.error(f"[ANIWATCH_ERROR]: {e}")

View File

@@ -1,4 +1,3 @@
# TODO: Write tests to make sure all click commands work
import pytest
from click.testing import CliRunner