Ejemplo n.º 1
0
		def down_img(num,thumbimg,link,fsid,header,path):
			logger.debug(" %s is downloading"%str(fsid))
			f=open(thumbimg,"wb")
			img = fetch(link,{},fsid,header,path)
			f.write(img)
			f.close()
			return (num,thumbimg)
Ejemplo n.º 2
0
def index():
    url = PAN_INDEX
    header = {
        'Host': PAN_HOST,
        'Referer': DISK_HOME,
    }
    sign1 = ''
    sign3 = ''
    bdstoken = ''
    timestamp = ''
    xml = fetch(url, {}, utils.myname(), header).decode('utf-8')
    signmatch = re.search("yunData\.sign1\s*=\s*'([^']*)'", xml)
    if signmatch:
        sign1 = signmatch.group(1)
    logger.debug('sign1: %s ' % sign1)

    bdstokenmatch = re.search('MYBDSTOKEN\s*=\s*"([^"]*)"', xml)
    if bdstokenmatch:
        bdstoken = bdstokenmatch.group(1)
    logger.debug('bdstoken: %s ' % bdstoken)

    sign3match = re.search("yunData\.sign3\s*=\s*'([^']*)'", xml)
    if sign3match:
        sign3 = sign3match.group(1)
    logger.debug('sign3: %s ' % sign3)

    timestampmatch = re.search("yunData\.timestamp\s*=\s*'([^']*)'", xml)
    if timestampmatch:
        timestamp = timestampmatch.group(1)
    logger.debug('timestamp: %s ' % timestamp)

    return (bdstoken, sign1, sign3, timestamp)
Ejemplo n.º 3
0
 def down_img(num, thumbimg, link, fsid, header, path):
     logger.debug(" %s is downloading" % str(fsid))
     f = open(thumbimg, "wb")
     img = fetch(link, {}, fsid, header, path)
     f.write(img)
     f.close()
     return (num, thumbimg)
Ejemplo n.º 4
0
def list_task(bdstoken):
    url = CLOUD_DL + '?bdstoken=' +  bdstoken + \
    '&need_task_info=1&status=255&start=0&limit=100&method=list_task&app_id=250528&t=' + \
     utils.tt() + '&bdstoken=' +  bdstoken + '&channel=chunlei&clienttype=0&web=1&app_id=250528'
    xml = fetch(url, {}, utils.myname(), {})
    j = json.loads(xml.decode("utf-8"))

    return j
Ejemplo n.º 5
0
def query_task(bdstoken, taskid):
    url =  CLOUD_DL + "?bdstoken=" +  bdstoken + "&task_ids=" + \
    taskid + "&op_type=1&method=query_task&app_id=250528&t=" + utils.tt() + \
    "&bdstoken=" +  bdstoken + "&channel=chunlei&clienttype=0&web=1&app_id=250528"
    xml = fetch(url, {}, utils.myname(), {})
    j = json.loads(xml.decode("utf-8"))
    logger.debug("json: %s " % str(j))
    return (j, taskid)
Ejemplo n.º 6
0
def list_task(bdstoken):
	url = CLOUD_DL + '?bdstoken=' +  bdstoken + \
	'&need_task_info=1&status=255&start=0&limit=100&method=list_task&app_id=250528&t=' + \
	 utils.tt() + '&bdstoken=' +  bdstoken + '&channel=chunlei&clienttype=0&web=1&app_id=250528'
	xml = fetch(url,{},utils.myname(),{})
	j = json.loads(xml.decode("utf-8"))
	
	return j
Ejemplo n.º 7
0
def query_task(bdstoken,taskid):
	url =  CLOUD_DL + "?bdstoken=" +  bdstoken + "&task_ids=" + \
	taskid + "&op_type=1&method=query_task&app_id=250528&t=" + utils.tt() + \
	"&bdstoken=" +  bdstoken + "&channel=chunlei&clienttype=0&web=1&app_id=250528"
	xml = fetch(url,{},utils.myname(),{})
	j = json.loads(xml.decode("utf-8"))
	logger.debug("json: %s "% str(j))
	return (j,taskid)
Ejemplo n.º 8
0
def search_mag(s,dry=True):
	settings.DRY = dry
	header = {
	"host":"www.thepiratebay.se",
	"method":"GET",
	}
	url = "https://www.thepiratebay.se/s/?q=" + s + \
	"&p**n=on&category=0&page=0&orderby=99"
	xml = fetch(url,{},utils.myname(),header)
	
	return xml
Ejemplo n.º 9
0
def search_mag(s, dry=True):
    settings.DRY = dry
    header = {
        "host": "www.thepiratebay.se",
        "method": "GET",
    }
    url = "https://www.thepiratebay.se/s/?q=" + s + \
    "&p**n=on&category=0&page=0&orderby=99"
    xml = fetch(url, {}, utils.myname(), header)

    return xml
