0 背景

还在为视频下载而烦恼吗?作为一名新时代农民工,代码就是最好的工具。推荐一款视频下载神器 you-get,只需要一个命令行,就可以下载到你想要的视频,不需要下载其他乱七八糟的工具,

项目地址:GitHub - soimort/you-get: Dumb downloader that scrapes the web:arrow_double_down: Dumb downloader that scrapes the web - GitHub - soimort/you-get: Dumb downloader that scrapes the webhttps://github.com/soimort/you-get

常见的视频网站,如土豆、优酷、西瓜视频、快手、抖音等都支持,截取部分支持列表如下

1 安装方法

如果是在 linux 上安装,可通过 pip 指令

$ pip3 install you-get

如果是在 windows 上使用,可直接下载安装包(0.4.915之后的版本不再直接提供exe安装包)

 使用 help 指令查看该工具的使用方法介绍

$ you-get --help
you-get: version 0.4.1432, a tiny downloader that scrapes the web.
usage: you-get [OPTION]... URL...

A tiny downloader that scrapes the web

optional arguments:
  -V, --version         Print version and exit
  -h, --help            Print this help message and exit

Dry-run options:
  (no actual downloading)

  -i, --info            Print extracted information
  -u, --url             Print extracted information with URLs
  --json                Print extracted URLs in JSON format

Download options:
  -n, --no-merge        Do not merge video parts
  --no-caption          Do not download captions (subtitles, lyrics, danmaku,
                        ...)
  -f, --force           Force overwriting existing files
  --skip-existing-file-size-check
                        Skip existing file without checking file size
  -F STREAM_ID, --format STREAM_ID
                        Set video format to STREAM_ID
  -O FILE, --output-filename FILE
                        Set output filename
  -o DIR, --output-dir DIR
                        Set output directory
  -p PLAYER, --player PLAYER
                        Stream extracted URL to a PLAYER
  -c COOKIES_FILE, --cookies COOKIES_FILE
                        Load cookies.txt or cookies.sqlite
  -t SECONDS, --timeout SECONDS
                        Set socket timeout
  -d, --debug           Show traceback and other debug info
  -I FILE, --input-file FILE
                        Read non-playlist URLs from FILE
  -P PASSWORD, --password PASSWORD
                        Set video visit password to PASSWORD
  -l, --playlist        Prefer to download a playlist
  -a, --auto-rename     Auto rename same name different files
  -k, --insecure        ignore ssl errors

Proxy options:
  -x HOST:PORT, --http-proxy HOST:PORT
                        Use an HTTP proxy for downloading
  -y HOST:PORT, --extractor-proxy HOST:PORT
                        Use an HTTP proxy for extracting only
  --no-proxy            Never use a proxy
  -s HOST:PORT, --socks-proxy HOST:PORT
                        Use an SOCKS5 proxy for downloading

常用的指令有以下几个:

 -i, --info ,输出视频信息

-O FILE, --output-filename FILE 指定保存文件的名字

-o DIR, --output-dir DIR 指定保存文件的路径

-a, --auto-rename 自动给不同的文件重命名

2 下载视频

比如我们想下载一个B 站上的视频,链接为《C4D OC渲染器基础入门中文教程-(持续更新)Octane中文教程》,打开后找到视频地址

 复制一下,可以查看该视频支持的分辨率,标有 [DEFAULT] 的是下载的默认画质,为最高画质,下载时可以根据提示,使用 --format 指令指定要下载的分辨率

