예제 #1
0
    def downloadFile(self, fname, nid, fileHash):
        ''' 根据文件名和节点ip下载文件

            fname String 文件路径名称 path
            nid Long 节点id
            fielHash String 文件的hash值
        '''
        # 如果hash值相同则无需下载
        #if fileHash == utilsYunPan.getFileHash(fname):
        #    return True
        url = self.serverAddr + "/file/download"
        args = {
            'fname' : fname,
            'hid' : '',
            'nid' : nid
        }
        args = urllib.urlencode(args)
        reqArgs  = urllib2.Request(
            url = url,
            data = args
        )
        reqArgs.add_header("Referer", "http://c21.yunpan.360.cn/my/index/");
        result = urllib2.urlopen(reqArgs).read()
        result = json.loads(result)
        # 这里需要做一些验证
        result = urllib2.urlopen(result['data']['download_url']).read();
        fname = self.pathYunPan + fname
        fname = fname.decode()
        if utilsYunPan.isText(result[0:512]):
            print "Download File: " + fname + " type: ASCII"
            open(fname, 'w').write(result)
        else:
            print "Download File: " + fname + " type: Binary"
            open(fname, 'wb').write(result)
예제 #2
0
    def downloadFile(self, fname, nid, fileHash):
        """ 根据文件名和节点ip下载文件

            fname String 文件路径名称 path
            nid Long 节点id
            fielHash String 文件的hash值
        """
        # 如果hash值相同则无需下载
        # if fileHash == utilsYunPan.getFileHash(fname):
        #    return True
        url = self.serverAddr + "/file/download"
        args = {"fname": fname, "hid": "", "nid": nid}
        referer = "http://c21.yunpan.360.cn/my/index/"
        result = self._getResult(url, args, referer)
        # 这里需要做一些验证
        result = urllib.request.urlopen(result["data"]["download_url"]).read()
        fname = self.pathYunPan + fname
        if utilsYunPan.isText(result[0:512]):
            print("Download File: " + fname + " type: ASCII")
            open(fname, "w").write(result)
        else:
            print("Download File: " + fname + " type: Binary")
            open(fname, "wb").write(result)