Пример #1
0
def get_media_flv_info(access_token, fpath):
    url_path = 'file'
    params = {
        "method": 'streaming',
        "access_token": access_token,
        "path": fpath,
        "type": "M3U8_FLV_264_480",
        "nom3u8": 1
    }
    ua = "xpanvideo;{app};{ver};{sys};{sys_ver};flv".format(app="netdisk",
                                                            ver='2.2.1',
                                                            sys="pc-mac",
                                                            sys_ver="10.13.6")
    headers = {"User-Agent": ua}
    url = "%s/%s" % (POINT, url_path)
    logger.info("get_media_flv_info params:{}, url:{}".format(params, url))
    rs = requests.get(url, params=params, headers=headers, verify=False)
    jsonrs = rs.json()
    err_no = jsonrs["errno"]
    if err_no:
        err_msg = jsonrs.get("err_msg", "")
        if not err_msg:
            err_msg = PAN_ERROR_CODES.get(err_no, "")
            jsonrs["err_msg"] = err_msg
    else:
        mlink = "%s/%s" % (POINT, url_path)
        mlink = "{qp}?method=streaming&path={path}&type=M3U8_FLV_264_480&adToken={adToken}".format(
            qp=mlink, path=fpath, adToken=jsonrs['adToken'])
        jsonrs['mlink_start_at'] = jsonrs['ltime'] + get_now_ts()
        jsonrs['mlink'] = mlink
    logger.info("get_media_flv_info jsonrs:{}".format(jsonrs))
    return jsonrs
Пример #2
0
def file_rename(access_token, filepath, newname):
    url_path = 'file'
    params = {
        "method": 'filemanager',
        "access_token": access_token,
        "opera": "rename"
    }
    filelist = '[{%s}]' % ('"path":"{path}", "newname":"{newname}"'.format(
        path=filepath, newname=newname))
    datas = {"async": 0, "filelist": filelist}
    headers = {"User-Agent": "pan.baidu.com"}
    # print("file_rename file:", access_token, ",path:", filepath, ", filelist:", datas["filelist"])
    rs = requests.post("%s/%s" % (POINT, url_path),
                       params=params,
                       data=datas,
                       headers=headers)
    # print("content:", rs.content)
    jsonrs = rs.json()
    err_no = jsonrs.get("errno", None)
    logger.info("restapi file_rename:{}, err_no:{}".format(filepath, err_no))
    if err_no:
        err_msg = jsonrs.get("err_msg", "")
        if not err_msg:
            err_msg = PAN_ERROR_CODES.get(err_no, "")
            jsonrs["err_msg"] = err_msg
    # {'errno': 0, 'info': [{'errno': 0, 'path': '/_SHAREDSYS/07声梦奇缘精讲:第5课.mp4'}], 'request_id': 1739388018147258558}
    return jsonrs
Пример #3
0
def transfer_share_files(access_token,
                         share_id,
                         from_uk,
                         randsk,
                         fs_id,
                         path,
                         recursion=True):
    point = "{protocol}://{domain}".format(protocol=PAN_SERVICE['protocol'],
                                           domain="pan.baidu.com/share")
    url_path = 'transfer'
    url = "%s/%s" % (point, url_path)
    headers = {"User-Agent": "pan.baidu.com", "Referer": "pan.baidu.com"}
    # params = {"access_token": access_token, "shareid": share_id, "from": from_uk, "sekey": randsk, "async": 0}
    # params 内部转码后报参数错误
    url = url + "?access_token={}&shareid={}&from={}&sekey={}&async=0".format(
        access_token, share_id, from_uk, randsk)
    datas = {"fsidlist": "[%s]" % fs_id, "path": path}
    logger.info("transfer_share_files url:{},fsidlist:{},path:{}".format(
        url, datas['fsidlist'], path))
    rs = requests.post(url, data=datas, headers=headers, verify=False)
    jsonrs = rs.json()
    err_no = jsonrs["errno"]
    if err_no:
        if 12 == err_no:
            if "info" in jsonrs:
                info_list = jsonrs["info"]
                if info_list:
                    _info = info_list[0]
                    info_err_no = _info.get("errno", None)
                    if info_err_no and info_err_no == -30 and "path" in _info:
                        return {"errno": -30, "path": _info["path"]}
            if recursion:
                time.sleep(0.5)
                logger.info("transfer_share_files will retry on time!")
                return transfer_share_files(access_token, share_id, from_uk,
                                            randsk, fs_id, path, False)

        err_msg = jsonrs.get("err_msg", "")
        if not err_msg:
            err_msg = PAN_ERROR_CODES.get(err_no, "")
            jsonrs["err_msg"] = err_msg
    logger.info("transfer_share_files:{}".format(jsonrs))
    return jsonrs