$ you-get -i "https://www.bilibili.com/video/BV1Dt4y1e7mM?share_source=copy_web"
site:                Bilibili
title:               C4D OC渲染器基础入门中文教程-(持续更新)Octane中文教程 (P1. 简介)
streams:             # Available quality and codecs
    [ DASH ] ____________________________________
    - format:        dash-flv
      container:     mp4
      quality:       高清 1080P
      size:          5.0 MiB (5284854 bytes)
    # download-with: you-get --format=dash-flv [URL]

    - format:        dash-flv720
      container:     mp4
      quality:       高清 720P
      size:          4.2 MiB (4354841 bytes)
    # download-with: you-get --format=dash-flv720 [URL]

    - format:        dash-flv480
      container:     mp4
      quality:       清晰 480P
      size:          3.2 MiB (3313700 bytes)
    # download-with: you-get --format=dash-flv480 [URL]

    - format:        dash-flv360
      container:     mp4
      quality:       流畅 360P
      size:          1.6 MiB (1722154 bytes)
    # download-with: you-get --format=dash-flv360 [URL]

    [ DEFAULT ] _________________________________
    - format:        flv
      container:     flv
      quality:       高清 1080P
      size:          6.8 MiB (7170233 bytes)
    # download-with: you-get --format=flv [URL]

    - format:        flv720
      container:     flv
      quality:       高清 720P
      size:          5.5 MiB (5746856 bytes)
    # download-with: you-get --format=flv720 [URL]

    - format:        flv480
      container:     flv
      quality:       清晰 480P
      size:          2.8 MiB (2983326 bytes)
    # download-with: you-get --format=flv480 [URL]

    - format:        flv360
      container:     flv
      quality:       流畅 360P
      size:          1.7 MiB (1752679 bytes)
    # download-with: you-get --format=flv360 [URL]

比如我们要下载一个 720p 分辨率的视频,输入指令如下

$ you-get --format=flv720 "https://www.bilibili.com/video/BV1Dt4y1e7mM?share_source=copy_web"
site:                Bilibili
title:               C4D OC渲染器基础入门中文教程-(持续更新)Octane中文教程 (P1. 简介)
stream:
    - format:        flv720
      container:     flv
      quality:       高清 720P
      size:          5.5 MiB (5746856 bytes)
    # download-with: you-get --format=flv720 [URL]

Downloading C4D OC渲染器基础入门中文教程-(持续更新)Octane中文教程 (P1. 简介).flv ...
 100% (  5.5/  5.5MB) ├████████████████████████████████████████┤[1/1]   12 MB/s

3 下载脚本

如果视频文件较多,可以使用下边的 shell 脚本进行自动下载,只需要更新一下 list 中的视频地址即可

#!/bin/bash

list=("https://www.bilibili.com/video/BV1rb41187ke?p=3&share_source=copy_web"  
        "https://www.bilibili.com/video/BV1rb41187ke?p=7&share_source=copy_web" 
    )
echo "视频个数为:${#list[@]}"
len=${#list[@]}

for((i=0;i<${len};i++))
do
echo ${list[${i}]}
you-get ${list[${i}]}
# you-get --output-filename ${i} ${list[${i}]}
done

3.1 改进一

通过观察视频 url 格式,可以发现除了第一个不一样外,后续的视频都是在第一个的基础上增加 p=2/3/.. 数字的形式,因此进阶版的脚本如下,只需要输入视频个数,以及视频 url 格式即可。

#!/bin/bash

# 输入视频个数
len=27

for((i=1;i<=${len};i++))
do
if ${i}==1
then
    you-get --output-filename "video_${i}" "https://www.bilibili.com/video/BV1VV411S7Yx?share_source=copy_web" 
else
    you-get --output-filename "video_${i}" "https://www.bilibili.com/video/BV1VV411S7Yx?p=${i}&share_source=copy_web" 
fi
done

3.2 改进二

如果下载的视频文件不多,可以使用多线程的方法

#!/bin/bash

# 输入视频个数
len=27

for((i=1;i<=${len};i++))
do
{
if ${i}==1
then
    you-get --output-filename "video_${i}" "https://www.bilibili.com/video/BV1VV411S7Yx?share_source=copy_web" 
else
    you-get --output-filename "video_${i}" "https://www.bilibili.com/video/BV1VV411S7Yx?p=${i}&share_source=copy_web" 
fi
}&
done
wait

3.3 改进三

如果下载的视频数比较多,可以限制一下线程数

#!/bin/bash

# 输入视频个数
len=27

start_time=`date +%s`              
[ -e /tmp/fd1 ] || mkfifo /tmp/fd1 
exec 3<>/tmp/fd1                   
rm -rf /tmp/fd1                    
for ((i=1;i<=20;i++)) # 设置进程数上限为20,可按需修改
do
        echo >&3                
done


for((i=1;i<=${len};i++))
do
read -u3
{
echo ${list[${i}]}
you-get ${list[${i}]}
echo 'success' ${list[${i}]}     
echo >&3  
}&
done
wait

stop_time=`date +%s`  
 
echo "TIME:`expr $stop_time - $start_time`"
exec 3<&-                       
exec 3>&-   
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