如何使用lux,youtube-dl下载各视频网站(含Youtube)上面的音视频,油管视频

简单快速地视频音频下载神器,支持各大视频站点

2023年11月 切换方案至lux

用法:

  1. lux {bilibili或youtube的播放url地址}
    1. 举例子:lux https://www.bilibili.com/video/BV1GN411n7En
  2. ffmpeg -i {输入文件} {输出文件}
    1. 举例子:ffmpeg - i /Users/carlzeng/Downloads/《踏雪》亚运版.mp4 踏雪亚运版.mp3

默认墙内时,对于油管的下载支持不是太好;解决办法:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
HTTPS_PROXY="socks5://127.0.0.1:7890" lux "https://www.youtube.com/watch?v=5Dm9XTbnN-M"


Site: YouTube youtube.com
Title: 秋殇别恋
Type: video
Stream:
[137] -------------------
Quality: 1080p video/mp4; codecs="avc1.640020"
Size: 20.82 MiB (21836289 Bytes)
# download with: lux -f 137 ...

20.82 MiB / 20.82 MiB [===========================================================================] 46.43 KiB p/s 100.00% 7m40s
Merging video parts into 秋殇别恋.mp4

需要注意到的是,我们在命令行前面使用HTTPS_PROXY现在基本是都HTTPS了,闭着眼睛这样一条命令就好:
HTTPS_PROXY=”可用的代理地址” lux “音乐播放的URL地址”


2023.12更新:【待实践测试】

yt-dlp

Python的一个实现,原来youtube-dl停更后,一个分支已经转为YT-DLP

yt-dlp is a youtube-dl fork based on the now inactive youtube-dlc. The main focus of this project is adding new features and patches while also keeping up to date with the original project

You can install yt-dlp using the binaries, pip or one using a third-party package manager. See the wiki for detailed instructions

https://github.com/yt-dlp/yt-dlp?tab=readme-ov-file#readme


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
[youtube] cEEWJ9LcBXk: Downloading webpage
WARNING: Unable to download webpage: <urlopen error [Errno 54] Connection reset by peer>
[youtube] cEEWJ9LcBXk: Downloading API JSON
ERROR: Unable to download API page: <urlopen error [Errno 54] Connection reset by peer> (caused by URLError(error(54, 'Connection reset by peer'),))

-------------
[youtube] cEEWJ9LcBXk: Downloading webpage
ERROR: Unable to extract uploader id; please report this issue on https://yt-dl.org/bug . Make sure you are using the latest version; type youtube-dl -U to update. Be sure to call youtube-dl with the --verbose flag and include its complete output.


youtube-dl --update
ERROR: can't find the current version. Please try again later.

sudo curl -L https://yt-dl.org/downloads/latest/youtube-dl -o /usr/local/bin/youtube-dl
sudo chmod a+rx /usr/local/bin/youtube-dl

youtube-dl --proxy 'socks5://127.0.0.1:7890' 'https://www.youtube.com/watch?v=cEEWJ9LcBXk'
/usr/local/bin/youtube-dl: line 1: syntax error near unexpected token `newline'
/usr/local/bin/youtube-dl: line 1: `<h1>Access denied</h1>'

youtube-dl年久失修了,转用其他方案:比如you-get 或者 lux方案
you-get 一直下载不成功,放弃。
转用lux
项目地址https://github.com/iawia002/lux


20231115实测
用来下载bilibili视频也非常轻松

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
lux "https://www.bilibili.com/video/BV1iy4y1u7n3/?vd_source=dabd362cb0c2607dd58ee4300223b109"

Site: 哔哩哔哩 bilibili.com
Title: 【地狱客栈/Hazbin Hotel】【第二版】《疯子》阿拉斯托歌曲
Type: video
Stream:
[32-7] -------------------
Quality: 清晰 480P avc1.64001F
Size: 10.52 MiB (11027795 Bytes)
# download with: lux -f 32-7 ...

