diff options
-rw-r--r-- | pyanidb/__init__.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/pyanidb/__init__.py b/pyanidb/__init__.py index bb8f234..57c44c2 100644 --- a/pyanidb/__init__.py +++ b/pyanidb/__init__.py @@ -48,6 +48,9 @@ class AniDBUnknownFile(AniDBError): class AniDBNotInMylist(AniDBError): pass +class AniDBUnknownAnime(AniDBError): + pass + class AniDB: def __init__(self, username, password, localport = 1234, server = ('api.anidb.info', 9000)): self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) @@ -173,3 +176,26 @@ class AniDB: self.auth() else: raise AniDBReplyError(code, text) + + def get_anime(self, aid = None, aname = None, amask = None, retry = False): + args = {} + if not aid == None: + args['aid'] = aid + elif not aname == None: + args['aname'] == aname + else: + raise TypeError('must set either aid or aname') + + args['amask'] = amask or '00'*7 + args['s'] = self.session + + while 1: + code, text, data = self.execute('ANIME', args, retry) + if code == 230: + return data[0] + elif code == 330: + raise AniDBUnknownAnime() + elif code in (501, 506): + self.auth() + else: + raise AniDBReplyError(code, text) |