def search(self, query): 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, } return [ Anime(data_dict, self.headers, self.cookies, self.API_URL) for data_dict in self.__post(data) ]
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_hot_anime(self, page=1): # TODO inspect this to figure out a correct description. data = {"controller": "Anime", "action": "getHotAnime", "page": page} return [ Anime(data_dict, self.network, self.API_URL) for data_dict in self.network.post(data, "/home")["entries"] ]
def get_popular_upcoming_anime(self, page=1): data = { "controller": "Anime", "action": "getPopularUpcomings", "page": page } return [ Anime(data_dict, self.headers, self.cookies, self.API_URL) for data_dict in self.__post(data)["entries"] ]
def get_best_rated_anime(self, page=1): data = { "controller": "Anime", "action": "getBestRatedAnime", "page": page } return [ Anime(data_dict, self.headers, self.cookies, self.API_URL) for data_dict in self.__post(data)["entries"] ]
def get_random_anime(self): """Gets a random anime from the aniwatch.me library. :return: An Anime object representing a random anime. :rtype: Anime """ data = {"controller": "Anime", "action": "getRandomAnime"} return Anime( self.network.post(data, "/random")["entries"][0], self.network, self.API_URL)
def get_seasonal_anime(self, index="null", year="null"): data = { "controller": "Anime", "action": "getSeasonalAnime", "current_index": index, "current_year": year, } return [ Anime(data_dict, self.headers, self.cookies, self.API_URL) for data_dict in self.__post(data)["entries"] ]
def get_latest_anime(self): """Gets the latest animes on "aniwatch.me" :return: A list of Anime objects. :rtype: list[Anime] """ data = {"controller": "Anime", "action": "getLatestAnime"} return [ Anime(data_dict, self.network, self.API_URL) for data_dict in self.network.post(data, "/home")["entries"] ]
def get_anime(self, anime_id): data = { "controller": "Anime", "action": "getAnime", "detail_id": str(anime_id) } return Anime( self.__post(data)["anime"], headers=self.headers, cookies=self.cookies, api_url=self.API_URL, )
def get_latest_uploads(self): """Gets latest uploads on "aniwatch.me". This includes animes that are not airing currently. :return: A list of Anime objects. :rtype: list[Anime] """ data = {"controller": "Anime", "action": "getLatestUploads"} return [ Anime(data_dict, self.network, self.API_URL) for data_dict in self.network.post(data, "/home")["entries"] ]
def get_latest_releases(self): """Gets the latest anime releases. This includes currently airing animes. :return: List of Anime objects. :rtype: list[Anime] """ data = {"controller": "Anime", "action": "getLatestReleases"} return [ Anime(data_dict, self.network, self.API_URL) for data_dict in self.network.post(data, "/home")["entries"] ]
def get_airing_anime(self, randomize=False): data = { "controller": "Anime", "action": "getAiringAnime", "randomize": randomize, } airing_anime_response = self.__post(data)["entries"] airing_anime = {} for day, animes in airing_anime_response.items(): airing_anime[day] = [ Anime(anime_dict, self.headers, self.cookies, self.API_URL) for anime_dict in animes ] return airing_anime
def get_popular_upcoming_anime(self, page=1): """Gets popular anime that have not started airing yet. :param page: Page number of the popularity chart that you want, defaults to 1 :type page: int, optional :return: A list of Anime objects. :rtype: list[Anime] """ data = { "controller": "Anime", "action": "getPopularUpcomings", "page": page } return [ Anime(data_dict, self.network, self.API_URL) for data_dict in self.network.post(data, "/home")["entries"] ]
def get_popular_seasonal_anime(self, page=1): """Gets popular anime of the current season. :param page: Page number of the popularity chart that you want, defaults to 1 :type page: int, optional :return: A list of Anime objects. :rtype: list[Anime] """ data = { "controller": "Anime", "action": "getPopularSeasonals", "page": page } return [ Anime(data_dict, self.network, self.API_URL) for data_dict in self.network.post(data, "/seasonal")["entries"] ]
def get_best_rated_anime(self, page=1): """Gets the highest rated animes on "aniwatch.me". :param page: Page number of the popularity chart that you want, defaults to 1 :type page: int, optional :return: A list of Anime objetcs. :rtype: list[Anime] """ data = { "controller": "Anime", "action": "getBestRatedAnime", "page": page } return [ Anime(data_dict, self.network, self.API_URL) for data_dict in self.network.post(data, "/home")["entries"] ]
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_seasonal_anime(self, index="null", year="null"): """Gets current seasonal animes. :param index: [description], defaults to "null" :type index: str, optional :param year: [description], defaults to "null" :type year: str, optional :return: A list of Anime objects. :rtype: list[Anime] """ data = { "controller": "Anime", "action": "getSeasonalAnime", "current_index": index, "current_year": year, } return [ Anime(data_dict, self.network, self.API_URL) for data_dict in self.network.post(data, "/home")["entries"] ]
def get_airing_anime(self, randomize=False): """Gets currently airing anime arranged according to weekdays. :param randomize: [description], defaults to False :type randomize: bool, optional :return: A dictionary with weekdays as keys and corresponding list of Anime objects as values. :rtype: dict """ data = { "controller": "Anime", "action": "getAiringAnime", "randomize": randomize, } airing_anime_response = self.network.post(data, "/airing")["entries"] airing_anime = {} for day, animes in airing_anime_response.items(): airing_anime[day] = [ Anime(anime_dict, self.network, self.API_URL) for anime_dict in animes ] return airing_anime
def get_latest_anime(self): data = {"controller": "Anime", "action": "getLatestAnime"} return [ Anime(data_dict, self.headers, self.cookies, self.API_URL) for data_dict in self.__post(data)["entries"] ]
def get_random_anime(self): data = {"controller": "Anime", "action": "getRandomAnime"} return Anime( self.__post(data)["entries"][0], self.headers, self.cookies, self.API_URL)