官方文档传送门:https://github.com/soimort/you-get/wiki/中文说明


you-get 大法之功用:

  • 下载流行网站之音视频,例如 YouTube、Youku、TED、土豆以及更多
  • 于您心仪的媒体播放器中观看在线视频,脱离浏览器与广告
  • 下载您喜欢的网页上的图片
  • 下载任何非 HTML 内容,例如二进制文件

安装:

1、you-get 的官方版本通过 PyPI 分发, 可从 PyPI 镜像中通过 pip 包管理器进行安装:

  1. pip install you-get -i http://pypi.douban.com/simple --trusted-host pypi.douban.com

2、安装上 FFmpeg,下载地址:https://www.gyan.dev/ffmpeg/builds/,找到文件最大的那个下载就对了。
image.png
解压文件,进入bin目录,能看到ffmpeg.exe、ffplay.exe、ffprobe.exe三个文件。然后把该路径添加到环境变量path。
image.png
打开cmd输入 ffmpeg –version 如果显示版本号,证明安装成功了。
image.png

实战:

下面我们进入实战,我们以B站为例:

当观赏感兴趣的视频时,您可以使用 —info/-i 以查看所有可用画质与格式:

  1. you-get -i https://www.bilibili.com/video/BV1Kh411X7n8?t=28

稍等片刻,我们会看到相关信息:
image.png

  • 标有 DEFAULT 为默认画质,如果希望保存为其他格式(mp4),可以使用 -i 查看所有可用画质与格式给出的其他选项进行下载。
  • 使用其他选项进行下载:download-with(之后的):you-get —format=。。。URL
  • 使用 —output-dir/-o 设定路径,—output-filename/-O 设定输出文件名
  • 下载过程中可以使用 Ctrl+C 暂停下载

比如我们要下载第一个格式为 flv,并且输出到D盘的test路径下,我们改如何写呢?

  1. you-get -o D:\test --format=flv https://www.bilibili.com/video/BV1Kh411X7n8

image.png
如果想下载列表,在地址前面加 —playlist :

  1. you-get -o D:\test --format=flv --playlist https://www.bilibili.com/video/BV1RE411C7t5

不过下载速度一直空六七百K左右,不会太快。

在 Python 中使用:

  1. import sys
  2. from you_get import common as you_get # 导入you-get库
  3. # 设置下载目录
  4. directory = r'D:\test'
  5. # 要下载的视频地址
  6. url = 'https://www.bilibili.com/video/BV1me411W7J5'
  7. # 传参数
  8. sys.argv = ['you-get', '-o', directory, '--format=flv', url]
  9. you_get.main()

参数:

  1. usage: you-get [OPTION]... URL...
  2. A tiny downloader that scrapes the web
  3. optional arguments:
  4. -V, --version Print version and exit
  5. -h, --help Print this help message and exit
  6. Dry-run options:
  7. (no actual downloading)
  8. -i, --info Print extracted information
  9. -u, --url Print extracted information with URLs
  10. --json Print extracted URLs in JSON format
  11. Download options:
  12. -n, --no-merge Do not merge video parts
  13. --no-caption Do not download captions (subtitles, lyrics, danmaku,
  14. ...)
  15. -f, --force Force overwriting existing files
  16. --skip-existing-file-size-check
  17. Skip existing file without checking file size
  18. -F STREAM_ID, --format STREAM_ID
  19. Set video format to STREAM_ID
  20. -O FILE, --output-filename FILE
  21. Set output filename
  22. -o DIR, --output-dir DIR
  23. Set output directory
  24. -p PLAYER, --player PLAYER
  25. Stream extracted URL to a PLAYER
  26. -c COOKIES_FILE, --cookies COOKIES_FILE
  27. Load cookies.txt or cookies.sqlite
  28. -t SECONDS, --timeout SECONDS
  29. Set socket timeout
  30. -d, --debug Show traceback and other debug info
  31. -I FILE, --input-file FILE
  32. Read non-playlist URLs from FILE
  33. -P PASSWORD, --password PASSWORD
  34. Set video visit password to PASSWORD
  35. -l, --playlist Prefer to download a playlist
  36. -a, --auto-rename Auto rename same name different files
  37. -k, --insecure ignore ssl errors
  38. Proxy options:
  39. -x HOST:PORT, --http-proxy HOST:PORT
  40. Use an HTTP proxy for downloading
  41. -y HOST:PORT, --extractor-proxy HOST:PORT
  42. Use an HTTP proxy for extracting only
  43. --no-proxy Never use a proxy
  44. -s HOST:PORT or USERNAME:PASSWORD@HOST:PORT, --socks-proxy HOST:PORT or USERNAME:PASSWORD@HOST:PORT
  45. Use an SOCKS5 proxy for downloading

注意:

如果 you-get 出现问题,不要惊慌. (是的,问题一直存在!),看看是不是在 https://github.com/soimort/you-get/wiki/Known-Bugs里面,搜索 开放Issue,如果没人报告,开个新issue,加上详细的命令行输出。