Skip to content

Commit d30e905

Browse files
committed
Add enums
1 parent f604562 commit d30e905

File tree

4 files changed

+226
-23
lines changed

4 files changed

+226
-23
lines changed

docs/models.rst

+121-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
API Models
22
==========
33

4-
.. currentmodule:: kitsu.models
4+
.. currentmodule:: kitsu
55

66
Anime
77
-----
@@ -17,4 +17,123 @@ Manga
1717
-----
1818

1919
.. autoclass:: Manga()
20-
:members:
20+
:members:
21+
22+
Enumerations
23+
------------
24+
25+
.. class:: AgeRating
26+
:canonical: kitsu.enums.AgeRating
27+
28+
Denotes the age rating of a Media.
29+
30+
.. attribute:: G
31+
32+
Rated for general audiences.
33+
34+
.. attribute:: PG
35+
36+
Rated as parental guidance suggested.
37+
38+
.. attribute:: R
39+
40+
Rated as restricted.
41+
42+
.. attribute:: R18
43+
44+
Rated as explicit.
45+
46+
47+
.. class:: Status
48+
:canonical: kitsu.enums.Status
49+
50+
Denotes the status of an Anime or Manga.
51+
52+
.. attribute:: current
53+
54+
The media is currently releasing.
55+
56+
.. attribute:: finished
57+
58+
The media has finished releasing.
59+
60+
.. attribute:: tba
61+
62+
The media is tba (to be announced).
63+
64+
.. attribute:: unreleased
65+
66+
The media is unreleased.
67+
68+
.. attribute:: upcoming
69+
70+
The media is upcoming.
71+
72+
.. class:: Season
73+
:canonical: kitsu.enums.Season
74+
75+
Denotes the release season of an Anime or Manga.
76+
77+
.. attribute:: spring
78+
79+
The media was released/will release in spring.
80+
81+
.. attribute:: summer
82+
83+
The media was released/will release in summer.
84+
85+
.. attribute:: fall
86+
87+
The media was released/will release in fall.
88+
89+
.. attribute:: winter
90+
91+
The media was released/will release in winter.
92+
93+
.. class:: AnimeSubtype
94+
:canonical: kitsu.enums.AnimeSubtype
95+
96+
Denotes the subtype of an Anime.
97+
98+
.. attribute:: ONA
99+
100+
The anime is an ONA (Original Net Animation).
101+
102+
.. attribute:: OVA
103+
104+
The anime is an OVA (Original Video Animation).
105+
106+
.. attribute:: TV
107+
108+
The anime is a TV series.
109+
110+
.. attribute:: movie
111+
112+
The anime is a movie.
113+
114+
.. attribute:: music
115+
116+
The anime is a music.
117+
118+
.. attribute:: special
119+
120+
The anime is a special.
121+
122+
.. class:: MangaSubtype
123+
:canonical: kitsu.enums.MangaSubtype
124+
125+
Denotes the subtype of a Manga.
126+
127+
.. attribute:: doujin
128+
129+
.. attribute:: manga
130+
131+
.. attribute:: manhua
132+
133+
.. attribute:: manwha
134+
135+
.. attribute:: novel
136+
137+
.. attribute:: oel
138+
139+
.. attribute:: oneshot

kitsu/client.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import aiohttp
2929

3030
from . import __version__
31+
from .enums import AgeRating, AnimeSubtype, Season
3132
from .errors import BadRequest, HTTPException, NotFound
3233
from .models import Anime, Manga
3334

