Skip to content

Commit

Permalink
libanilist: Parsing unknown statuses and types
Browse files Browse the repository at this point in the history
  • Loading branch information
z411 committed May 14, 2019
1 parent 6b1de66 commit a656757
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
17 changes: 12 additions & 5 deletions trackma/lib/libanilist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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']),
Expand Down Expand Up @@ -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'],
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions trackma/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a656757

Please sign in to comment.