Ejemplo n.º 10
0
def login_check(username, token):
    header = {
        'Host': PASSPORT_HOST,
        'Referer': PAN_INDEX,
    }
    cbs = utils.cbs_token()
    url = PASSPORT_API + '/?loginhistory&token=' + token + \
    '&tpl=netdisk&apiver=v3&tt=' + utils.tt() + '&username='******'&isphone=false&callback=' + cbs
    xml = fetch(url, {}, utils.myname(), header)
    xml = utils.fix_json(xml)
    return xml
Ejemplo n.º 11
0
def move_file(bdstoken,filelist):
	header = {
	'Content-Type':'application/x-www-form-urlencoded',
	'Host':PAN_HOST,
	'Referer':DISK_HOME,
	}
	url = FILE_MANAGER + \
	'?channel=chunlei&clienttype=0&web=1&opera=move&bdstoken=' + \
	bdstoken + "&app_id=250528"
	post = {
	'filelist':filelist,
	}
	xml = fetch(url,post,utils.myname(),header)
	return xml
Ejemplo n.º 12
0
def move_file(bdstoken, filelist):
    header = {
        'Content-Type': 'application/x-www-form-urlencoded',
        'Host': PAN_HOST,
        'Referer': DISK_HOME,
    }
    url = FILE_MANAGER + \
    '?channel=chunlei&clienttype=0&web=1&opera=move&bdstoken=' + \
    bdstoken + "&app_id=250528"
    post = {
        'filelist': filelist,
    }
    xml = fetch(url, post, utils.myname(), header)
    return xml
Ejemplo n.º 13
0
def delete_file(bdstoken, filelist):
    header = {
        'Content-Type': 'application/x-www-form-urlencoded',
        'Host': PAN_HOST,
        'Referer': DISK_HOME,
    }
    url = FILE_MANAGER + \
    '?channel=chunlei&clienttype=0&web=1&opera=delete&bdstoken=' + \
    bdstoken + "&app_id=250528"
    post = {
        'filelist': filelist,
    }
    path = os.path.dirname(filelist.strip('["').strip('"]').split(',')[0])
    xml = fetch(url, post, utils.myname(), header, path)
    return xml
Ejemplo n.º 14
0
def delete_file(bdstoken,filelist):
	header = {
	'Content-Type':'application/x-www-form-urlencoded',
	'Host':PAN_HOST,
	'Referer':DISK_HOME,
	}
	url = FILE_MANAGER + \
	'?channel=chunlei&clienttype=0&web=1&opera=delete&bdstoken=' + \
	bdstoken + "&app_id=250528"
	post = {
	'filelist':filelist,
	}
	path = os.path.dirname(filelist.strip('["').strip('"]').split(',')[0])
	xml = fetch(url,post,utils.myname(),header,path)
	return xml
Ejemplo n.º 15
0
def get_token():
    header = {
        'Host': PASSPORT_HOST,
        'Referer': PAN_INDEX,
    }
    cbs = utils.cbs_token()
    login_init = utils.tt()
    url = PASSPORT_API + '/?getapi&tpl=netdisk&apiver=v3&tt='+ \
    login_init + '&class=login&logintype=basicLogin&callback=' + cbs
    logger.debug('url:: %s ' % url)
    xml = fetch(url, {}, utils.myname(), header)
    xml = utils.fix_json(xml.decode('utf-8'))
    token = json.loads(xml)['data']['token']
    logger.debug("token:%s" % token)

    return token
Ejemplo n.º 16
0
def get_dlink(tokens, fid, path, num):
    global counter
    settings.DRY = False
    logger.debug("file path: %s " % path)
    bdstoken, sign1, sign3, timestamp = tokens

    header = {
        'Host': PAN_HOST,
        'Referer': DISK_HOME,
    }
    data = {
        'sign': base64.b64encode(utils.tosign(sign3, sign1)).decode('utf-8'),
        'timestamp': timestamp,
        'fidlist': '[%s]' % fid,
        'type': 'dlink',
        'bdstoken': bdstoken,
        'channel': 'chunlei',
        'clienttype': 0,
        'web': 1,
        'app_id': '250528',
    }
    url = 'http://pan.baidu.com/api/download?' + urllib.parse.urlencode(data)

    xml = fetch(url, {}, fid + "_json", header, os.path.dirname(path))
    list_json = json.loads(xml.decode("utf-8"))

    if list_json['errno'] == 112 or list_json['errno'] == 113:

        if counter < 2:
            counter += 1
            tokens = auth.index()
            return get_dlink(tokens, fid, path, num)
        else:
            return (None, fid, num)

    elif list_json['errno'] == -1:
        #remove_invalid_file(path)

        return (None, fid, num)
    elif list_json['errno'] == 0:

        settings.DRY = True

        return (list_json['dlink'][0]['dlink'], fid, num)
    else:
        logger.info("Unknow Error, return none.")
        return (None, fid, num)
