def voice_acting(self): lst = [] for va in self._raw_voice_acting: char = va['character'] char['mal_id'] = parse_id(char['url']) anime = va['anime'] anime['mal_id'] = parse_id(anime['url']) anime_obj = PartialAnime.from_character(anime, state=self._state) obj = PartialCharacter.from_person(char, anime_obj, state=self._state) lst.append(obj) return lst
def voice_actors(self): lst = [] for va in self._raw_voice_actors: va['mal_id'] = parse_id(va['url']) obj = PartialPerson.from_voice_acting(va, state=self._state) lst.append(obj) return lst
def mangaography(self): lst = [] for manga in self._raw_mangaography: manga['mal_id'] = parse_id(manga['url']) obj = PartialManga.from_character(manga, state=self._state) lst.append(obj) return lst
def animeography(self): lst = [] for anime in self._raw_animeography: anime['mal_id'] = parse_id(anime['url']) obj = PartialAnime.from_character(anime, state=self._state) lst.append(obj) return lst
def manga(self): lst = [] for position in self._raw_manga: manga = position['manga'] manga['mal_id'] = parse_id(manga['url']) manga['relation'] = position['role'] manga['title'] = manga.pop('name') obj = PartialManga.from_related(manga, state=self._state) lst.append(obj) return lst
def anime(self): lst = [] for position in self._raw_anime: anime = position['anime'] anime['mal_id'] = parse_id(anime['url']) anime['relation'] = position['role'] anime['title'] = anime.pop('name') obj = PartialAnime.from_related(anime, state=self._state) lst.append(obj) return lst
async def search_id(self, type_, query): """Parse a google query and return the ID. Raises a :class:`TokageNotFound` Error if an ID was not found. """ query = "site:myanimelist.net/{}/ {}".format(type_, query) params = {'q': query, 'safe': 'on'} headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; Win64; x64)'} url = 'https://www.google.com/search' async with self.session.get(url, params=params, headers=headers) as resp: if resp.status != 200: raise RuntimeError('Google somehow failed to respond.') root = etree.fromstring(await resp.text(), etree.HTMLParser()) nodes = root.findall(".//div[@class='g']") for node in nodes: url_node = node.find('.//h3/a') if url_node is None: continue url = url_node.attrib['href'] if not url.startswith('/url?'): continue url = parse_qs(url[5:])['q'][0] id = parse_id(url) if id is None: raise TokageNotFound( "An ID corresponding to the given query was not found") return id else: raise TokageNotFound( "An ID corresponding to the given query was not found")
def author(self): self._raw_author['mal_id'] = parse_id(self._raw_author['url']) return PartialPerson.from_author(self._raw_author, state=self._state)