python操作百度网盘

一直有种想法,要是我们能用代码操作网盘,我们岂不是可以自动化,解放双手了

无意中发现了一个宝贝bypy,这个可以操作我们的网盘

首先我们要安装它:

[root@VM_0_9_centos ~]# pip install bypy

如果不报错,就说明安装成功了

紧接着就是去和百度进行绑定:

[root@VM_0_9_centos ~]# bypy info

然后需要打开命令行上面显示的链接,拷贝到网页上打开,然后登陆自己的百度账号即可,然后点击授权,就可以得到这么一个页面,我们拷贝这个编码,粘贴到linux中的命令行,然后回车,就能进行授权操作了。

授权成功就会显示这个:

[root@VM_0_9_centos ~]# bypy info
Quota: 5.008TB
Used: 1.607TB

注:我是授权过了,所以只显示了结果,如果是第一次前面还好出现很多信息,只是最后两行是上面这个内容。

然后在命令行输入bypy -h就会显示提示帮助

[root@VM_0_9_centos ~]# bypy -h
usage: bypy [-h] [-V] [-d] [-v] [-r RETRY] [-q] [-t TIMEOUT] [-s SLICE]
            [--chunk CHUNK] [-e] [-f] [--no-resume-download]
            [--include-regex INCREGEX] [--on-dup ONDUP] [--no-symlink]
            [--disable-ssl-check] [--cacerts CACERTS] [--mirror MIRROR]
            [--select-fastest-mirror] [--rapid-upload-only]
            [--resume-download-revert-back RCOUNT] [--move]
            [--processes PROCESSES] [--downloader DOWNLOADER]
            [--downloader-arguments DOWNLOADER_ARGS] [--config-dir CONFIGDIR]
            [-c]
            [command [command ...]]

bypy v1.6.7 - Python client for Baidu Yun (Personal Cloud Storage) 百度云/百度网盘 Python 客户端

positional arguments:
  command               operations (quota, list, etc)

