-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c05bdc4
commit 34c54f1
Showing
6 changed files
with
121 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from .anime import * | ||
from .characters import * | ||
from .staff import * | ||
from .staff import * | ||
from .episodes import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
from __future__ import annotations | ||
from typing import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from typing import List, Optional | ||
from ...typing.jikan import ( | ||
AnimeEpisodeData, | ||
JikanPageResponseData | ||
) | ||
from ...typing.jikan.title import TitleData | ||
|
||
from datetime import datetime | ||
from dataclasses import dataclass, field | ||
|
||
from ..helpers import Title | ||
from ..base import JikanResource | ||
|
||
__all__ = ( | ||
"AnimeEpisodes", | ||
) | ||
|
||
@dataclass | ||
class AnimeEpisode(): | ||
data: AnimeEpisodeData = field(repr = False) | ||
|
||
id: int = field(init = False) | ||
"""The MyAnimeList ID of this episode.""" | ||
title: Title = field(init = False) | ||
"""The title of this episode.""" | ||
name: Title = field(init = False) | ||
"""Alias to ``AnimeEpisode.title``.""" | ||
url: Optional[str] = field(init = False) | ||
"""The MyAnimeList URL to this episode.""" | ||
aired: Optional[datetime] = field(init = False, default = None) | ||
"""The date this episode was aired.""" | ||
filler: bool = field(init = False) | ||
"""Is this episode a filler episode or not.""" | ||
recap: bool = field(init = False) | ||
"""Is this episode a recap episode or not.""" | ||
forum_url: Optional[str] = field(init = False) | ||
"""The URL to the forum discussion of this episode.""" | ||
|
||
def __post_init__(self): | ||
self.id = self.data["mal_id"] | ||
|
||
titles: List[TitleData] = [] | ||
|
||
japanese_title = self.data["title_japanese"] | ||
if japanese_title is not None: | ||
titles.append( | ||
{"type": "Japanese", "title": japanese_title} | ||
) | ||
|
||
romanji_title = self.data["title_romanji"] | ||
if romanji_title is not None: | ||
titles.append( | ||
{"type": "Japanese", "title": romanji_title} | ||
) | ||
|
||
titles.append( | ||
{"type": "Default", "title": self.data["title"]} | ||
) | ||
|
||
self.title = Title(titles) | ||
self.name = self.title | ||
|
||
self.url = self.data["url"] | ||
|
||
aired = self.data["aired"] | ||
if aired is not None: | ||
self.aired = datetime.fromisoformat(aired) | ||
|
||
self.filler = self.data["filler"] | ||
self.recap = self.data["recap"] | ||
self.forum_url = self.data["forum_url"] | ||
|
||
@dataclass | ||
class AnimeEpisodes(JikanResource): | ||
"""Get an anime's episodes.""" | ||
_get_endpoint = "/anime/{id}/episodes" | ||
|
||
data: JikanPageResponseData[List[AnimeEpisodeData]] | ||
|
||
def __iter__(self): | ||
|
||
for episode in self.data["data"]: | ||
yield AnimeEpisode(episode) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from .anime import * | ||
from .characters import * | ||
from .staff import * | ||
from .staff import * | ||
from .episode import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from __future__ import annotations | ||
from typing import TypedDict, final, Optional | ||
|
||
__all__ = ( | ||
"AnimeEpisodeData", | ||
) | ||
|
||
@final | ||
class AnimeEpisodeData(TypedDict): | ||
mal_id: int | ||
url: Optional[str] | ||
title: str | ||
title_japanese: str | ||
title_romanji: str | ||
# duration: Optional[int] # this just doesn't exist lmao | ||
aired: Optional[str] | ||
filler: bool | ||
recap: bool | ||
forum_url: Optional[str] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,16 @@ | ||
from typing import TypedDict, TypeVar, Generic | ||
|
||
__all__ = ("JikanResponseData",) | ||
__all__ = ( | ||
"JikanResponseData", | ||
"JikanPageResponseData" | ||
) | ||
|
||
T = TypeVar("T") | ||
|
||
class JikanResponseData(TypedDict, Generic[T]): | ||
"""Typical Jikan response data.""" | ||
data: T | ||
|
||
class JikanPageResponseData(TypedDict, Generic[T]): | ||
"""Jikan response data that contains pagination object.""" | ||
data: T |