Coverage for otaku_info/external/entities/AnimeListItem.py: 81%
Shortcuts on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""LICENSE
2Copyright 2020 Hermann Krumrey <hermann@krumreyh.com>
4This file is part of otaku-info.
6otaku-info is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation, either version 3 of the License, or
9(at your option) any later version.
11otaku-info is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
16You should have received a copy of the GNU General Public License
17along with otaku-info. If not, see <http://www.gnu.org/licenses/>.
18LICENSE"""
20from typing import Optional, Dict, Any, Tuple
21from otaku_info.enums import MediaType, MediaSubType, \
22 ReleasingState, MediaRelationType, ListService
25class AnimeListItem:
26 """
27 Class that models a general anime list item
28 """
29 def __init__(
30 self,
31 _id: int,
32 service: ListService,
33 extra_ids: Dict[ListService, str],
34 media_type: MediaType,
35 media_subtype: MediaSubType,
36 english_title: Optional[str],
37 romaji_title: str,
38 cover_url: str,
39 chapters: Optional[int],
40 volumes: Optional[int],
41 episodes: Optional[int],
42 next_episode: Optional[int],
43 next_episode_airing_time: Optional[int],
44 releasing_state: ReleasingState,
45 relations: Dict[Tuple[MediaType, int], MediaRelationType]
46 ):
47 """
48 Initializes the AnimeListItem object
49 :param _id: The anime list ID
50 :param service: The anime list service
51 :param extra_ids: Any extra IDs for other services
52 :param media_type: The media type of the series
53 :param media_subtype: The media subtype of the series
54 :param english_title: The English title of the series
55 :param romaji_title: The Japanes title of the series written in romaji
56 :param cover_url: URL to a cover image for the series
57 :param chapters: The total amount of known manga chapters
58 :param volumes: The total amount of known manga/ln volumes
59 :param episodes: The total amount of known anime episodes
60 :param next_episode: The next airing episode, if available
61 :param next_episode_airing_time: The airing time of the next episode
62 :param releasing_state: The current releasing state of the series
63 :param relations: Related media items identified by IDs
64 """
65 self.id = _id
66 self.service = service
67 self.extra_ids = extra_ids
68 self.media_type = media_type
69 self.media_subtype = media_subtype
70 self.english_title = english_title
71 self.romaji_title = romaji_title
72 self.cover_url = cover_url
73 self.chapters = chapters
74 self.volumes = volumes
75 self.episodes = episodes
76 self.next_episode = next_episode
77 self.next_episode_airing_time = next_episode_airing_time
78 self.releasing_state = releasing_state
79 self.relations = relations
81 @property
82 def latest_release(self) -> Optional[int]:
83 """
84 :return: The latest release. Chapters for manga, episodes for anime
85 """
86 if self.media_type == MediaType.ANIME:
87 return self.episodes
88 else:
89 return self.chapters
91 @classmethod
92 def from_query(cls, media_type: MediaType, data: Dict[str, Any]) \
93 -> "AnimeListItem":
94 """
95 Generates an AnimeListItem from a dictionary generated by an APi query
96 :param media_type: The media type of the item
97 :param data: The data to use
98 :return: The generated AnimeListItem
99 """
100 raise NotImplementedError()