Exemplo n.º 1
0
def list_trash(cookie, tokens, path='/', page=1, num=100):
    '''获取回收站的信息.

    path - 目录的绝对路径, 默认是根目录
    page - 页码, 默认是第一页
    num - 每页有多少个文件, 默认是100个.
    回收站里面的文件会被保存10天, 10天后会自动被清空.
    回收站里面的文件不占用用户的存储空间.
    '''
    url = ''.join([
        const.PAN_API_URL,
        'recycle/list?channel=chunlei&clienttype=0&web=1&app_id=250528',
        '&num=',
        str(num),
        '&t=',
        util.timestamp(),
        '&dir=',
        encoder.encode_uri_component(path),
        '&t=',
        util.latency(),
        '&order=time&desc=1',
        '&_=',
        util.timestamp(),
        '&bdstoken=',
        tokens['bdstoken'],
    ])
    req = net.urlopen(url, headers={'Cookie': cookie.header_output()})
    if req:
        content = req.data
        return json.loads(content.decode())
    else:
        return None
Exemplo n.º 2
0
def list_dir(cookie, tokens, path, page=1, num=100):
    '''得到一个目录中的所有文件的信息(最多100条记录).'''
    timestamp = util.timestamp()
    url = ''.join([
        const.PAN_API_URL,
        'list?channel=chunlei&clienttype=0&web=1&app_id=250528',
        '&num=',
        str(num),
        '&t=',
        timestamp,
        '&page=',
        str(page),
        '&dir=',
        encoder.encode_uri_component(path),
        '&t=',
        util.latency(),
        '&order=time&desc=1',
        '&_=',
        timestamp,
        '&bdstoken=',
        tokens['bdstoken'],
    ])
    req = net.urlopen(url,
                      headers={
                          'Content-type':
                          const.CONTENT_FORM_UTF8,
                          'Cookie':
                          cookie.sub_output('BAIDUID', 'BDUSS', 'PANWEB',
                                            'cflag', 'SCRC', 'STOKEN'),
                      })
    if req:
        content = req.data
        return json.loads(content.decode())
    else:
        return None
Exemplo n.º 3
0
def list_share_path(cookie, tokens, uk, path, share_id, page):
    '''列举出用户共享的某一个目录中的文件信息

    uk       - user key
    path     - 共享目录
    share_id - 共享文件的ID值
    '''
    url = ''.join([
        const.PAN_URL,
        'share/list?channel=chunlei&clienttype=0&web=1&num=100',
        '&t=', util.timestamp(),
        '&page=', str(page),
        '&dir=', encoder.encode_uri_component(path),
        '&t=', util.latency(),
        '&shareid=', share_id,
        '&order=time&desc=1',
        '&uk=', uk,
        '&_=', util.timestamp(),
        '&bdstoken=', tokens['bdstoken'],
    ])
    req = net.urlopen(url, headers={
        'Cookie': cookie.header_output(),
        'Referer': const.SHARE_REFERER,
    })
    if req:
        content = req.data
        return json.loads(content.decode())
    else:
        return None
Exemplo n.º 4
0
def search(cookie, tokens, key, path='/'):
    '''搜索全部文件, 根据文件名.

    key - 搜索的关键词
    path - 如果指定目录名的话, 只搜索本目录及其子目录里的文件名.
    '''
    url = ''.join([
        const.PAN_API_URL,
        'search?channel=chunlei&clienttype=0&web=1&appid=250528',
        '&dir=',
        path,
        '&key=',
        key,
        '&recursion',
        '&timeStamp=',
        util.latency(),
        '&bdstoken=',
        tokens['bdstoken'],
    ])
    req = net.urlopen(url, headers={'Cookie': cookie.header_output()})
    if req:
        content = req.data
        return json.loads(content.decode())
    else:
        return None
Exemplo n.º 5
0
def list_trash(cookie, tokens, path='/', page=1, num=100):
    '''获取回收站的信息.

    path - 目录的绝对路径, 默认是根目录
    page - 页码, 默认是第一页
    num - 每页有多少个文件, 默认是100个.
    回收站里面的文件会被保存10天, 10天后会自动被清空.
    回收站里面的文件不占用用户的存储空间.
    '''
    url = ''.join([
        const.PAN_API_URL,
        'recycle/list?channel=chunlei&clienttype=0&web=1',
        '&num=', str(num),
        '&t=', util.timestamp(),
        '&dir=', encoder.encode_uri_component(path),
        '&t=', util.latency(),
        '&order=time&desc=1',
        '&_=', util.timestamp(),
        '&bdstoken=', tokens['bdstoken'],
    ])
    req = net.urlopen(url, headers={'Cookie': cookie.header_output()})
    if req:
        content = req.data
        return json.loads(content.decode())
    else:
        return None