optional arguments:
  -h, --help            show this help message and exit
  -V, --version         show program's version number and exit
  -d, --debug           set debugging level (-dd to increase debugging level,
                        -ddd to enable HTPP traffic debugging as well (very
                        talkative)) [default: 0]
  -v, --verbose         set verbosity level [default: 0]
  -r RETRY, --retry RETRY
                        number of retry attempts on network error [default: 5
                        times]
  -q, --quit-when-fail  quit when maximum number of retry failed [default:
                        False]
  -t TIMEOUT, --timeout TIMEOUT
                        network timeout in seconds [default: 300]
  -s SLICE, --slice SLICE
                        size of file upload slice (can use '1024', '2k',
                        '3MB', etc) [default: 20 MB]
  --chunk CHUNK         size of file download chunk (can use '1024', '2k',
                        '3MB', etc) [default: 20 MB]
  -e, --verify          verify upload / download [default : False]
  -f, --force-hash      force file MD5 / CRC32 calculation instead of using
                        cached value
  --no-resume-download  resume instead of restarting when downloading if local
                        file already exists [default: True]
  --include-regex INCREGEX
                        regular expression of files to include. if not
                        specified (default), everything is included. for
                        download, the regex applies to the remote files; for
                        upload, the regex applies to the local files. to
                        exclude files, think about your regex, some tips here:
                        https://stackoverflow.com/questions/406230/regular-
                        expression-to-match-string-not-containing-a-word
                        [default: ]
  --on-dup ONDUP        what to do when the same file / folder exists in the
                        destination: 'overwrite', 'skip', 'prompt' [default:
                        overwrite]
  --no-symlink          DON'T follow symbol links when uploading / syncing up
  --disable-ssl-check   DON'T verify host SSL cerificate
  --cacerts CACERTS     Specify the path for CA Bundle [default: None]
  --mirror MIRROR       Specify the PCS mirror (e.g. bj.baidupcs.com. Open 'ht
                        tps://pcs.baidu.com/rest/2.0/pcs/manage?method=listhos
                        t' to get the list) to use. [default: pcs.baidu.com]
  --select-fastest-mirror
                        Let the program run some tests and select the fastest
                        PCS mirror it detectes. [default: False]
  --rapid-upload-only   only upload large files that can be rapidly uploaded
  --resume-download-revert-back RCOUNT
                        Revert back at least RCOUNT download chunk(s) and
                        align to chunk boundary when resuming the download. A
                        negative value means NO reverts. [default: 1]
  --move                Delete source files/directories after
                        download/upload/syncdown/syncup is successful (This
                        will force verification of the files). [default:
                        False]
  --processes PROCESSES
                        Number of parallel processes. (Only applies to dir
                        sync/dl/ul). [default: 1]
  --downloader DOWNLOADER
                        downloader to use (use python if not specified). valid
                        values: ['aria2'] [default: ]
  --downloader-arguments DOWNLOADER_ARGS
                        arguments for the downloader: normally, the string is
                        the arguments to be passed to the downloader. however,
                        when it begins with '@', it will be treated as the
                        name of file, whose contents will be used as the
                        downloader arguments (example: when specifying
                        '@args.txt', file contents of 'args.txt' will be used
                        as the downloader arguments, not the string
                        '@args.txt' itself). you can also use environment
                        variable 'DOWNLOADER_ARGUMENTS' to specify the
                        downloader arguments (the environment variable has
                        lower priority compared to this argument). default
                        values: {'aria2': '-c -k10M -x4 -s4 --file-
                        allocation=none'}
  --config-dir CONFIGDIR
                        specify the config path [default: /root/.bypy]
  -c, --clean           remove the token file (need re-auth) and upload
                        progress file, -cc: clean hash cache file as well

Commands:
refreshtoken - refresh the access token
cdl_add <source_url> [save_path] [timeout] - add an offline (cloud) download task
cdl_addmon <source_url> [save_path] [timeout] - add an offline (cloud) download task and monitor the download progress
cdl_cancel <task_id>  - cancel an offline (cloud) download task
cdl_list - list offline (cloud) download tasks
cdl_query <task_ids>  - query existing offline (cloud) download tasks
cleancache - remove invalid entries from hash cache file
combine <remotefile> [localfile] [md5s] - try to create a file at PCS by combining slices, having MD5s specified
compare [remotedir] [localdir] - compare the remote directory with the local directory
copy/cp <from> <to> - copy a file / dir remotely at Baidu Yun
delete/remove/rm <remotepath> - delete a file / dir remotely at Baidu Yun
downdir [remotedir] [localdir] - download a remote directory (recursively)
downfile <remotefile> [localpath] - download a remote file.
download [remotepath] [localpath] - download a remote directory (recursively) / file
dumpcache - display file hash cache
list/ls [remotepath] [format] [sort] [order] - list the 'remotepath' directory at Baidu PCS
listrecycle [start] [limit] - list the recycle contents
meta <remotepath> [format] - get information of the given path (dir / file) at Baidu Yun.
mkdir <remotedir> - create a directory at Baidu Yun
move/mv/rename/ren <from> <to> - move a file / dir remotely at Baidu Yun
quota/info - displays the quota information
restore <remotepath> - restore a file from the recycle bin
search <keyword> [remotepath] [recursive] - search for a file using keyword at Baidu Yun
stream <remotefile> <localpipe> [format] [chunk] - stream a video / audio file converted to M3U format at cloud side, to a pipe.
syncdown [remotedir] [localdir] [deletelocal] - sync down from the remote directory to the local directory
syncup [localdir] [remotedir] [deleteremote] - sync up from the local directory to the remote directory
upload [localpath] [remotepath] [ondup] - upload a file or directory (recursively)

比如说,我们上传linux本地文件到百度网盘上面:

[root@VM_0_9_centos ~]# bypy upload yum_list.xls

我们看一下结果:

[root@VM_0_9_centos ~]# bypy ls
/apps/bypy ($t $f $s $m $d):
F yum_list.xls 3268096 2020-03-14, 11:34:19 4fad2ffedh6c7f375fde1920abc058c0

发现我们已经上传成功,而且结果在/app/bypy下,我们打开百度网盘客户端看看。实际上是在这个路径下:

当然类似的也可以进行下载,我发现一个现象就是,这个命令行操作的是/apps/bypy下的,我试过了哪怕是用../../这样的也是没法得到的结果的,所以我们要是想操作,可以在网盘里拷贝到这个路径下,这样就能操作了,也许是我没找到窍门,比如我:

[root@VM_0_9_centos ~]# bypy cp yum_list.xls ../

不会报错,但是数据还是在/app/bypy友这个数据,而/app/下没有这个数据,所以才用曲折一点的路线,就是在网盘拷贝一下,反正网盘里拷贝是非常快的。

不过我想到了可能是我操作不当,就是要把文件名给给出来才行,因为我想到了linux里面的zip命令就是这样的。

[root@VM_0_9_centos ~]# bypy cp yum_list.xls ../yum_list.xls
[root@VM_0_9_centos ~]# bypy ls ../
/apps/bypy/.. ($t $f $s $m $d):
F yum_list.xls 3268096 2020-03-14, 11:34:19 4fad2ffedh6c7f375fde1920abc058c0

不过,这个结果在网盘里不是这样的:

按照网盘里的显示是,..作为了目录名称,而不是linux里面指代的上一级目录,我们再来试一下:

[root@VM_0_9_centos ~]# bypy cp yum_list.xls qqq/yum_list.xls

结果是这样的: 

从目前看来,我们只能操作bypy下的内容

  • 0
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值