From a656757ecdfd4f56cdf4d71ba922c7c35937ec1c Mon Sep 17 00:00:00 2001 From: z411 Date: Tue, 14 May 2019 06:07:40 -0400 Subject: [PATCH] libanilist: Parsing unknown statuses and types --- trackma/lib/libanilist.py | 17 ++++++++++++----- trackma/utils.py | 2 ++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/trackma/lib/libanilist.py b/trackma/lib/libanilist.py index c33526a7..5e412912 100644 --- a/trackma/lib/libanilist.py +++ b/trackma/lib/libanilist.py @@ -110,6 +110,7 @@ class libanilist(lib): 'NOVEL': utils.TYPE_OTHER, 'ONE_SHOT': utils.TYPE_OTHER, } + status_translate = { 'RELEASING': utils.STATUS_AIRING, 'FINISHED': utils.STATUS_FINISHED, @@ -288,8 +289,8 @@ def fetch_list(self): 'id': showid, 'title': media['title']['userPreferred'], 'aliases': self._get_aliases(media), - 'type': self.type_translate[media['format']], - 'status': self.status_translate[media['status']], + 'type': self._translate_type(media['format']), + 'status': self._translate_status(media['status']), 'my_progress': self._c(item['progress']), 'my_status': my_status, 'my_score': self._c(item['score']), @@ -448,8 +449,8 @@ def _parse_info(self, item): 'title': item['title']['userPreferred'], 'total': self._c(item[self.total_str]), 'aliases': self._get_aliases(item), - 'type': self.type_translate[item['format']], - 'status': self.status_translate[item['status']], + 'type': self._translate_type(item['format']), + 'status': self._translate_status(item['status']), 'image': item['coverImage']['large'], 'image_thumb': item['coverImage']['medium'], 'url': item['siteUrl'], @@ -465,7 +466,7 @@ def _parse_info(self, item): ('Synopsis', item.get('description')), ('Type', item.get('format')), ('Average score', item.get('averageScore')), - ('Status', self.status_translate[item['status']]), + ('Status', self._translate_status(item['status'])), ] }) return info @@ -479,6 +480,12 @@ def _get_aliases(self, item): return aliases + def _translate_type(self, orig_type): + return self.type_translate.get(orig_type, utils.TYPE_UNKNOWN) + + def _translate_status(self, orig_status): + return self.status_translate.get(orig_status, utils.STATUS_UNKNOWN) + def _dict2date(self, item): if not item: return None diff --git a/trackma/utils.py b/trackma/utils.py index d40d0c9c..1e15d4eb 100644 --- a/trackma/utils.py +++ b/trackma/utils.py @@ -30,12 +30,14 @@ LOGIN_PASSWD = 1 LOGIN_OAUTH = 2 +STATUS_UNKNOWN = 0 STATUS_AIRING = 1 STATUS_FINISHED = 2 STATUS_NOTYET = 3 STATUS_CANCELLED = 4 STATUS_OTHER = 100 +TYPE_UNKNOWN = 0 TYPE_TV = 1 TYPE_MOVIE = 2 TYPE_OVA = 3