教你如何使用you-get下载视频网站的视频

you-get是一个开源的用python写的工具,支持多个网站视频的下载。包括国内的视频网站像B站,腾讯视频也支持。

安装很容易,可以从github网站直接使用git clone:

git clone git://github.com/soimort/you-get.git

或者可以用pip安装。需要注意的是,必须使用python3带的pip安装。

pip3 install you-get

debian Jessie自带的python3 是3.5,要想安装最新的python 3.6,可以使用如下命令:

$ sudo nano /etc/apt/sources.list
# add
deb http://ftp.de.debian.org/debian testing main
$ echo 'APT::Default-Release "stable";' | sudo tee -a /etc/apt/apt.conf.d/00local
$ sudo apt-get update
$ sudo apt-get -t testing install python3.6
$ python3.6 -V
$ sudo apt-get -t testing install python3-pip
$ pip3 -V

pip3安装了以后,就可以开心安装you-get了。

you-get -i 显示所有可以下载的youtube视频资源选项。

$ you-get -i https://www.youtube.com/watch?v=dfnCAmr569k
site:                YouTube
title:               Taylor Swift - End Game ft. Ed Sheeran, Future
streams:             # Available quality and codecs
    [ DASH ] ____________________________________
    - itag:          137
      container:     mp4
      quality:       1920x1080
      size:          53.1 MiB (55640658 bytes)
    # download-with: you-get --itag=137 [URL]
- itag:          248
      container:     webm
      quality:       1920x1080
      size:          46.1 MiB (48389197 bytes)
    # download-with: you-get --itag=248 [URL]
- itag:          136
      container:     mp4
      quality:       1280x720
      size:          37.2 MiB (39036275 bytes)
    # download-with: you-get --itag=136 [URL]
- itag:          247
      container:     webm
      quality:       1280x720
      size:          30.8 MiB (32341782 bytes)
    # download-with: you-get --itag=247 [URL]
- itag:          135
      container:     mp4
      quality:       854x480
      size:          24.9 MiB (26130838 bytes)
    # download-with: you-get --itag=135 [URL]
- itag:          244
      container:     webm
      quality:       854x480
      size:          20.6 MiB (21562584 bytes)
    # download-with: you-get --itag=244 [URL]
- itag:          134
      container:     mp4
      quality:       640x360
      size:          14.2 MiB (14863399 bytes)
    # download-with: you-get --itag=134 [URL]
- itag:          243
      container:     webm
      quality:       640x360
      size:          13.6 MiB (14308835 bytes)
    # download-with: you-get --itag=243 [URL]
- itag:          242
      container:     webm
      quality:       426x240
      size:          8.9 MiB (9302263 bytes)
    # download-with: you-get --itag=242 [URL]
- itag:          133
      container:     mp4
      quality:       426x240
      size:          8.8 MiB (9266854 bytes)
    # download-with: you-get --itag=133 [URL]
- itag:          278
      container:     webm
      quality:       256x144
      size:          6.5 MiB (6845295 bytes)
    # download-with: you-get --itag=278 [URL]
- itag:          160
      container:     mp4
      quality:       256x144
      size:          6.1 MiB (6445955 bytes)
    # download-with: you-get --itag=160 [URL]
[ DEFAULT ] _________________________________
    - itag:          22
      container:     mp4
      quality:       hd720
      size:          37.2 MiB (39023386 bytes)
    # download-with: you-get --itag=22 [URL]
- itag:          43
      container:     webm
      quality:       medium
    # download-with: you-get --itag=43 [URL]
- itag:          18
      container:     mp4
      quality:       medium
    # download-with: you-get --itag=18 [URL]
- itag:          36
      container:     3gp
      quality:       small
    # download-with: you-get --itag=36 [URL]
- itag:          17
      container:     3gp
      quality:       small
    # download-with: you-get --itag=17 [URL]

缺省是使用-itag=22下载720p的mp4文件,下载视频文件和字幕文件(如果自带字幕的话)。1080p的文件不带声音,要跟webm合成才行。

$ you-get https://www.youtube.com/watch?v=dfnCAmr569k
site:                YouTube
title:               Taylor Swift - End Game ft. Ed Sheeran, Future
stream:
    - itag:          22
      container:     mp4
      quality:       hd720
      size:          37.2 MiB (39023386 bytes)
    # download-with: you-get --itag=22 [URL]
Downloading Taylor Swift - End Game ft. Ed Sheeran, Future.mp4 ...
 100% ( 37.2/ 37.2MB) ├████████████████████████████████████████████████████████████████████████████████┤[1/1]   14 MB/s
Saving Taylor Swift - End Game ft. Ed Sheeran, Future.en.srt ... Done.
$ ls
Taylor Swift - End Game ft. Ed Sheeran, Future.en.srt
Taylor Swift - End Game ft. Ed Sheeran, Future.mp4

在使用过程中,可能会遇到说console不支持unicode的错误,如下:

you-get: [error] oops, the current environment does not seem to support Unicode.
you-get: please set it to a UTF-8-aware locale first,
you-get: so as to save the video (with some Unicode characters) correctly.
you-get: you can do it like this:
you-get:     (Windows)    % chcp 65001 
you-get:     (Linux)      $ LC_CTYPE=en_US.UTF-8

没有关系,只要安装locales就可以了。

Check that you have the locales package installed

dpkg -l locales

If not, install it

apt-get install locales

Run the localecommand ,the output should be similar to this:

$ locale
LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"

这样就?了。要是想把youtube的视频直接转成MP3,可以安装ffmpeg,然后使用youtube-dl这个工具下载和直接转换。

© 版权声明
THE END
喜欢就支持以下吧
点赞0
分享
评论 抢沙发

请登录后发表评论