def get_complete_object(self): """Gets the current anime object but with complete attributes. Sometimes, the Anime object that is returned by the API does not contain values for all the attributes that the Anime object has. Use this method to get an object with the maximum amount of data. This method is almost never required but is for edge cases :return: An Anime object with values for as many attributes as possible. :rtype: Anime """ data = { "controller": "Anime", "action": "getAnime", "detail_id": str(self.anime_id), } headers = self.__generate_default_headers() json = self.__network.post(data, headers) if json.get("success", True) != True: error = json["error"] raise AniwatchError(error) else: data_dict = json["anime"] return Anime( data_dict, self.__network, api_url=self.__API_URL, )
def get_episodes(self): """Gets a list of all available episodes of the anime. :return: An EpisodeList object, an EpisodeList object is very similar to a normal list. You can access specific indexes using the "[]" syntax. In addition to this, an EpisodeList has few convinience methods like ``get_episode_by_number(episode_number)`` which returns an episode with the provided episode number. :rtype: EpisodeList """ if self.__episodes: return self.__episodes else: data = { "controller": "Anime", "action": "getEpisodes", "detail_id": str(self.anime_id), } headers = self.__generate_default_headers() json = self.__network.post(data, headers) if json.get("success", True) != True: error = json["error"] raise AniwatchError(error) else: self.__episodes = EpisodeList([ Episode( data_dict, self.__network, self.__API_URL, self.anime_id, self.title, ) for data_dict in json["episodes"] ]) return self.__episodes
def get_chronicle(self, page=1): """Gets the chronicle for the anime, a chronicle tracks the user's watch history for a particular anime. :param page: The page of the chronicle you want to get, defaults to 1 :type page: int, optional :return: A list of ChronicleEntry objects where each object has details like date. :rtype: list[ChronicleEntry] """ data = { "controller": "Profile", "action": "getChronicle", "detail_id": str(self.anime_id), "page": page, } headers = self.__generate_default_headers() json = self.__network(data, headers) if json.get("success", True) != True: error = json["error"] raise AniwatchError(error) else: return [ ChronicleEntry(data_dict, self.__network, self.__API_URL) for data_dict in json["chronicle"] ]
def get_anime(self, anime_id: int): """Gets an anime by its ID. :param anime_id: ID of the anime you want to get. :type anime_id: int :return: An Anime object that has all the relevant details regarding a single anime like title, description, score, number of episodes etc. :rtype: Anime """ data = { "controller": "Anime", "action": "getAnime", "detail_id": str(anime_id) } headers = { "X-PATH": f"/anime/{anime_id}", "REFERER": f"https://aniwatch.me/anime/{anime_id}" } json = self.network.post(data, headers) if json.get("success", True) != True: error = json["error"] raise AniwatchError(error) else: return Anime( json["anime"], network=self.network, api_url=self.API_URL, )
def get_relations(self): """Gets the relation of the anime. :return: A Relation object that contains all the details of the relation. :rtype: Relation """ data = { "controller": "Relation", "action": "getRelation", "relation_id": self.relation_id, } headers = self.__generate_default_headers() json = self.__network.post(data, headers) if json.get("success", True) != True: error = json["error"] raise AniwatchError(error) else: return Relation(json["relation"])
def search(self, query: str): """Searches the aniwatch.me library for the given anime title. :param query: The title of the anime that you want to search. Aniwatch also stores synonyms, english names for animes so those can be used too. :type query: str :return: A list of Anime objects. :rtype: [type] """ data = { "controller": "Search", "action": "search", "rOrder": False, "order": "title", "typed": str(query), "genre": "[]", "staff": "[]", "tags": [], "langs": [], "anyGenre": False, "anyStaff": False, "anyTag": False, "animelist": [2], "types": [0], "status": [0], "yearRange": [1965, 2022], "maxEpisodes": 0, "hasRelation": False, } headers = { "X-PATH": "/search", "REFERER": f"https://aniwatch.me/search" } json = self.network.post(data, headers) if type(json) == dict and json.get("success", True) != True: error = json["error"] raise AniwatchError(error) else: return [ Anime(data_dict, self.network, self.API_URL) for data_dict in json ]
def get_recommendations(self): """Gets the recommendations for the anime. :return: A list of RecommendationEntry objects where each object represents a single recommendation. :rtype: list[RecommendationEntry] """ data = { "controller": "Anime", "action": "getRecommendations", "detail_id": str(self.anime_id), } headers = self.__generate_default_headers() json = self.__network(data, headers) if json.get("success", True) != True: error = json["error"] raise AniwatchError(error) else: return [ RecommendationEntry(data_dict, self.__network) for data_dict in json["entries"] ]