def post(self, anonymous): if options.using_xsrf: self.check_xsrf_cookie() values_map = {} url = self.get_argument("url", None) values_map['url'] = url if url else '' btfile = self.request.files.get("btfile") btfile = btfile[0] if btfile else None title = self.get_argument("title", None) values_map['title'] = title if title else '' tags = self.get_argument("tags", "") values_map['tags'] = tags if tags else '' anonymous = True if anonymous else False render_path = "add_task_anonymous.html" if anonymous else "add_task.html" email = self.current_user['email'] verifycode = self.get_argument("verifycode", None) verifykey = self.get_cookie("verifykey") if anonymous and not self.has_permission("add_anonymous_task"): raise HTTPError(403, "You might not have permission to add anonymous task.") elif not anonymous and not self.has_permission("add_task"): raise HTTPError(403, "You might not have permission to add task.") elif self.user_manager.get_add_task_limit(self.current_user["email"]) <= 0: raise HTTPError(403, "You had reach the limit of adding tasks.") if not url and not btfile: self.render(render_path, message=u"任务下载地址不能为空!", timestamp=_now(), values=values_map) return if btfile and len(btfile['body']) > 500*1024: self.render(render_path, message=u"种子文件过大!", timestamp=_now(), values=values_map) return if tags: tags = set([x.strip() for x in _split_re.split(tags)]) result, task = yield gen.Task(self.call_subprocess, partial( self.task_manager.add_task, btfile or url, title, tags, email, anonymous, self.has_permission("need_miaoxia"), verifycode, verifykey )) if result == 1: self.user_manager.incr_add_task_limit(self.current_user["email"]) if task: self.finish("""<script> parent.$('#fancybox-content').css({height: "350px"}); parent.$.fancybox.resize(); location='/get_lixian_url?task_id=%d' </script>""" % task.id) else: self.finish("<script>top.location='/'</script>") else: if anonymous: self.render("add_task_anonymous.html", message=add_task_info_map.get(result, u"未知错误"), timestamp=_now(), values=values_map) else: self.render("add_task.html", message=add_task_info_map.get(result, u"未知错误"), timestamp=_now(), values=values_map)
def add_task_with_dict(self, url, info, verifycode=None, verifykey=None): params = dict( callback = "ret_task", uid = self.uid, cid = info['cid'], gcid = info['gcid'], size = info['size'], goldbean = 0, silverbean = 0, t = info['title'], url = url, type = 0, o_page = "task", o_taskid = 0, class_id = 0, database = "undefined", time = "Wed May 30 2012 14:22:01 GMT 0800 (CST)", noCacheIE = _now(), verify_code = verifycode ) DEBUG(pformat(params)) if verifycode and verifykey: self.session.cookies = self.update_cookie(self.session.cookies, 'VERIFY_KEY', verifykey) # Thank @torta https://github.com/iambus/xunlei-lixian/pull/380 # userid = '0' * randint(0, 3000) + str(int(self.session.cookies['userid'])) # self.session.cookies = self.update_cookie(self.session.cookies, 'userid', userid) DEBUG(pformat(self.session.cookies)) r = self.session.get(self.TASK_COMMIT_URL, params=params) r.raise_for_status() DEBUG(pformat(r.content)) if "ret_task" in r.content: if "'-11','-11'" in r.content: return -6 if "'-12','-12'" in r.content: return -7 return True return False
def bt_task_check(self, url): r = self.session.get(self.QUERY_URL, params={ "callback": "queryUrl", "u": url, "random": self._random, "tcache": _now()}) r.raise_for_status() #queryUrl(flag,infohash,fsize,bt_title,is_full,subtitle,subformatsize,size_list,valid_list,file_icon,findex,random) function, args = parser_js_function_call(r.content) DEBUG(pformat(args)) if len(args) < 12: return {} if not args[2]: return {} result = dict( flag = args[0], cid = args[1], size = args[2], title = title_fix(args[3]), is_full = args[4], random = args[11]) filelist = [] for subtitle, subformatsize, size, valid, file_icon, findex in zip(*args[5:11]): tmp_file = dict( title = subtitle, formatsize = subformatsize, size=size, file_icon = file_icon, ext = "", index = findex, valid = int(valid), ) filelist.append(tmp_file) result['filelist'] = filelist return result
def add_task_with_dict(self, url, info, verifycode=None, verifykey=None): params = dict(callback="ret_task", uid=self.uid, cid=info['cid'], gcid=info['gcid'], size=info['size'], goldbean=0, silverbean=0, t=info['title'], url=url, type=0, o_page="task", o_taskid=0, class_id=0, database="undefined", time="Wed May 30 2012 14:22:01 GMT 0800 (CST)", noCacheIE=_now(), verify_code=verifycode) DEBUG(pformat(params)) if verifycode and verifykey: self.session.cookies = self.update_cookie(self.session.cookies, 'VERIFY_KEY', verifykey) # Thank @torta https://github.com/iambus/xunlei-lixian/pull/380 # userid = '0' * randint(0, 3000) + str(int(self.session.cookies['userid'])) # self.session.cookies = self.update_cookie(self.session.cookies, 'userid', userid) DEBUG(pformat(self.session.cookies)) r = self.session.get(self.TASK_COMMIT_URL, params=params) r.raise_for_status() DEBUG(pformat(r.content)) if "ret_task" in r.content: if "'-11','-11'" in r.content: return -6 if "'-12','-12'" in r.content: return -7 return True return False
def get_vip_info(self): params = {"cachetime": _now(), "callback": "jsonp1234567890"} r = self.session.get(self.VIP_INFO_URL, params=params) r.raise_for_status() function, args = parser_js_function_call(r.content) DEBUG(pformat(args)) assert args return args[0]
def delay_task(self, task_ids): tmp_ids = [str(x) + "_1" for x in task_ids] r = self.session.get(self.TASK_DELAY_URL % dict(ids=",".join(tmp_ids), cachetime=_now())) r.raise_for_status() function, args = parser_js_function_call(r.content) DEBUG(pformat(args)) assert args if args and args[0].get("result") == 1: return True return False
def get_vip_info(self): params = { "cachetime": _now(), "callback": "jsonp1234567890" } r = self.session.get(self.VIP_INFO_URL, params=params) r.raise_for_status() function, args = parser_js_function_call(r.content) DEBUG(pformat(args)) assert args return args[0]
def task_pause(self, task_ids): r = self.session.get(self.TASK_PAUSE_URL, params = { "tid": ",".join(map(str, task_ids)), "uid": self.uid, "noCacheIE": _now() }) r.raise_for_status() DEBUG(pformat(r.content)) if "pause_task_resp" in r.content: return True return False
def webfilemail_url_analysis(self, url): params = { "action": "webfilemail_url_analysis", "url": url, "cachetime": _now(), } r = self.session.get(self.WEBFILEMAIL_INTERFACE_URL, params=params) r.raise_for_status() function, args = parser_js_function_call(r.content) DEBUG(pformat(args)) assert args return args[0]
def delay_task(self, task_ids): tmp_ids = [str(x)+"_1" for x in task_ids] r = self.session.get(self.TASK_DELAY_URL % dict( ids = ",".join(tmp_ids), cachetime = _now())) r.raise_for_status() function, args = parser_js_function_call(r.content) DEBUG(pformat(args)) assert args if args and args[0].get("result") == 1: return True return False
def get_wait_time(self, task_id, key=None): params = dict(callback="download_check_respo", t=_now(), taskid=task_id) if key: params["key"] = key r = self.session.get(self.GET_WAIT_TIME_URL, params=params) r.raise_for_status() function, args = parser_js_function_call(r.content) DEBUG(pformat(args)) assert args return args[0] if args else {}
def task_pause(self, task_ids): r = self.session.get(self.TASK_PAUSE_URL, params={ "tid": ",".join(map(str, task_ids)), "uid": self.uid, "noCacheIE": _now() }) r.raise_for_status() DEBUG(pformat(r.content)) if "pause_task_resp" in r.content: return True return False
def get_wait_time(self, task_id, key=None): params = dict( callback = "download_check_respo", t = _now(), taskid = task_id) if key: params["key"] = key r = self.session.get(self.GET_WAIT_TIME_URL, params=params) r.raise_for_status() function, args = parser_js_function_call(r.content) DEBUG(pformat(args)) assert args return args[0] if args else {}
def _get_verifycode(self, username): r = self.session.get(self.CHECK_URL % {"username": username, "cachetime": _now()}) r.raise_for_status() #DEBUG(pformat(r.content)) verifycode_tmp = r.cookies['check_result'].split(":", 1) assert 2 >= len(verifycode_tmp) > 0, verifycode_tmp if verifycode_tmp[0] == '0': return verifycode_tmp[1] return None
def vod_get_list_pic(self, gcids): params = { "callback": "jsonp1234567890", "t": _now(), "ids": "", # urlhash "gcid": ",".join(gcids), "rate": 0 } r = self.session.get(self.VOD_GET_LIST_PIC, params=params) r.raise_for_status() function, args = parser_js_function_call(r.content) DEBUG(pformat(args)) assert args return args[0]
def delete_task(self, task_ids): r = self.session.post(self.TASK_DELETE_URL, params = { "type": "0", "t": _now()} , data = { "databases": "0", "taskids": ",".join(map(str, task_ids))}) r.raise_for_status() function, args = parser_js_function_call(r.content) DEBUG(pformat(args)) assert args if args and args[0].get("result") == 1: return True return False
def vod_get_process(self, url_list): params = { "callback": "jsonp1234567890", "t": _now(), "url_list": "####".join(url_list), "id_list": "####".join(["list_bt_%d" % x for x in range(len(url_list))]), "palform": 0, } r = self.session.get(self.VOD_GET_PROCESS, params=params) r.raise_for_status() function, args = parser_js_function_call(r.content) DEBUG(pformat(args)) assert args return args[0]
def _get_showtask(self, pagenum, st): self.session.cookies["pagenum"] = str(pagenum) r = self.session.get(self.SHOWTASK_UNFRSH_URL, params={ "callback": "json1234567890", "t": _now(), "type_id": st, "page": 1, "tasknum": pagenum, "p": 1, "interfrom": "task"}) r.raise_for_status() function, args = parser_js_function_call(r.content) DEBUG(pformat(args)) assert args return args[0] if args else {}
def _get_verifycode(self, username): r = self.session.get(self.CHECK_URL % { "username": username, "cachetime": _now() }) r.raise_for_status() #DEBUG(pformat(r.content)) verifycode_tmp = r.cookies['check_result'].split(":", 1) assert 2 >= len(verifycode_tmp) > 0, verifycode_tmp if verifycode_tmp[0] == '0': return verifycode_tmp[1] return None
def vod_get_play_url(self, url, bindex=-1): params = { "callback": "jsonp1234567890", "t": _now(), "check": 0, "url": url, "format": 225536, #225536:g, 282880:p "bindex": bindex, "isipad": 0, } r = self.session.get(self.VOD_GET_PLAY_URL, params=params, headers={'referer': 'http://222.141.53.5/iplay.html'}) r.raise_for_status() function, args = parser_js_function_call(r.content) DEBUG(pformat(args)) assert args return args[0]
def _get_showtask(self, pagenum, st): self.session.cookies["pagenum"] = str(pagenum) r = self.session.get(self.SHOWTASK_UNFRSH_URL, params={ "callback": "json1234567890", "t": _now(), "type_id": st, "page": 1, "tasknum": pagenum, "p": 1, "interfrom": "task" }) r.raise_for_status() function, args = parser_js_function_call(r.content) DEBUG(pformat(args)) assert args return args[0] if args else {}
def vod_get_bt_pic(self, cid, bindex=[]): """ get gcid and shotcut of movice of bt task * max length of bindex is 18 """ params = { "jsonp": "jsonp1234567890", "t": _now(), "info_hash": cid, "req_list": "/".join(map(str, bindex)), } r = self.session.get(self.VOD_GET_BT_PIC % params) r.raise_for_status() function, args = parser_js_function_call(r.content) DEBUG(pformat(args)) assert args return args[0].get("resp", {})
def delete_task(self, task_ids): r = self.session.post(self.TASK_DELETE_URL, params={ "type": "0", "t": _now() }, data={ "databases": "0", "taskids": ",".join(map(str, task_ids)) }) r.raise_for_status() function, args = parser_js_function_call(r.content) DEBUG(pformat(args)) assert args if args and args[0].get("result") == 1: return True return False
def vod_get_bt_pic(self, cid, bindex=[]): """ get gcid and shotcut of movice of bt task * max length of bindex is 18 """ params = { "jsonp" : "jsonp1234567890", "t" : _now(), "info_hash" : cid, "req_list" : "/".join(map(str, bindex)), } r = self.session.get(self.VOD_GET_BT_PIC % params) r.raise_for_status() function, args = parser_js_function_call(r.content) DEBUG(pformat(args)) assert args return args[0].get("resp", {})
def get_free_url(self, nm_list=[], bt_list=[]): #info = self.get_wait_time(task_id) #if info.get("result") != 0: # return {} info = {} params = dict(key=info.get("key", ""), list=",".join((str(x) for x in nm_list + bt_list)), nm_list=",".join((str(x) for x in nm_list)), bt_list=",".join((str(x) for x in bt_list)), uid=self.uid, t=_now()) r = self.session.get(self.GET_FREE_URL, params=params) r.raise_for_status() function, args = parser_js_function_call(r.content) DEBUG(pformat(args)) assert args return args[0] if args else {}
def _get_bt_list(self, tid, cid): self.session.cookies["pagenum"] = str(2000) r = self.session.get(self.FILL_BT_LIST, params=dict(callback="fill_bt_list", tid=tid, infoid=cid, g_net=1, p=1, uid=self.uid, noCacheIE=_now())) r.raise_for_status() function, args = parser_js_function_call(r.content) DEBUG(pformat(args)) if not args: return {} if isinstance(args[0], basestring): raise LiXianAPIException, args[0] return args[0].get("Result", {})
def _get_bt_list(self, tid, cid): self.session.cookies["pagenum"] = str(2000) r = self.session.get(self.FILL_BT_LIST, params=dict( callback="fill_bt_list", tid = tid, infoid = cid, g_net = 1, p = 1, uid = self.uid, noCacheIE = _now())) r.raise_for_status() function, args = parser_js_function_call(r.content) DEBUG(pformat(args)) if not args: return {} if isinstance(args[0], basestring): raise LiXianAPIException, args[0] return args[0].get("Result", {})
def get_free_url(self, nm_list=[], bt_list=[]): #info = self.get_wait_time(task_id) #if info.get("result") != 0: # return {} info = {} params = dict( key=info.get("key", ""), list=",".join((str(x) for x in nm_list+bt_list)), nm_list=",".join((str(x) for x in nm_list)), bt_list=",".join((str(x) for x in bt_list)), uid=self.uid, t=_now()) r = self.session.get(self.GET_FREE_URL, params=params) r.raise_for_status() function, args = parser_js_function_call(r.content) DEBUG(pformat(args)) assert args return args[0] if args else {}
def get(self, anonymous): render_path = "add_task_anonymous.html" if anonymous else "add_task.html" if not self.current_user: message = "Please login first." elif anonymous and not self.has_permission("add_anonymous_task"): message = u"您没有添加任务的权限。" elif not anonymous and not self.has_permission("add_task"): message = u"您没有发布资源的权限。" elif self.user_manager.get_add_task_limit(self.current_user["email"]) <= 0: message = u"您今天添加的任务太多了!请重新登录以激活配额或联系管理员。" else: message = "" values_map = { 'url' : '', 'title' : '', 'tags' : '', } self.render(render_path, message=message, timestamp=_now(), values=values_map)
def vod_get_play_url(self, url, bindex=-1): params = { "callback": "jsonp1234567890", "t": _now(), "check": 0, "url": url, "format": 225536, #225536:g, 282880:p "bindex": bindex, "isipad": 0, } r = self.session.get( self.VOD_GET_PLAY_URL, params=params, headers={'referer': 'http://222.141.53.5/iplay.html'}) r.raise_for_status() function, args = parser_js_function_call(r.content) DEBUG(pformat(args)) assert args return args[0]
def task_check(self, url): r = self.session.get(self.TASK_CHECK_URL, params={ "callback": "queryCid", "url": url, "random": self._random, "tcache": _now()}) r.raise_for_status() #queryCid(cid,gcid,file_size,avail_space,tname,goldbean_need,silverbean_need,is_full,random) function, args = parser_js_function_call(r.content) DEBUG(pformat(args)) if len(args) < 8: return {} result = dict( cid = args[0], gcid = args[1], size = args[2], title = title_fix(args[4]), goldbean_need = args[5], silverbean_need = args[6], is_full = args[7], random = args[8]) return result
def get(self, anonymous): render_path = "add_task_anonymous.html" if anonymous else "add_task.html" if not self.current_user: message = "Please login first." elif anonymous and not self.has_permission("add_anonymous_task"): message = u"您没有添加任务的权限。" elif not anonymous and not self.has_permission("add_task"): message = u"您没有发布资源的权限。" elif self.user_manager.get_add_task_limit( self.current_user["email"]) <= 0: message = u"您今天添加的任务太多了!请重新登录以激活配额或联系管理员。" else: message = "" values_map = { 'url': '', 'title': '', 'tags': '', } self.render(render_path, message=message, timestamp=_now(), values=values_map)
def task_check(self, url): r = self.session.get(self.TASK_CHECK_URL, params={ "callback": "queryCid", "url": url, "random": self._random, "tcache": _now() }) r.raise_for_status() #queryCid(cid,gcid,file_size,avail_space,tname,goldbean_need,silverbean_need,is_full,random) function, args = parser_js_function_call(r.content) DEBUG(pformat(args)) if len(args) < 8: return {} result = dict(cid=args[0], gcid=args[1], size=args[2], title=title_fix(args[4]), goldbean_need=args[5], silverbean_need=args[6], is_full=args[7], random=args[8]) return result
def get_task_process(self, nm_list=[], bt_list=[], with_summary=False): params = dict( callback="rebuild", list=",".join((str(x) for x in nm_list + bt_list)), nm_list=",".join((str(x) for x in nm_list)), bt_list=",".join((str(x) for x in bt_list)), uid=self.uid, noCacheIE=_now(), ) r = self.session.get(self.GET_TASK_PROCESS, params=params) r.raise_for_status() function, args = parser_js_function_call(r.content) DEBUG(pformat(args)) assert args args = args[0] result = [] for task in args.get("Process", {}).get("Record", []) if args else []: status = None if task.get('fsize', u'0B') == u'0B': # it's a task own by other account status = 'failed' tmp = dict( task_id=int(task['tid']), cid=task.get('cid', None), status=status or self.d_status.get(int(task['download_status']), "waiting"), process=task['percent'], leave_time=task['leave_time'], speed=int(task['speed']), lixian_url=task.get('lixian_url', None), ) result.append(tmp) if with_summary: return result, args.get("Process", {}).get("Task", {}) else: return result
def bt_task_check(self, url): r = self.session.get(self.QUERY_URL, params={ "callback": "queryUrl", "u": url, "random": self._random, "tcache": _now() }) r.raise_for_status() #queryUrl(flag,infohash,fsize,bt_title,is_full,subtitle,subformatsize,size_list,valid_list,file_icon,findex,random) function, args = parser_js_function_call(r.content) DEBUG(pformat(args)) if len(args) < 12: return {} if not args[2]: return {} result = dict(flag=args[0], cid=args[1], size=args[2], title=title_fix(args[3]), is_full=args[4], random=args[11]) filelist = [] for subtitle, subformatsize, size, valid, file_icon, findex in zip( *args[5:11]): tmp_file = dict( title=subtitle, formatsize=subformatsize, size=size, file_icon=file_icon, ext="", index=findex, valid=int(valid), ) filelist.append(tmp_file) result['filelist'] = filelist return result
def get_task_process(self, nm_list=[], bt_list=[], with_summary=False): params = dict( callback="rebuild", list=",".join((str(x) for x in nm_list+bt_list)), nm_list=",".join((str(x) for x in nm_list)), bt_list=",".join((str(x) for x in bt_list)), uid=self.uid, noCacheIE=_now(), ) r = self.session.get(self.GET_TASK_PROCESS, params=params) r.raise_for_status() function, args = parser_js_function_call(r.content) DEBUG(pformat(args)) assert args args = args[0] result = [] for task in args.get("Process", {}).get("Record", []) if args else []: status = None if task.get('fsize', u'0B') == u'0B': # it's a task own by other account status = 'failed' tmp = dict( task_id = int(task['tid']), cid = task.get('cid', None), status = status or self.d_status.get(int(task['download_status']), "waiting"), process = task['percent'], leave_time = task['leave_time'], speed = int(task['speed']), lixian_url = task.get('lixian_url', None), ) result.append(tmp) if with_summary: return result, args.get("Process", {}).get("Task", {}) else: return result
def post(self, anonymous): if options.using_xsrf: self.check_xsrf_cookie() values_map = {} url = self.get_argument("url", None) values_map['url'] = url if url else '' btfile = self.request.files.get("btfile") btfile = btfile[0] if btfile else None title = self.get_argument("title", None) values_map['title'] = title if title else '' tags = self.get_argument("tags", "") values_map['tags'] = tags if tags else '' anonymous = True if anonymous else False render_path = "add_task_anonymous.html" if anonymous else "add_task.html" email = self.current_user['email'] verifycode = self.get_argument("verifycode", None) verifykey = self.get_cookie("verifykey") if anonymous and not self.has_permission("add_anonymous_task"): raise HTTPError( 403, "You might not have permission to add anonymous task.") elif not anonymous and not self.has_permission("add_task"): raise HTTPError(403, "You might not have permission to add task.") elif self.user_manager.get_add_task_limit( self.current_user["email"]) <= 0: raise HTTPError(403, "You had reach the limit of adding tasks.") if not url and not btfile: self.render(render_path, message=u"任务下载地址不能为空!", timestamp=_now(), values=values_map) return if btfile and len(btfile['body']) > 500 * 1024: self.render(render_path, message=u"种子文件过大!", timestamp=_now(), values=values_map) return if tags: tags = set([x.strip() for x in _split_re.split(tags)]) result, task = yield gen.Task( self.call_subprocess, partial(self.task_manager.add_task, btfile or url, title, tags, email, anonymous, self.has_permission("need_miaoxia"), verifycode, verifykey)) if result == 1: self.user_manager.incr_add_task_limit(self.current_user["email"]) if task: self.finish("""<script> parent.$('#fancybox-content').css({height: "350px"}); parent.$.fancybox.resize(); location='/get_lixian_url?task_id=%d' </script>""" % task.id) else: self.finish("<script>top.location='/'</script>") else: if anonymous: self.render("add_task_anonymous.html", message=add_task_info_map.get(result, u"未知错误"), timestamp=_now(), values=values_map) else: self.render("add_task.html", message=add_task_info_map.get(result, u"未知错误"), timestamp=_now(), values=values_map)
def _random(self): return str(_now())+str(random()*(2000000-10)+10)
def get(self): verifycode_image_url = 'http://verify2.xunlei.com/image?t=MVA&cachetime=%s' % _now( ) r = yield gen.Task(self.call_subprocess, partial(get, verifycode_image_url)) verifycode_image = r.content verifykey = r.cookies['VERIFY_KEY'] self.set_header('Content-Type', 'image/jpeg') self.set_cookie('verifykey', verifykey, domain='.%s' % self.request.host, path='/') self.finish(verifycode_image)
def _random(self): return str(_now()) + str(random() * (2000000 - 10) + 10)
def verifycode(self): r = self.session.get(self.VERIFY_CODE % _now()) return r.content
def get(self): verifycode_image_url = 'http://verify2.xunlei.com/image?t=MVA&cachetime=%s' % _now() r = yield gen.Task(self.call_subprocess, partial(get, verifycode_image_url)) verifycode_image = r.content verifykey = r.cookies['VERIFY_KEY'] self.set_header('Content-Type', 'image/jpeg') self.set_cookie('verifykey', verifykey, domain='.%s' % self.request.host, path='/') self.finish(verifycode_image)