Пример #4
0
def pan_mkdir(access_token, filepath):
    url_path = 'file'
    params = {"method": 'create', "access_token": access_token}
    datas = {"path": filepath, "size": 0, "isdir": 1, "rtype": 0}
    headers = {"User-Agent": "pan.baidu.com"}
    rs = requests.post("%s/%s" % (POINT, url_path),
                       params=params,
                       data=datas,
                       headers=headers)
    # print("content:", rs.content)
    jsonrs = rs.json()
    # print(jsonrs)
    err_no = jsonrs.get("errno", None)
    logger.info("restapi pan_mkdir:{}, err_no:{}".format(filepath, err_no))
    if err_no:
        err_msg = jsonrs.get("err_msg", "")
        if not err_msg:
            err_msg = PAN_ERROR_CODES.get(err_no, "")
            jsonrs["err_msg"] = err_msg
    return jsonrs
Пример #5
0
def get_share_list(share_id, short_url, randsk):
    url_path = 'share?method=list'
    url = "%s/%s" % (POINT, url_path)
    headers = {"User-Agent": "pan.baidu.com"}
    params = {
        "shareid": share_id,
        "shorturl": short_url,
        "sekey": randsk,
        "root": 1
    }
    rs = requests.get(url, params=params, headers=headers, verify=False)
    jsonrs = rs.json()
    err_no = jsonrs["errno"]
    logger.info("restapi get_share_list share_id:{}, err_no:{}".format(
        share_id, err_no))
    if err_no:
        err_msg = jsonrs.get("err_msg", "")
        if not err_msg:
            err_msg = PAN_ERROR_CODES.get(err_no, "")
            jsonrs["err_msg"] = err_msg
    logger.info("get_share_list:{}".format(jsonrs))
    return jsonrs
Пример #6
0
def get_share_randsk(share_id, pwd, surl):
    url_path = 'share?method=verify'
    url = "%s/%s" % (POINT, url_path)
    headers = {"User-Agent": "pan.baidu.com", "Referer": "pan.baidu.com"}
    params = {"pwd": pwd, "surl": surl, "shareid": share_id}
    datas = {"pwd": pwd}
    rs = requests.post(url,
                       data=datas,
                       params=params,
                       headers=headers,
                       verify=False)
    jsonrs = rs.json()
    # print(jsonrs)
    err_no = jsonrs["errno"]
    logger.info("restapi get_share_randsk share_id:{}, err_no:{}".format(
        share_id, err_no))
    if err_no:
        err_msg = jsonrs.get("err_msg", "")
        if not err_msg:
            err_msg = PAN_ERROR_CODES.get(err_no, "")
            jsonrs["err_msg"] = err_msg
    return jsonrs
Пример #7
0
def share_folder(access_token, fs_id, pwd, period=1):
    url_path = 'share?method=set&access_token=%s' % access_token
    url = "%s/%s" % (POINT, url_path)
    headers = {"User-Agent": "pan.baidu.com"}
    params = {
        "fid_list": "[%s]" % fs_id,
        "schannel": 4,
        "channel_list": "[]",
        "pwd": pwd,
        "period": period
    }
    rs = requests.post(url, data=params, headers=headers, verify=False)
    jsonrs = rs.json()
    err_no = jsonrs["errno"]
    logger.info("restapi share_folder fs_id:{}, err_no:{}".format(
        fs_id, err_no))
    if err_no:
        err_msg = jsonrs.get("err_msg", "")
        if not err_msg:
            err_msg = PAN_ERROR_CODES.get(err_no, "")
            jsonrs["err_msg"] = err_msg
    # print("share_folder:", jsonrs)
    return jsonrs
Пример #8
0
def del_file(access_token, filepath):
    url_path = 'file'
    params = {
        "method": 'filemanager',
        "access_token": access_token,
        "opera": "delete"
    }
    datas = {"async": 0, "filelist": '["%s"]' % filepath}
    headers = {"User-Agent": "pan.baidu.com"}
    rs = requests.post("%s/%s" % (POINT, url_path),
                       params=params,
                       data=datas,
                       headers=headers)
    # print("content:", rs.content)
    jsonrs = rs.json()
    # print(jsonrs)
    err_no = jsonrs["errno"]
    logger.info("restapi del file:{}, err_no:{}".format(filepath, err_no))
    if err_no:
        err_msg = jsonrs.get("err_msg", "")
        if not err_msg:
            err_msg = PAN_ERROR_CODES.get(err_no, "")
            jsonrs["err_msg"] = err_msg
    return jsonrs