批量下载视频文件
将公司托管在视频三方平台的9000个视频文件下载到本地做备份。记录批量下载视频文件操作步骤,下载程序详见github地址。
下载程序github地址: https://github.com/sj741231/DownloadVideo.git.
代码逻辑:
- 读取Excel源文件,源文件中包括视频VID,下载文件存储相对路径。
- 用构造POST请求,使用VID获取视频临时下载地址。
- 请求临时下载地址并存储到指定的文件存储路径。
一、系统环境
VMware® Workstation 15 Pro
Centos 7.9
Python 3.9
一、环境准备
-
安装 Workstation 15 Pro
略 -
安装 Centos 7.9
略 -
启动虚机连接USB硬盘
点击USB(虚机要开启USB接口)选择连接到虚机
-
Centos 7挂载USB硬盘
参考挂载方法:https://blog.youkuaiyun.com/shijin741231/article/details/113903229.// 将USB硬盘挂载到/data目录下 [root@192 download]# mount -t ntfs-3g /dev/sdb2 /data
-
安装 Python3.9
参考方法:https://blog.youkuaiyun.com/shijin741231/article/details/110196975. -
安装 Python虚拟环境
参考方法:https://blog.youkuaiyun.com/shijin741231/article/details/110791097.
二、部署代码
- github上下载代码部署到虚机
// 代码路径 (DownloadVideo) [root@192 DownloadVideo]# pwd /opt/dev/DownloadVideo // 代码文件,详细信息见代码项目说明 (DownloadVideo) [root@192 DownloadVideo]# ll 总用量 3764 -rw-r--r-- 1 root root 2177067 3月 13 20:08 dl_20210313-20:08:22.xlsx drwxr-xr-x 2 root root 30 3月 12 21:52 doc -rw-r--r-- 1 root root 26132 3月 12 21:52 handle.py -rw-r--r-- 1 root root 0 3月 12 21:52 __init__.py drwxr-xr-x 2 root root 61 3月 13 19:19 logs -rw------- 1 root root 1881 3月 13 20:07 nohup.out drwxr-xr-x 2 root root 70 3月 13 17:51 __pycache__ -rw-r--r-- 1 root root 1320 3月 12 21:52 readme.md -rw-r--r-- 1 root root 985 3月 12 21:52 row_object.py -rw-r--r-- 1 root root 499 3月 13 17:22 settings.py drwxr-xr-x 3 root root 198 3月 13 15:39 utils -rw-r--r-- 1 root root 1630058 3月 8 17:44 vid-20210214.xlsx (DownloadVideo) [root@192 DownloadVideo]# // vid-20210214.xlsx是代码读取VID的源文件 // dl_20210313-20:08:22.xlsx是下载任务执行后写入下载结果文件
- 导入程序依赖包
参考方法:https://blog.youkuaiyun.com/shijin741231/article/details/110003509.// 导入requirement文件 (DownloadVideo) [root@192 doc]# pwd /opt/dev/DownloadVideo/doc (DownloadVideo) [root@192 doc]# ls requirements.txt (DownloadVideo) [root@192 doc]#
- 程序运行命令
// 输入-h 或 --help 查看帮助 (DownloadVideo) [root@192 DownloadVideo]# python3.9 handle.py -h Usage: python3.9 handle.py -file [ -sheet -start -end ] Help: -h --help -c --check <check whether download file exists and do nothing> Mandatory options: -f --file <source excel> Optional options: -t --sheet <The sheet name in Excel, default active sheet in Excel> -s --start <Excel start row. Must be int,default index 2> -e --end <Excel end row. Must be int,default Maximum number of rows in Excel> (DownloadVideo) [root@192 DownloadVideo]#