Ejemplo n.º 17
0
def get_dlink(tokens,fid,path,num):
	global counter
	settings.DRY = False
	logger.debug("file path: %s "%path)
	bdstoken,sign1,sign3,timestamp = tokens
	
	header = {
	'Host':PAN_HOST,
	'Referer':DISK_HOME,
	}
	data = {
		'sign':base64.b64encode(utils.tosign(sign3,sign1)).decode('utf-8'),
		'timestamp':timestamp,
		'fidlist':'[%s]'%fid,
		'type':'dlink',
		'bdstoken':bdstoken,
		'channel':'chunlei',
		'clienttype':0,
		'web':1,
		'app_id':'250528',
		}
	url = 'http://pan.baidu.com/api/download?' + urllib.parse.urlencode(data)
	
	xml = fetch(url,{},fid+"_json",header,os.path.dirname(path))
	list_json = json.loads(xml.decode("utf-8"))
	
	if list_json['errno'] == 112 or list_json['errno'] == 113 :
		
		if counter < 2:
			counter +=1
			tokens = auth.index()
			return get_dlink(tokens,fid,path,num)
		else:
			return (None,fid,num)
		
	elif list_json['errno'] == -1:
		#remove_invalid_file(path)
		
		return (None,fid,num)
	elif list_json['errno'] == 0:
		
		settings.DRY = True
	
		return (list_json['dlink'][0]['dlink'],fid,num)
	else:
		logger.info ("Unknow Error, return none.")
		return (None,fid,num)
Ejemplo n.º 18
0
def get_public_key(token):

    header = {
        'Host': PASSPORT_HOST,
        'Referer': PAN_INDEX,
    }
    cbs = utils.cbs_token()

    url = 'https://passport.baidu.com/v2/getpublickey?token=' + \
    token + '&tpl=netdisk&apiver=v3&tt=' + utils.tt() + '&callback=' + cbs
    xml = fetch(url, {}, utils.myname(), header).decode('utf-8')
    keystr = re.search("\(([^\)]*)\)",
                       xml).group(1).replace("'", '"').replace('\t', '')
    logger.debug("key str:%s" % keystr)
    keydict = eval(keystr)
    logger.debug("keydict:%s" % keydict)
    rsakey = keydict['key']
    pubkey = keydict['pubkey']
    logger.debug("rsakey:%s" % rsakey)
    logger.debug("pubkey:%s" % pubkey)
    return (rsakey, pubkey)
Ejemplo n.º 19
0
def list_path(path,num,dry,bdstoken):
	logger.info("Listing path %s."%path)
	settings.DRY = dry
	header = {
	'Host':PAN_HOST,
	'Referer':DISK_HOME,
	}
	t = utils.tt()
	t2 = str(int(t) + 2)
	if path:
		_path = urllib.parse.urlencode({"dir":path})
	else:
		_path = urllib.parse.urlencode({"dir":'/'})
	url = PAN_INDEX + '/api/list?channel=chunlei&clienttype=0&web=1&num=' + \
	str(num) + '&t=' + t + '&page=1&' + _path + \
	'&showempty=0&order=time&desc=1&_='+ t2 +  \
	 '&bdstoken=' + bdstoken + "&app_id=250528"
	xml = fetch(url,{},utils.myname(),header,path)

	list_json = json.loads(xml.decode("utf-8"))
	if list_json:
		return list_json
	else:	
		return None
Ejemplo n.º 20
0
def list_path(path, num, dry, bdstoken):
    logger.info("Listing path %s." % path)
    settings.DRY = dry
    header = {
        'Host': PAN_HOST,
        'Referer': DISK_HOME,
    }
    t = utils.tt()
    t2 = str(int(t) + 2)
    if path:
        _path = urllib.parse.urlencode({"dir": path})
    else:
        _path = urllib.parse.urlencode({"dir": '/'})
    url = PAN_INDEX + '/api/list?channel=chunlei&clienttype=0&web=1&num=' + \
    str(num) + '&t=' + t + '&page=1&' + _path + \
    '&showempty=0&order=time&desc=1&_='+ t2 +  \
     '&bdstoken=' + bdstoken + "&app_id=250528"
    xml = fetch(url, {}, utils.myname(), header, path)

    list_json = json.loads(xml.decode("utf-8"))
    if list_json:
        return list_json
    else:
        return None
Ejemplo n.º 21
0
	def download_vcodeimg(self,imgurl,vcodeimg):
		f=open(vcodeimg,"wb")
		fp = fetch(imgurl,{},"GetVcode")
		f.write(fp)
		f.close()
		return vcodeimg