10.52 MiB / 10.52 MiB [====================================================================================] 10.43 MiB p/s 100.00% 1.2s
Merging video parts into 【地狱客栈 Hazbin Hotel】【第二版】《疯子》阿拉斯托歌曲.mp4


#下载后转化为mp3
ffmpeg -i "【地狱客栈 Hazbin Hotel】【第二版】《疯子》阿拉斯托歌曲.mp4" "地狱客栈-疯子.mp3"

安装:

1
2
3
4
5
$ brew install lux

前提是已经全局*墙的情况下这条命令可以正常访问下载到最新版lux
lux --version
lux: version v0.0.0, A fast and simple video downloader.

所有这些youtube-dl可执行文件都被下载到Mac目录:/usr/local/bin
而使用brew安装就跑到了?

如何用ffmpeg将mp4转换为mp3

ffmpeg -i {输入文件} {输出文件}
好简单,明了


相关内容

如果您对相关的 youtube 感兴趣,以下内容可能帮到您:

youtube_dl工具已无效了

2023.6.20 测试,报错:

ERROR: Signature extraction failed

File “/usr/local/bin/youtube-dl/youtube_dl/extractor/youtube.py”, line 1360, in _decrypt_signature

func = self._extract_signature_function(

File “/usr/local/bin/youtube-dl/youtube_dl/extractor/youtube.py”, line 1277, in _extract_signature_function

。。。

File “/usr/local/bin/youtube-dl/youtube_dl/jsinterp.py”, line 182, in interpret_expression

return obj[member](argvals)

KeyError: ‘QV’

(caused by KeyError(‘QV’)); please report this issue on https://yt-dl.org/bug . Make sure you are using the latest version; type youtube-dl -U to update. Be sure to call youtube-dl with the –verbose flag and include its complete output.

File “/usr/local/bin/youtube-dl/youtube_dl/jsinterp.py”, line 182, in interpret_expression

return obj[member](argvals)

KeyError: ‘QV’

已使用2种方法,确保升级到最新版:

youtube-dl is up-to-date (2021.12.17)

错误依旧,此工具方法已失效。


背景

下载视频或者音频越来越复杂,原因之一是现在的网站需要自动适配音视频的质量(声音的采样率和视频的分辨率),单独使用url的下载方法(一些浏览器插件的方法)会导致下载了视频而没有声音。

没有*墙的情况下(又想要下载youtube音视频的话),请忽略本文。(或使用网络加速器访问youtube)

工具

youtube-dl

ffmpeg(可选)

代理(比如socks5。没有*墙的情况下,请忽略本文)

Mac下安装

1. 打开Terminal 输入:

sudo curl -L https://yt-dl.org/downloads/latest/youtube-dl -o /usr/local/bin/youtube-dl

sudo chmod a+rx /usr/local/bin/youtube-dl

2. 下载ffmpeg搭配使用(可选,使用情形之一:使用参数来仅仅下载Youtube中的音频)

下载后,解压缩至相同目录:/usr/local/bin/

赋予权限:sudo chmod a+rx /usr/local/bin/ffmpeg

实例

Terminal运行:

youtube-dl –proxy ‘socks5://127.0.0.1:10804/‘ ‘https://www.youtube.com/watch?v=RrUQoAOC9\_w

使用socks5代理,连接本机的10804端口,去下载视频(包含音频)。

youtube-dl –extract-audio –format bestaudio –proxy ‘socks5://127.0.0.1:10804/‘ ‘https://www.youtube.com/watch?v=RrUQoAOC9\_w

需要ffmpeg支持,使用代理,并仅仅下载音频文件

合并起来的转化成mp4的例子(请将sock5的代理和端口改成你所使用的情况,比如1080):

youtube-dl –proxy ‘socks5://127.0.0.1:10804/‘ ‘https://www.youtube.com/watch?v=5MrM4-4xw7M‘ –format mp4

引用:

教你一招如何将油管上的4K视频放到你的硬盘里https://www.bilibili.com/read/cv9635822

youtube-dl详细使用说明https://github.com/ytdl-org/youtube-dl/blob/master/README.md#options