def _parse_manga(self, root): """Converts an XML manga list to a dictionary""" mangalist = dict() for child in root.iter('manga'): manga_id = int(child.find('series_mangadb_id').text) if child.find('series_synonyms').text: aliases = child.find('series_synonyms').text.lstrip( '; ').split('; ') else: aliases = [] show = utils.show() show.update({ 'id': manga_id, 'title': child.find('series_title').text, 'aliases': aliases, 'my_progress': int(child.find('my_read_chapters').text), 'my_status': int(child.find('my_status').text), 'my_score': int(child.find('my_score').text), 'total': int(child.find('series_chapters').text), 'status': int(child.find('series_status').text), 'image': child.find('series_image').text, 'url': "http://myanimelist.net/manga/%d" % manga_id, }) mangalist[manga_id] = show return mangalist
def _parse_anime(self, data): """Loads JSON anime list into a dictionary""" showlist = dict() _my_statuses = {"watching": 1, "completed": 2, "on-hold": 3, "dropped": 4, "plan to watch": 6} _statuses = {"finished airing": 0, "currently airing": 1, "not yet aired": 2} for child in data["anime"]: show_id = child["id"] _my_status = child["watched_status"] _status = child["status"] show = utils.show() show.update( { "id": show_id, "title": child["title"].encode("utf-8"), "my_progress": child["watched_episodes"], "my_status": _my_statuses[_my_status], "my_score": child["score"], "total": child["episodes"], "status": _statuses[_status], "image": child["image_url"], } ) showlist[show_id] = show return showlist
def _parse_manga(self, data): """Loads JSON manga list into a dictionary""" showlist = dict() _my_statuses = { 'reading': 1, 'completed': 2, 'on-hold': 3, 'dropped': 4, 'plan to read': 6 } _statuses = {'finished': 0, 'publishing': 1, 'not yet published': 2} for child in data['manga']: manga_id = child[' id'] _my_status = child['read_status'] _status = child['status'] show = utils.show() show.update({ 'id': manga_id, 'title': child['title'].encode('utf-8'), 'my_progress': child['chapters_read'], 'my_status': _my_statuses[_my_status], 'my_score': child['score'], 'total': child['chapters'], 'status': _statuses[_status], 'image': child['image_url'], }) mangalist[manga_id] = show return mangalist
def _parse_anime(self, data): """Loads JSON anime list into a dictionary""" showlist = dict() _my_statuses = { 'watching': 1, 'completed': 2, 'on-hold': 3, 'dropped': 4, 'plan to watch': 6 } _statuses = { 'finished airing': 0, 'currently airing': 1, 'not yet aired': 2 } for child in data['anime']: show_id = child['id'] _my_status = child['watched_status'] _status = child['status'] show = utils.show() show.update({ 'id': show_id, 'title': child['title'].encode('utf-8'), 'my_progress': child['watched_episodes'], 'my_status': _my_statuses[_my_status], 'my_score': child['score'], 'total': child['episodes'], 'status': _statuses[_status], 'image': child['image_url'], }) showlist[show_id] = show return showlist
def _parse_anime(self, root): """Converts an XML anime list to a dictionary""" showlist = dict() for child in root.iter('anime'): show_id = int(child.find('series_animedb_id').text) if child.find('series_synonyms').text: aliases = child.find('series_synonyms').text.lstrip('; ').split('; ') else: aliases = [] show = utils.show() show.update({ 'id': show_id, 'title': child.find('series_title').text, 'aliases': aliases, 'my_progress': int(child.find('my_watched_episodes').text), 'my_status': int(child.find('my_status').text), 'my_score': int(child.find('my_score').text), 'total': int(child.find('series_episodes').text), 'status': int(child.find('series_status').text), 'image': child.find('series_image').text, 'url': "http://myanimelist.net/anime/%d" % show_id, }) showlist[show_id] = show return showlist
def _parse_manga(self, root): """Converts an XML manga list to a dictionary""" mangalist = dict() for child in root.iter("manga"): manga_id = int(child.find("series_mangadb_id").text) if child.find("series_synonyms").text: aliases = child.find("series_synonyms").text.lstrip("; ").split("; ") else: aliases = [] show = utils.show() show.update( { "id": manga_id, "title": child.find("series_title").text, "aliases": aliases, "my_progress": int(child.find("my_read_chapters").text), "my_status": int(child.find("my_status").text), "my_score": int(child.find("my_score").text), "total": int(child.find("series_chapters").text), "status": int(child.find("series_status").text), "image": child.find("series_image").text, "url": "http://myanimelist.net/manga/%d" % manga_id, } ) mangalist[manga_id] = show return mangalist
def _parse_anime(self, root): """Converts an XML anime list to a dictionary""" showlist = dict() for child in root.iter("anime"): show_id = int(child.find("series_animedb_id").text) if child.find("series_synonyms").text: aliases = child.find("series_synonyms").text.lstrip("; ").split("; ") else: aliases = [] show = utils.show() show.update( { "id": show_id, "title": child.find("series_title").text, "aliases": aliases, "my_progress": int(child.find("my_watched_episodes").text), "my_status": int(child.find("my_status").text), "my_score": int(child.find("my_score").text), "total": int(child.find("series_episodes").text), "status": int(child.find("series_status").text), "image": child.find("series_image").text, "url": "http://myanimelist.net/anime/%d" % show_id, } ) showlist[show_id] = show return showlist
def _parse_manga(self, root): """Converts an XML manga list to a dictionary""" mangalist = dict() for child in root.iter('manga'): manga_id = int(child.find('series_mangadb_id').text) if child.find('series_synonyms').text: aliases = child.find('series_synonyms').text.lstrip('; ').split('; ') else: aliases = [] show = utils.show() show.update({ 'id': manga_id, 'title': child.find('series_title').text, 'aliases': aliases, 'my_progress': int(child.find('my_read_chapters').text), 'my_status': int(child.find('my_status').text), 'my_score': int(child.find('my_score').text), 'total': int(child.find('series_chapters').text), 'status': int(child.find('series_status').text), 'image': child.find('series_image').text, 'url': "http://myanimelist.net/manga/%d" % manga_id, }) mangalist[manga_id] = show return mangalist
def _parse_manga(self, data): """Loads JSON manga list into a dictionary""" showlist = dict() _my_statuses = {"reading": 1, "completed": 2, "on-hold": 3, "dropped": 4, "plan to read": 6} _statuses = {"finished": 0, "publishing": 1, "not yet published": 2} for child in data["manga"]: manga_id = child[" id"] _my_status = child["read_status"] _status = child["status"] show = utils.show() show.update( { "id": manga_id, "title": child["title"].encode("utf-8"), "my_progress": child["chapters_read"], "my_status": _my_statuses[_my_status], "my_score": child["score"], "total": child["chapters"], "status": _statuses[_status], "image": child["image_url"], } ) mangalist[manga_id] = show return mangalist
def fetch_list(self): """Queries the full list from the remote server. Returns the list if successful, False otherwise.""" self.check_credentials() self.msg.info(self.name, 'Downloading list...') try: # Get an XML list from MyAnimeList API data = self._request( "/users/%s/library" % self.username, get={'auth_token': self.auth} ) shows = json.load(data) showlist = dict() infolist = list() for show in shows: slug = show['anime']['slug'] showlist[slug] = utils.show() showlist[slug].update({ 'id': slug, 'title': show['anime']['title'], 'my_progress': show['episodes_watched'], 'my_status': show['status'], 'total': show['anime']['episode_count'], 'image': show['anime']['cover_image'], }) info = self._parse_info(show['anime']) infolist.append(info) self._emit_signal('show_info_changed', infolist) return showlist except urllib2.HTTPError, e: raise utils.APIError("Error getting list.")
def fetch_list(self): """Queries the full list from the remote server. Returns the list if successful, False otherwise.""" self.check_credentials() self.msg.info(self.name, 'Downloading list...') try: # Get an XML list from MyAnimeList API data = self._request( "https://hummingbirdv1.p.mashape.com/users/%s/library?%s" % (self.username, urllib.urlencode({'auth_token': self.auth})) ) shows = json.load(data) showlist = dict() infolist = list() for show in shows: slug = show['anime']['slug'] showlist[slug] = utils.show() showlist[slug].update({ 'id': slug, 'title': show['anime']['title'], 'my_progress': show['episodes_watched'], 'my_status': show['status'], 'total': show['anime']['episode_count'], 'image': show['anime']['cover_image'], }) info = utils.show() info.update({ 'id': slug, 'title': show['anime']['title'], 'image': show['anime']['cover_image'], 'url': show['anime']['url'], 'extra': [ ('Alternate title', show['anime']['alternate_title']), ('Show type', show['anime']['show_type']), ('Synopsis', show['anime']['synopsis']), ('Status', show['anime']['status']), ] }) infolist.append(info) self._emit_signal('show_info_changed', infolist) return showlist except urllib2.HTTPError, e: raise utils.APIError("Error getting list.")
def search(self, criteria): """Searches MyAnimeList database for the queried show""" self.msg.info(self.name, "Searching for %s..." % criteria) # Send the urlencoded query to the search API query = self._urlencode({'q': criteria}) data = self._request_gzip(self.url + self.mediatype + "/search.xml?" + query) # Load the results into XML try: root = ET.ElementTree().parse(data, parser=self._make_parser()) except (ET.ParseError, IOError): return [] # Use the correct tag name for episodes if self.mediatype == 'manga': episodes_str = 'chapters' else: episodes_str = 'episodes' # Since the MAL API returns the status as a string, and # we handle statuses as integers, we need to convert them if self.mediatype == 'anime': status_translate = {'Currently Airing': 1, 'Finished Airing': 2, 'Not yet aired': 3} elif self.mediatype == 'manga': status_translate = {'Publishing': 1, 'Finished': 2} entries = list() for child in root.iter('entry'): show = utils.show() showid = int(child.find('id').text) show.update({ 'id': showid, 'title': child.find('title').text, 'type': child.find('type').text, 'status': status_translate[child.find('status').text], # TODO : This should return an int! 'total': int(child.find(episodes_str).text), 'image': child.find('image').text, 'url': "http://myanimelist.net/anime/%d" % showid, 'extra': [ ('English', child.find('english').text), ('Synonyms', child.find('synonyms').text), ('Synopsis', self._translate_synopsis(child.find('synopsis').text)), (episodes_str.title(), child.find(episodes_str).text), ('Type', child.find('type').text), ('Score', child.find('score').text), ('Status', child.find('status').text), ('Start date', child.find('start_date').text), ('End date', child.find('end_date').text), ] }) entries.append(show) self._emit_signal('show_info_changed', entries) return entries
def _parse_info(self, show): info = utils.show() info.update({ 'id': show['slug'], 'title': show['title'], 'image': show['cover_image'], 'url': show['url'], 'extra': [ ('Alternate title', show['alternate_title']), ('Show type', show['show_type']), ('Synopsis', show['synopsis']), ('Status', show['status']), ] }) return info
def fetch_list(self): self.check_credentials() self.msg.info(self.name, 'Downloading list...') # Get a JSON list from API response = self.opener.open("http://melative.com/api/library.json?user={0}&context_type={1}".format(self.username, self.mediatype)) data = json.load(response) # Load data from the JSON stream into a parsed dictionary statuses = self.media_info()['statuses_dict'] itemlist = dict() for record in data['library']: entity = record['entity'] segment = record['segment'] itemid = int(entity['id']) # use appropiate number for the show state _status = 0 for k, v in statuses.items(): if v.lower() == record['state']: _status = k # use show length if available try: _total = int(entity['length']) except TypeError: _total = 0 # use show progress if needed if self.mediatypes[self.mediatype]['has_progress']: _progress = int(segment['name']) else: _progress = 0 show = utils.show() show['id'] = itemid show['title'] = entity['aliases'][0].encode('utf-8') show['my_status'] = _status show['my_score'] = int(record['rating'] or 0) show['my_progress'] =_progress show['total'] = _total show['image'] = entity['image_url'] show['status'] = 0 #placeholder itemlist[itemid] = show return itemlist
def _parse_info(self, item): info = utils.show() info.update({'id': item['id'], 'title': item['title'], 'image': item['image'], 'url': self._get_url(item['id']), 'extra': [ ('Original Name', item['original']), ('Released', item['released']), ('Languages', ','.join(item['languages'])), ('Original Language', ','.join(item['orig_lang'])), ('Platforms', ','.join(item['platforms'])), ('Aliases', item['aliases']), ('Length', item['length']), ('Description', item['description']), ('Links', item['links']), ] }) return info
def _parse_info(self, show): info = utils.show() alt_titles = [] if show['alternate_title'] is not None: alt_titles.append(show['alternate_title']) info.update({ 'id': show['slug'], 'title': show['title'], 'image': show['cover_image'], 'url': show['url'], 'aliases': alt_titles, 'extra': [ ('Alternate title', show['alternate_title']), ('Show type', show['show_type']), ('Synopsis', show['synopsis']), ('Status', show['status']), ] }) return info
def _parse_info(self, item): info = utils.show() info.update({ 'id': item['id'], 'title': item['title'], 'image': item['image'], 'url': self._get_url(item['id']), 'extra': [ ('Original Name', item['original']), ('Released', item['released']), ('Languages', ','.join(item['languages'])), ('Original Language', ','.join(item['orig_lang'])), ('Platforms', ','.join(item['platforms'])), ('Aliases', item['aliases']), ('Length', item['length']), ('Description', item['description']), ('Links', item['links']), ] }) return info
def _parse_anime(self, root): """Converts an XML anime list to a dictionary""" showlist = dict() for child in root.iter('anime'): show_id = int(child.find('series_animedb_id').text) if child.find('series_synonyms').text: aliases = child.find('series_synonyms').text.lstrip( '; ').split('; ') else: aliases = [] show = utils.show() show.update({ 'id': show_id, 'title': child.find('series_title').text, 'aliases': aliases, 'my_progress': int(child.find('my_watched_episodes').text), 'my_status': int(child.find('my_status').text), 'my_score': int(child.find('my_score').text), 'total': int(child.find('series_episodes').text), 'status': int(child.find('series_status').text), 'image': child.find('series_image').text, 'url': "http://myanimelist.net/anime/%d" % show_id, }) showlist[show_id] = show return showlist
def search(self, criteria): """Searches MyAnimeList database for the queried show""" self.msg.info(self.name, "Searching for %s..." % criteria) # Send the urlencoded query to the search API query = self._urlencode({"q": criteria}) data = self._request_gzip("http://myanimelist.net/api/" + self.mediatype + "/search.xml?" + query) # Load the results into XML try: root = ET.ElementTree().parse(data, parser=self._make_parser()) except ET.ParseError: self.msg.warn(self.name, "Problem parsing the search ...") return [] except IOError: self.msg.warn(self.name, "Problem during the search, response was not as expected. Try less words ...") return [] # Use the correct tag name for episodes if self.mediatype == "manga": episodes_str = "chapters" else: episodes_str = "episodes" # Since the MAL API returns the status as a string, and # we handle statuses as integers, we need to convert them if self.mediatype == "anime": status_translate = {"Currently Airing": 1, "Finished Airing": 2, "Not yet aired": 3} elif self.mediatype == "manga": status_translate = {"Publishing": 1, "Finished": 2} entries = list() for child in root.iter("entry"): show = utils.show() showid = int(child.find("id").text) show.update( { "id": showid, "title": child.find("title").text, "type": child.find("type").text, "status": status_translate[child.find("status").text], # TODO : This should return an int! "total": int(child.find(episodes_str).text), "image": child.find("image").text, "url": "http://myanimelist.net/anime/%d" % showid, "extra": [ ("English", child.find("english").text), ("Synonyms", child.find("synonyms").text), ("Synopsis", self._translate_synopsis(child.find("synopsis").text)), (episodes_str.title(), child.find(episodes_str).text), ("Type", child.find("type").text), ("Score", child.find("score").text), ("Status", child.find("status").text), ("Start date", child.find("start_date").text), ("End date", child.find("end_date").text), ], } ) entries.append(show) self._emit_signal("show_info_changed", entries) return entries
def fetch_list(self): """Queries the full list from the remote server. Returns the list if successful, False otherwise.""" self.check_credentials() # Retrieve VNs per pages page = 1 vns = dict() while True: self.msg.info(self.name, 'Downloading list... (%d)' % page) (name, data) = self._sendcmd('get %s basic (uid = 0)' % self.mediatype, { 'page': page, 'results': 25 }) # Something is wrong if we don't get a results response. if name != 'results': raise utils.APIFatal("Invalid response (%s)" % name) # Process list for item in data['items']: vnid = item['vn'] vns[vnid] = utils.show() vns[vnid]['id'] = vnid vns[vnid]['url'] = self._get_url(vnid) vns[vnid]['my_status'] = item.get('status') or item.get( 'priority') if not data['more']: # No more VNs, finish break page += 1 # Retrieve scores per pages page = 1 while True: self.msg.info(self.name, 'Downloading votes... (%d)' % page) (name, data) = self._sendcmd('get votelist basic (uid = 0)', { 'page': page, 'results': 25 }) # Something is wrong if we don't get a results response. if name != 'results': raise utils.APIFatal("Invalid response (%s)" % name) for item in data['items']: vnid = item['vn'] try: vns[vnid]['my_score'] = (item['vote'] / 10) except KeyError: # Ghost vote; ignore it pass if not data['more']: # No more VNs, finish break page += 1 return vns
# Use the correct tag name for episodes if self.mediatype == 'manga': episodes_str = 'chapters' else: episodes_str = 'episodes' # Since the MAL API returns the status as a string, and # we handle statuses as integers, we need to convert them if self.mediatype == 'anime': status_translate = {'Currently Airing': 1, 'Finished Airing': 2, 'Not yet aired': 3} elif self.mediatype == 'manga': status_translate = {'Publishing': 1, 'Finished': 2} entries = list() for child in root.iter('entry'): show = utils.show() showid = int(child.find('id').text) show.update({ 'id': showid, 'title': child.find('title').text, 'type': child.find('type').text, 'status': status_translate[child.find('status').text], # TODO : This should return an int! 'total': int(child.find(episodes_str).text), 'image': child.find('image').text, 'url': "http://myanimelist.net/anime/%d" % showid, 'extra': [ ('English', child.find('english').text), ('Synonyms', child.find('synonyms').text), ('Synopsis', self._translate_synopsis(child.find('synopsis').text)), (episodes_str.title(), child.find(episodes_str).text), ('Type', child.find('type').text),
def fetch_list(self): """Queries the full list from the remote server. Returns the list if successful, False otherwise.""" self.check_credentials() # Retrieve VNs per pages page = 1 vns = dict() while True: self.msg.info(self.name, 'Downloading list... (%d)' % page) (name, data) = self._sendcmd('get %s basic (uid = 0)' % self.mediatype, {'page': page, 'results': 25 }) # Something is wrong if we don't get a results response. if name != 'results': raise utils.APIFatal("Invalid response (%s)" % name) # Process list for item in data['items']: vnid = item['vn'] vns[vnid] = utils.show() vns[vnid]['id'] = vnid vns[vnid]['url'] = self._get_url(vnid) vns[vnid]['my_status'] = item.get('status') or item.get('priority') if not data['more']: # No more VNs, finish break page += 1 # Retrieve scores per pages page = 1 while True: self.msg.info(self.name, 'Downloading votes... (%d)' % page) (name, data) = self._sendcmd('get votelist basic (uid = 0)', {'page': page, 'results': 25 }) # Something is wrong if we don't get a results response. if name != 'results': raise utils.APIFatal("Invalid response (%s)" % name) for item in data['items']: vnid = item['vn'] try: vns[vnid]['my_score'] = (item['vote'] / 10.0) except KeyError: # Ghost vote; ignore it pass if not data['more']: # No more VNs, finish break page += 1 return vns
def search(self, criteria): """Searches MyAnimeList database for the queried show""" self.msg.info(self.name, "Searching for %s..." % criteria) # Send the urlencoded query to the search API query = self._urlencode({'q': criteria}) data = self._request_gzip("http://myanimelist.net/api/" + self.mediatype + "/search.xml?" + query) # Load the results into XML try: root = ET.ElementTree().parse(data, parser=self._make_parser()) except ET.ParseError: self.msg.warn(self.name, "Problem parsing the search ...") return [] except IOError: self.msg.warn( self.name, "Problem during the search, response was not as expected. Try less words ..." ) return [] # Use the correct tag name for episodes if self.mediatype == 'manga': episodes_str = 'chapters' else: episodes_str = 'episodes' # Since the MAL API returns the status as a string, and # we handle statuses as integers, we need to convert them if self.mediatype == 'anime': status_translate = { 'Currently Airing': 1, 'Finished Airing': 2, 'Not yet aired': 3 } elif self.mediatype == 'manga': status_translate = {'Publishing': 1, 'Finished': 2} entries = list() for child in root.iter('entry'): show = utils.show() showid = int(child.find('id').text) show.update({ 'id': showid, 'title': child.find('title').text, 'type': child.find('type').text, 'status': status_translate[child.find( 'status').text], # TODO : This should return an int! 'total': int(child.find(episodes_str).text), 'image': child.find('image').text, 'url': "http://myanimelist.net/anime/%d" % showid, 'extra': [ ('English', child.find('english').text), ('Synonyms', child.find('synonyms').text), ('Synopsis', self._translate_synopsis(child.find('synopsis').text)), (episodes_str.title(), child.find(episodes_str).text), ('Type', child.find('type').text), ('Score', child.find('score').text), ('Status', child.find('status').text), ('Start date', child.find('start_date').text), ('End date', child.find('end_date').text), ] }) entries.append(show) self._emit_signal('show_info_changed', entries) return entries