Ejemplo n.º 22
0
def add_task(bdstoken, t_url, save_path, dia):
    header = {
        'Content-Type': 'application/x-www-form-urlencoded',
        'Host': PAN_HOST,
        'Referer': DISK_HOME,
    }
    url = CLOUD_DL + '?bdstoken=' + bdstoken + '&channel=chunlei&clienttype=0&web=1'
    post = {
        'method': 'add_task',
        'app_id': '250528',
        'source_url': t_url,
        'save_path': save_path,
        'type': '3',
    }
    xml = fetch(url, post, utils.myname(), header, save_path)
    j = json.loads(xml.decode("utf-8"))
    logger.debug("json: %s " % str(j))

    if 'error_code' in list(j.keys()):
        logger.info(j['error_msg'])
        if j['error_code'] != 36022:
            while 'vcode' in list(j.keys()):
                vcode = j['vcode']
                logger.info(vcode)
                imgurl = j['img']
                #f=open(vimg,"wb")
                #fp = fetch(imgurl,{},"Input Vcode")
                #f.write(fp)
                #f.close()
                #try:
                #	subprocess.Popen(['xdg-open', vimg])
                #except:
                #	print("please open file %s to check the vcode."%vimg)
                #mag = re.search('(&.*$)',t_url).group(1)
                #task_name = dict(urllib.parse.parse_qsl(mag))['dn']

                #logger.info("Please input vcode for task: %s ."%(task_name))
                vd = VcodeDialog(dia, imgurl)
                vd.new_url(imgurl)
                response = vd.run()
                print(response)
                if response == 22:
                    print("The OK button was clicked")
                    vf = vd.get_user_input()
                    vd.destroy()
                elif response == Gtk.ResponseType.DELETE_EVENT:
                    vd.destroy()
                #input("verification code # ").strip()

                add = {
                    'file_sha1': '',
                    'selected_idx': '1,2,3,4',
                    'task_from': '0',
                    't': utils.tt(),
                    'type': 4,
                    'input': vf,
                    'vcode': vcode,
                }
                print(add)
                post.update(add)
                xml = fetch(url, post, "TryWithVcode", header, save_path)
                j = json.loads(xml.decode("utf-8"))
                logger.debug("json: %s " % str(j))
                if 'error_code' in list(j.keys()):
                    logger.info(j['error_msg'])
            return j
        else:

            return j['error_msg']
    logger.debug("json: %s " % str(j))

    return j
Ejemplo n.º 23
0
def add_task(bdstoken,t_url,save_path,dia):
	header = {
	'Content-Type':'application/x-www-form-urlencoded',
	'Host':PAN_HOST,
	'Referer':DISK_HOME,
	}
	url = CLOUD_DL + '?bdstoken=' + bdstoken + '&channel=chunlei&clienttype=0&web=1'
	post = {
	'method':'add_task',
	'app_id':'250528',
	'source_url':t_url,
	'save_path':save_path,
	'type':'3',
	}
	xml = fetch(url,post,utils.myname(),header,save_path)
	j = json.loads(xml.decode("utf-8"))
	logger.debug("json: %s "% str(j))
	
	if 'error_code' in list(j.keys()):
		logger.info(j['error_msg'])
		if j['error_code'] != 36022 :
			while 'vcode' in list(j.keys()):
				vcode = j['vcode']
				logger.info(vcode)
				imgurl = j['img']
				#f=open(vimg,"wb")
				#fp = fetch(imgurl,{},"Input Vcode")
				#f.write(fp)
				#f.close()
				#try:
				#	subprocess.Popen(['xdg-open', vimg])
				#except:
				#	print("please open file %s to check the vcode."%vimg)
				#mag = re.search('(&.*$)',t_url).group(1)
				#task_name = dict(urllib.parse.parse_qsl(mag))['dn']

				#logger.info("Please input vcode for task: %s ."%(task_name))
				vd = VcodeDialog(dia,imgurl)
				vd.new_url(imgurl)
				response = vd.run()
				print(response)
				if response == 22:
					print("The OK button was clicked")
					vf = vd.get_user_input()
					vd.destroy()
				elif  response == Gtk.ResponseType.DELETE_EVENT:
					vd.destroy()
				#input("verification code # ").strip()
				
				add = {
				'file_sha1':'',
				'selected_idx':'1,2,3,4',
				'task_from':'0',
				't':utils.tt(),
				'type':4,
				'input':vf,
				'vcode':vcode,
				}
				print(add)
				post.update(add)
				xml = fetch(url,post,"TryWithVcode",header,save_path)
				j = json.loads(xml.decode("utf-8"))
				logger.debug("json: %s "% str(j))
				if 'error_code' in list(j.keys()):
					logger.info(j['error_msg'])
			return j
		else:
			
			return j['error_msg']
	logger.debug("json: %s "% str(j))

	return j