Exemplo n.º 6
0
def list_share_files(cookie, tokens, uk, shareid, dirname, page=1):
    '''列举出用户共享的某一个目录中的文件信息

    这个对所有用户都有效
    uk       - user key
    shareid - 共享文件的ID值
    dirname  - 共享目录, 如果dirname为None, 说明这有可能是一个单独共享的文件,
               这里, 需要调用list_share_single_file()
    '''
    if not dirname:
        return list_share_single_file(cookie, tokens, uk, shareid)
    url = ''.join([
        const.PAN_URL,
        'share/list?channel=chunlei&clienttype=0&web=1&num=50',
        '&t=', util.timestamp(),
        '&page=', str(page),
        '&dir=', encoder.encode_uri_component(dirname),
        '&t=', util.latency(),
        '&shareid=', shareid,
        '&order=time&desc=1',
        '&uk=', uk,
        '&_=', util.timestamp(),
        '&bdstoken=', tokens['bdstoken'],
    ])
    req = net.urlopen(url, headers={
        'Cookie': cookie.header_output(),
        'Referer': const.SHARE_REFERER,
    })
    if req:
        content = req.data
        info = json.loads(content.decode())
        if info['errno'] == 0:
            return info['list']
    return list_share_single_file(cookie, tokens, uk, shareid)
Exemplo n.º 7
0
def list_share_files(cookie, tokens, uk, shareid, dirname, page=1):
    '''列举出用户共享的某一个目录中的文件信息

    这个对所有用户都有效
    uk       - user key
    shareid - 共享文件的ID值
    dirname  - 共享目录, 如果dirname为None, 说明这有可能是一个单独共享的文件,
               这里, 需要调用list_share_single_file()
    '''
    if not dirname:
        return list_share_single_file(cookie, tokens, uk, shareid)
    url = ''.join([
        const.PAN_URL,
        'share/list?channel=chunlei&clienttype=0&web=1&num=50',
        '&t=', util.timestamp(),
        '&page=', str(page),
        '&dir=', encoder.encode_uri_component(dirname),
        '&t=', util.latency(),
        '&shareid=', shareid,
        '&order=time&desc=1',
        '&uk=', uk,
        '&_=', util.timestamp(),
        '&bdstoken=', tokens['bdstoken'],
    ])
    req = net.urlopen(url, headers={
        'Cookie': cookie.header_output(),
        'Referer': const.SHARE_REFERER,
    })
    if req:
        content = req.data
        info = json.loads(content.decode())
        if info['errno'] == 0:
            return info['list']
    return list_share_single_file(cookie, tokens, uk, shareid)
Exemplo n.º 8
0
def search(cookie, tokens, key, path='/'):
    print('/usr/local/lib/python3.4/dist-packages/bcloud/pcs.py:search 887')
    '''搜索全部文件, 根据文件名.

    key - 搜索的关键词
    path - 如果指定目录名的话, 只搜索本目录及其子目录里的文件名.
    '''
    url = ''.join([
        const.PAN_API_URL,
        'search?channel=chunlei&clienttype=0&web=1',
        '&dir=',
        path,
        '&key=',
        key,
        '&recursion',
        '&timeStamp=',
        util.latency(),
        '&bdstoken=',
        tokens['bdstoken'],
    ])
    req = net.urlopen(url, headers={'Cookie': cookie.header_output()})
    if req:
        content = req.data
        return json.loads(content.decode())
    else:
        return None
Exemplo n.º 9
0
def search(cookie, tokens, key, path='/'):
    '''搜索全部文件, 根据文件名.

    key - 搜索的关键词
    path - 如果指定目录名的话, 只搜索本目录及其子目录里的文件名.
    '''
    url = ''.join([
        const.PAN_API_URL,
        'search?channel=chunlei&clienttype=0&web=1',
        '&dir=', path,
        '&key=', key,
        '&recursion',
        '&timeStamp=', util.latency(),
        '&bdstoken=', tokens['bdstoken'],
    ])
    req = net.urlopen(url, headers={'Cookie': cookie.header_output()})
    if req:
        content = req.data
        return json.loads(content.decode())
    else:
        return None
Exemplo n.º 10
0
def list_share_path(cookie, tokens, uk, path, share_id, page):
    '''列举出用户共享的某一个目录中的文件信息

    uk       - user key
    path     - 共享目录
    share_id - 共享文件的ID值
    '''
    url = ''.join([
        const.PAN_URL,
        'share/list?channel=chunlei&clienttype=0&web=1&num=100',
        '&t=',
        util.timestamp(),
        '&page=',
        str(page),
        '&dir=',
        encoder.encode_uri_component(path),
        '&t=',
        util.latency(),
        '&shareid=',
        share_id,
        '&order=time&desc=1',
        '&uk=',
        uk,
        '&_=',
        util.timestamp(),
        '&bdstoken=',
        tokens['bdstoken'],
    ])
    req = net.urlopen(url,
                      headers={
                          'Cookie': cookie.header_output(),
                          'Referer': const.SHARE_REFERER,
                      })
    if req:
        content = req.data
        return json.loads(content.decode())
    else:
        return None
Exemplo n.º 11
0
def list_dir(cookie, tokens, path, page=1, num=100):
    '''得到一个目录中的所有文件的信息(最多100条记录).'''
    timestamp = util.timestamp()
    url = ''.join([
        const.PAN_API_URL,
        'list?channel=chunlei&clienttype=0&web=1',
        '&num=', str(num),
        '&t=', timestamp,
        '&page=', str(page),
        '&dir=', encoder.encode_uri_component(path),
        '&t=', util.latency(),
        '&order=time&desc=1',
        '&_=', timestamp,
        '&bdstoken=', tokens['bdstoken'],
    ])
    req = net.urlopen(url, headers={
        'Content-type': const.CONTENT_FORM_UTF8,
        'Cookie': cookie.sub_output('BAIDUID', 'BDUSS', 'PANWEB', 'cflag'),
    })
    if req:
        content = req.data
        return json.loads(content.decode())
    else:
        return None