Hot-keys 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 2015 Hermann Krumrey <hermann@krumreyh.com>
4This file is part of toktokkie.
6toktokkie 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.
11toktokkie 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 toktokkie. If not, see <http://www.gnu.org/licenses/>.
18LICENSE"""
20from typing import Dict, Any
21from toktokkie.exceptions import InvalidMetadata
22from toktokkie.metadata.base.components.JsonComponent import JsonComponent
25class TvEpisode(JsonComponent):
26 """
27 Class that models a TV Episode
28 """
30 def __init__(self, season: int, episode: int):
31 """
32 Initializes the TvEpisode object
33 :param season: The season of the episode
34 :param episode: The episode number
35 """
36 self.season = season
37 self.episode = episode
39 @property
40 def json(self) -> Dict[str, Any]:
41 """
42 :return: The object represented as JSON data
43 """
44 return {"season": self.season, "episode": self.episode}
46 @classmethod
47 def from_json(cls, json_data: Dict[str, Any]) -> "TvEpisode":
48 """
49 Generates a TvEpisode object from json data
50 :param json_data: The JSON data
51 :return: The generated TvEpisode object
52 :raises InvalidMetadataException: If the provided JSON is invalid
53 """
54 try:
55 return cls(json_data["season"], json_data["episode"])
56 except KeyError as e:
57 raise InvalidMetadata(f"Attribute missing: {e}")