for GROUP command")
parameters = {'gid': gid, 'gname': gname}
Command.__init__(self, 'GROUP', **parameters)
class GroupstatusCommand(Command):
def __init__(self, aid=None, status=None):
if not aid:
raise AniDBIncorrectParameterError("You must provide aid for GROUPSTATUS command")
parameters = {'aid': aid, 'status': status}
Command.__init__(self, 'GROUPSTATUS', **parameters)
class ProducerCommand(Command):
def __init__(self, pid=None, pname=None):
if not (pid or pname) or (pid and pname):
raise AniDBIncorrectParameterError("You must provide for PRODUCER command")
parameters = {'pid': pid, 'pname': pname}
Command.__init__(self, 'PRODUCER', **parameters)
def cached(self, intr, db):
pid = self.parameters['pid']
pname = self.parameters['pname']
codes = ('pid', 'name', 'shortname', 'othername', 'type', 'pic', 'url')
names = ','.join([code for code in codes if code != ''])
ruleholder = (pid and 'pid=%s' or '(name=%s OR shortname=%s OR othername=%s)')
rulevalues = (pid and [pid] or [pname, pname, pname])
rows = db.select('ptb', names, ruleholder + " AND status&8", *rulevalues)
if len(rows) > 1:
raise AniDBInternalError("It shouldn't be possible for database to return more than 1 line for PRODUCER cache")
elif not len(rows):
return None
else:
resp = ProducerResponse(self, None, '245', 'CACHED PRODUCER', [list(rows[0])])
resp.parse()
return resp
def cache(self, intr, db):
if self.resp.rescode != '245' or self.cached(intr, db):
return
codes = ('pid', 'name', 'shortname', 'othername', 'type', 'pic', 'url')
if len(db.select('ptb', 'pid', 'pid=%s', self.resp.datalines[0]['pid'])):
sets = 'status=status|15,' + ','.join([code + '=%s' for code in codes if code != ''])
values = [self.resp.datalines[0][code] for code in codes if code != ''] + [self.resp.datalines[0]['pid']]
db.update('ptb', sets, 'pid=%s', *values)
else:
names = 'status,' + ','.join([code for code in codes if code != ''])
valueholders = '0,' + ','.join(['%s' for code in codes if code != ''])
values = [self.resp.datalines[0][code] for code in codes if code != '']
db.insert('ptb', names, valueholders, *values)
class MyListCommand(Command):
def __init__(self, lid=None, fid=None, size=None, ed2k=None, aid=None, aname=None, gid=None, gname=None, epno=None):
if not (lid or fid or (size and ed2k) or (aid or aname)) or (lid and (fid or size or ed2k or aid or aname or gid or gname or epno)) or (fid and (lid or size or ed2k or aid or aname or gid or gname or epno)) or ((size and ed2k) and (lid or fid or aid or aname or gid or gname or epno)) or ((aid or aname) and (lid or fid or size or ed2k)) or (aid and aname) or (gid and gname):
raise AniDBIncorrectParameterError("You must provide for MYLIST command")
parameters = {'lid': lid, 'fid': fid, 'size': size, 'ed2k': ed2k, 'aid': aid, 'aname': aname, 'gid': gid, 'gname': gname, 'epno': epno}
Command.__init__(self, 'MYLIST', **parameters)
def cached(self, intr, db):
lid = self.parameters['lid']
fid = self.parameters['fid']
size = self.parameters['size']
ed2k = self.parameters['ed2k']
aid = self.parameters['aid']
aname = self.parameters['aname']
gid = self.parameters['gid']
gname = self.parameters['gname']
epno = self.parameters['epno']
names = ','.join([code for code in MylistResponse(None, None, None, None, []).codetail if code != ''])
if lid:
ruleholder = "lid=%s"
rulevalues = [lid]
elif fid or size or ed2k:
resp = intr.file(fid=fid, size=size, ed2k=ed2k)
if resp.rescode != '220':
resp = NoSuchMylistFileResponse(self, None, '321', 'NO SUCH ENTRY (FILE NOT FOUND)', [])
resp.parse()
return resp
fid = resp.datalines[0]['fid']
ruleholder = "fid=%s"
rulevalues = [fid]
else:
resp = intr.anime(aid=aid, aname=aname)
if resp.rescode != '230':
resp = NoSuchFileResponse(self, None, '321', 'NO SUCH ENTRY (ANIME NOT FOUND)', [])
resp.parse()
return resp
aid = resp.datalines[0]['aid']
resp = intr.group(gid=gid, gname=gname)
if resp.rescode != '250':
resp = NoSuchFileResponse(self, None, '321', 'NO SUCH ENTRY (GROUP NOT FOUND)', [])
resp.parse()
return resp
gid = resp.datalines[0]['gid']
resp = intr.episode(aid=aid, epno=epno)
if resp.rescode != '240':
resp = NoSuchFileResponse(self, None, '321', 'NO SUCH ENTRY (EPISODE NOT FOUND)', [])
resp.parse()
return resp
eid = resp.datalines[0]['eid']
ruleholder = "aid=%s AND eid=%s AND gid=%s"
rulevalues = [aid, eid, gid]
rows = db.select('ltb', names, ruleholder + " AND status&8", *rulevalues)
if len(rows) > 1:
# resp=MultipleFilesFoundResponse(self,None,'322','CACHED MULTIPLE FILES FOUND',/*get fids from rows, not gonna do this as you haven't got a real cache out of these..*/)
return None
elif not len(rows):
return None
else:
resp = MylistResponse(self, None, '221', 'CACHED MYLIST', [list(rows[0])])
resp.parse()
return resp
def cache(self, intr, db):
if self.resp.rescode != '221' or self.cached(intr, db):
return
codes = MylistResponse(None, None, None, None, []).codetail
if len(db.select('ltb', 'lid', 'lid=%s', self.resp.datalines[0]['lid'])):
sets = 'status=status|15,' + ','.join([code + '=%s' for code in codes if code != ''])
values = [self.resp.datalines[0][code] for code in codes if code != ''] + [self.resp.datalines[0]['lid']]
db.update('ltb', sets, 'lid=%s', *values)
else:
names = 'status,' + ','.join([code for code in codes if code != ''])
valueholders = '15,' + ','.join(['%s' for code in codes if code != ''])
values = [self.resp.datalines[0][code] for code in codes if code != '']
db.insert('ltb', names, valueholders, *values)
class MyListAddCommand(Command):
def __init__(self, lid=None, fid=None, size=None, ed2k=None, aid=None, aname=None, gid=None, gname=None, epno=None, edit=None, state=None, viewed=None, source=None, storage=None, other=None):
if not (lid or fid or (size and ed2k) or ((aid or aname) and (gid or gname))) or (lid and (fid or size or ed2k or aid or aname or gid or gname or epno)) or (fid and (lid or size or ed2k or aid or aname or gid or gname or epno)) or ((size and ed2k) and (lid or fid or aid or aname or gid or gname or epno)) or (((aid or aname) and (gid or gname)) and (lid or fid or size or ed2k)) or (aid and aname) or (gid and gname) or (lid and not edit):
raise AniDBIncorrectParameterError("You must provide for MYLISTADD command")
parameters = {'lid': lid, 'fid': fid, 'size': size, 'ed2k': ed2k, 'aid': aid, 'aname': aname, 'gid': gid, 'gname': gname, 'epno': epno, 'edit': edit, 'state': state, 'viewed': viewed, 'source': source, 'storage': storage, 'other': other}
Command.__init__(self, 'MYLISTADD', **parameters)
class MyListDelCommand(Command):
def __init__(self, lid=None, fid=None, aid=None, aname=None, gid=None, gname=None, epno=None):
if not (lid or fid or ((aid or aname) and (gid or gname) and epno)) or (lid and (fid or aid or aname or gid or gname or epno)) or (fid and (lid or aid or aname or gid or gname or epno)) or (((aid or aname) and (gid or gname) and epno) and (lid or fid)) or (aid and aname) or (gid and gname):
raise AniDBIncorrectParameterError("You must provide for MYLISTDEL command")
parameters = {'lid': lid, 'fid': fid, 'aid': aid, 'aname': aname, 'gid': gid, 'gname': gname, 'epno': epno}
Command.__init__(self, 'MYLISTDEL', **parameters)
class MyListStatsCommand(Command):
def __init__(self):
Command.__init__(self, 'MYLISTSTATS')
class VoteCommand(Command):
def __init__(self, type, id=None, name=None, value=None, epno=None):
if not (id or name) or (id and name):
raise AniDBIncorrectParameterError("You must provide <(id|name)> for VOTE command")
parameters = {'type': type, 'id': id, 'name': name, 'value': value, 'epno': epno}
Command.__init__(self, 'VOTE', **parameters)
class RandomAnimeCommand(Command):
def __init__(self, type):
parameters = {'type': type}
Command.__init__(self, 'RANDOMANIME', **parameters)
class PingCommand(Command):
def __init__(self):
Command.__init__(self, 'PING')
# second run
class EncryptCommand(Command):
def __init__(self, user, apipassword, type):
self.apipassword = apipassword
parameters = {'user': user.lower(), 'type': type}
Command.__init__(self, 'ENCRYPT', **parameters)
class EncodingCommand(Command):
def __init__(self, name):
parameters = {'name': type}
Command.__init__(self, 'ENCODING', **parameters)
class SendMsgCommand(Command):
def __init__(self, to, title, body):
if len(title) > 50 or len(body) > 900:
raise AniDBIncorrectParameterError("Title must not be longer than 50 chars and body must not be longer than 900 chars for SENDMSG command")
parameters = {'to': to.lower(), 'title': title, 'body': body}
Command.__init__(self, 'SENDMSG', **parameters)
class UserCommand(Command):
def __init__(self, user):
parameters = {'user': user}
Command.__init__(self, 'USER', **parameters)
class UptimeCommand(Command):
def __init__(self):
Command.__init__(self, 'UPTIME')
class VersionCommand(Command):
def __init__(self):
Command.__init__(self, 'VERSION')