@@ -110,9 +111,9 @@ async def search_anime(
110111
text: Optional[str] = None,
111112
after_year: Optional[int] = None,
112113
before_year: Optional[int] = None,
113-
season: Optional[List[Literal["spring", "summer", "fall", "winter"]]] = None,
114-
age_rating: Optional[List[Literal["G", "PG", "R", "R18"]]] = None,
115-
subtype: Optional[List[Literal["ONA", "OVA", "TV", "movie", "music", "special"]]] = None,
114+
season: Optional[List[Season]] = None,
115+
age_rating: Optional[List[AgeRating]] = None,
116+
subtype: Optional[List[AnimeSubtype]] = None,
116117
categories: Optional[List[str]] = None,
117118
) -> List[Anime]:
118119
"""
@@ -130,11 +131,11 @@ async def search_anime(
130131
The upper limit of the release year of the Anime to use for filtering the results.
131132
before_year: Optional[:class:`int`]
132133
The upper limit of the release year of the Anime to use for filtering the results.
133-
season: Optional[List[Literal["spring", "summer", "fall", "winter"]]]
134+
season: Optional[List[:class:`Season`]]
134135
The release season(s) of the Anime to use for filtering the results.
135-
age_rating: Optional[List[Literal["G", "PG", "R", "R18"]]]
136+
age_rating: Optional[List[:class:`AgeRating`]]
136137
The age rating(s) of the Anime to use for filtering the results.
137-
subtype: Optional[List[Literal["ONA", "OVA", "TV", "movie", "music", "special"]]]
138+
subtype: Optional[List[:class:`AnimeSubtype`]]
138139
The subtype(s) of the Anime to use for filtering the results.
139140
categories: Optional[List[:class:`str`]]
140141
The categories of the Anime to use for filtering the results.
@@ -152,13 +153,13 @@ async def search_anime(
152153
params["filter[seasonYear]"] = f"{after_year or ''}..{before_year or ''}"
153154

154155
if season is not None:
155-
params["filter[season]"] = ",".join(season)
156+
params["filter[season]"] = ",".join(str(season))
156157

157158
if age_rating is not None:
158-
params["filter[ageRating]"] = ",".join(age_rating)
159+
params["filter[ageRating]"] = ",".join(str(age_rating))
159160

160161
if subtype is not None:
161-
params["fiter[subtype]"] = ",".join(subtype)
162+
params["fiter[subtype]"] = ",".join(str(subtype))
162163

163164
if categories is not None:
164165
params["filter[categories]"] = ",".join(categories)

kitsu/enums.py

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
"""
2+
MIT License
3+
4+
Copyright (c) 2021-present MrArkon
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
"""
24+
25+
from enum import Enum
26+
27+
28+
class AgeRating(Enum):
29+
G = "G"
30+
PG = "PG"
31+
R = "R"
32+
R18 = "R18"
33+
34+
def __str__(self) -> str:
35+
return self.value
36+
37+
38+
class Status(Enum):
39+
current = "current"
40+
finished = "finished"
41+
tba = "tba"
42+
unreleased = "unreleased"
43+
upcoming = "upcoming"
44+
45+
def __str__(self) -> str:
46+
return self.value
47+
48+
49+
class Season(Enum):
50+
spring = "spring"
51+
summer = "summer"
52+
fall = "fall"
53+
winter = "winter"
54+
55+
def __str__(self) -> str:
56+
return self.value
57+
58+
59+
class AnimeSubtype(Enum):
60+
ONA = "ONA"
61+
OVA = "OVA"
62+
TV = "TV"
63+
movie = "movie"
64+
music = "music"
65+
special = "special"
66+
67+
def __str__(self) -> str:
68+
return self.value
69+
70+
71+
class MangaSubtype(Enum):
72+
doujin = "doujin"
73+
manga = "manga"
74+
manhua = "manhua"
75+
manhwa = "manhwa"
76+
novel = "novel"
77+
oel = "oel"
78+
oneshot = "oneshot"
79+
80+
def __str__(self) -> str:
81+
return self.value

kitsu/models.py

+14-12
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
from datetime import datetime
2727
from typing import TYPE_CHECKING, List, Optional
2828

29+
from .enums import AgeRating, AnimeSubtype, MangaSubtype, Status
30+
2931
if TYPE_CHECKING:
3032
from .client import Client
3133
from .types import AnimeData, EpisodeCollection, EpisodeData
@@ -181,13 +183,13 @@ class Anime:
181183
The popularity rank of this Anime on Kitsu.
182184
rating_rank: :class:`int`
183185
The rating rank of this Anime on Kitsu.
184-
age_rating: Literal["G", "PG", "R", "R18"]
186+
age_rating: :class:`AgeRating`
185187
The age rating of this Anime.
186188
age_rating_guide: :class:`str`
187189
A string describing the age rating of this Anime.
188-
subtype: Literal["ONA", "OVA", "TV", "movie", "music", "special"]
190+
subtype: :class:`AnimeSubtype`
189191
The subtype of this Anime.
190-
status: Literal["current", "finished", "tba", "unreleased", "upcoming"]
192+
status: :class:`Status`
191193
The status of this Anime.
192194
episode_count: :class:`int`
193195
The number of episodes in this Anime.
@@ -247,10 +249,10 @@ def __init__(self, payload: AnimeData, client: Client, *, included: Optional[Lis
247249
self.favorites_count = self._attributes["favoritesCount"]
248250
self.popularity_rank = self._attributes["popularityRank"]
249251
self.rating_rank = self._attributes["ratingRank"]
250-
self.age_rating = self._attributes["ageRating"]
252+
self.age_rating = AgeRating(self._attributes["ageRating"])
251253
self.age_rating_guide = self._attributes["ageRatingGuide"]
252-
self.subtype = self._attributes["subtype"]
253-
self.status = self._attributes["status"]
254+
self.subtype = AnimeSubtype(self._attributes["subtype"])
255+
self.status = Status(self._attributes["status"])
254256
self.episode_count = self._attributes["episodeCount"]
255257
self.episode_length = self._attributes["episodeLength"]
256258
self.youtube_video_id = self._attributes["youtubeVideoId"]
@@ -386,13 +388,13 @@ class Manga:
386388
The popularity rank of this Manga on Kitsu.
387389
rating_rank: :class:`int`
388390
The rating rank of this Manga on Kitsu.
389-
age_rating: Optional[Literal["G", "PG", "R", "R18"]]
391+
age_rating: :class:`AgeRating`
390392
The age rating of this Manga.
391393
age_rating_guide: Optional[:class:`str`]
392394
A string describing the age rating of this Manga.
393-
subtype: Literal["doujin", "manga", "manhua", "manhwa", "novel", "oel", "oneshot"]
395+
subtype: :class:`MangaSubtype`
394396
The subtype of this Manga.
395-
status: Literal["current", "finished", "tba", "unreleased", "upcoming"]
397+
status: :class:`Status`
396398
The status of this Manga.
397399
chapter_count: :class:`int`
398400
The number of chapters in the Manga.
@@ -446,10 +448,10 @@ def __init__(self, payload: MangaData, client: Client) -> None:
446448
self.favorites_count = self._attributes["favoritesCount"]
447449
self.popularity_rank = self._attributes["popularityRank"]
448450
self.rating_rank = self._attributes["ratingRank"]
449-
self.age_rating = self._attributes["ageRating"]
451+
self.age_rating = AgeRating(self._attributes["ageRating"])
450452
self.age_rating_guide = self._attributes["ageRatingGuide"]
451-
self.subtype = self._attributes["subtype"]
452-
self.status = self._attributes["status"]
453+
self.subtype = MangaSubtype(self._attributes["subtype"])
454+
self.status = Status(self._attributes["status"])
453455
self.chapter_count = self._attributes["chapterCount"]
454456
self.volume_count = self._attributes["volumeCount"]
455457
self.serialization = self._attributes["serialization"]

0 commit comments

Comments
 (0)