24 / 05 / 30

下载youtube视频

最开始是用的之前了解的一个工具 youtube_dl,但报错了。

$ pip3 install --upgrade youtube_dl $ youtube-dl --verbose -cit https://www.youtube.com/playlist\?list\=PLXE2Bj4edhg7mmm1MQV2S6NFtpT6MOBh0 # failed $ youtube-dl --verbose https://www.youtube.com/playlist\?list\=PLXE2Bj4edhg7mmm1MQV2S6NFtpT6MOBh0 [debug] System config: [] [debug] User config: [] [debug] Custom config: [] [debug] Command-line args: ['--verbose', 'https://www.youtube.com/playlist?list=PLXE2Bj4edhg7mmm1MQV2S6NFtpT6MOBh0'] [debug] Encodings: locale UTF-8, fs utf-8, out utf-8, pref UTF-8 [debug] youtube-dl version 2021.12.17 [debug] Python version 3.10.8 (CPython) - macOS-14.5-x86_64-i386-64bit [debug] exe versions: rtmpdump 2.4 [debug] Proxy map: {'no': 'localhost,127.0.0.1,localaddress,.localdomain.com', 'http': 'http://127.0.0.1:7890', 'https': 'http://127.0.0.1:7890'} [youtube:tab] PLXE2Bj4edhg7mmm1MQV2S6NFtpT6MOBh0: Downloading webpage [download] Downloading playlist: Rust Projects [youtube:tab] Downloading page 1 [youtube:tab] playlist Rust Projects: Downloading 75 videos [download] Downloading video 1 of 75 [youtube] ygL_xcavzQ4: 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; see https://yt-dl.org/update on how to update. Be sure to call youtube-dl with the --verbose flag and include its complete output. Traceback (most recent call last): File "/usr/local/lib/python3.10/site-packages/youtube_dl/YoutubeDL.py", line 815, in wrapper return func(self, *args, **kwargs) File "/usr/local/lib/python3.10/site-packages/youtube_dl/YoutubeDL.py", line 836, in __extract_info ie_result = ie.extract(url) File "/usr/local/lib/python3.10/site-packages/youtube_dl/extractor/common.py", line 534, in extract ie_result = self._real_extract(url) File "/usr/local/lib/python3.10/site-packages/youtube_dl/extractor/youtube.py", line 1794, in _real_extract 'uploader_id': self._search_regex(r'/(?:channel|user)/([^/?&#]+)', owner_profile_url, 'uploader id') if owner_profile_url else None, File "/usr/local/lib/python3.10/site-packages/youtube_dl/extractor/common.py", line 1012, in _search_regex raise RegexNotFoundError('Unable to extract %s' % _name) youtube_dl.utils.RegexNotFoundError: Unable to extract uploader id; please report this issue on https://yt-dl.org/bug . Make sure you are using the latest version; see https://yt-dl.org/update on how to update. Be sure to call youtube-dl with the --verbose flag and include its complete output.

解决不了。。。

那只能是网上搜索穷举各种办法了。

在Stack Overflow看到一个帖子,也是这个问题,但指向安装另一个包(一开始我还以为跟上面同一个包但不同的版本)。

$ python3 -m pip install --force-reinstall https://github.com/yt-dlp/yt-dlp/archive/master.tar.gz Looking in indexes: https://mirrors.aliyun.com/pypi/simple/ Collecting https://github.com/yt-dlp/yt-dlp/archive/master.tar.gz Downloading https://github.com/yt-dlp/yt-dlp/archive/master.tar.gz (2.6 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.6/2.6 MB 259.3 kB/s eta 0:00:00 Installing build dependencies ... done Getting requirements to build wheel ... done Preparing metadata (pyproject.toml) ... done Collecting brotli (from yt-dlp==2024.5.27) Downloading https://mirrors.aliyun.com/pypi/packages/dd/11/afc14026ea7f44bd6eb9316d800d439d092c8d508752055ce8d03086079a/Brotli-1.1.0-cp310-cp310-macosx_10_9_x86_64.whl (446 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 446.2/446.2 kB 125.6 kB/s eta 0:00:00 Collecting certifi (from yt-dlp==2024.5.27) Downloading https://mirrors.aliyun.com/pypi/packages/ba/06/a07f096c664aeb9f01624f858c3add0a4e913d6c96257acb4fce61e7de14/certifi-2024.2.2-py3-none-any.whl (163 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 163.8/163.8 kB 120.0 kB/s eta 0:00:00 Collecting mutagen (from yt-dlp==2024.5.27) Downloading https://mirrors.aliyun.com/pypi/packages/b0/7a/620f945b96be1f6ee357d211d5bf74ab1b7fe72a9f1525aafbfe3aee6875/mutagen-1.47.0-py3-none-any.whl (194 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 194.4/194.4 kB 124.7 kB/s eta 0:00:00 Collecting pycryptodomex (from yt-dlp==2024.5.27) Downloading https://mirrors.aliyun.com/pypi/packages/4c/c4/9b1e8fca01c4b5a0e1c6f52ba19478b2692af4694afe8c89ebbe24348604/pycryptodomex-3.20.0-cp35-abi3-macosx_10_9_x86_64.whl (1.6 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.6/1.6 MB 125.4 kB/s eta 0:00:00 Collecting requests<3,>=2.31.0 (from yt-dlp==2024.5.27) Downloading https://mirrors.aliyun.com/pypi/packages/c3/20/748e38b466e0819491f0ce6e90ebe4184966ee304fe483e2c414b0f4ef07/requests-2.32.2-py3-none-any.whl (63 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 63.9/63.9 kB 117.8 kB/s eta 0:00:00 Collecting urllib3<3,>=1.26.17 (from yt-dlp==2024.5.27) Downloading https://mirrors.aliyun.com/pypi/packages/a2/73/a68704750a7679d0b6d3ad7aa8d4da8e14e151ae82e6fee774e6e0d05ec8/urllib3-2.2.1-py3-none-any.whl (121 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 121.1/121.1 kB 123.3 kB/s eta 0:00:00 Collecting websockets>=12.0 (from yt-dlp==2024.5.27) Downloading https://mirrors.aliyun.com/pypi/packages/bb/d3/1eca0d8fb6f0665c96f0dc7c0d0ec8aa1a425e8c003e0c18e1451f65d177/websockets-12.0-cp310-cp310-macosx_10_9_x86_64.whl (121 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 121.3/121.3 kB 125.3 kB/s eta 0:00:00 Collecting charset-normalizer<4,>=2 (from requests<3,>=2.31.0->yt-dlp==2024.5.27) Downloading https://mirrors.aliyun.com/pypi/packages/cc/94/f7cf5e5134175de79ad2059edf2adce18e0685ebdb9227ff0139975d0e93/charset_normalizer-3.3.2-cp310-cp310-macosx_10_9_x86_64.whl (122 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 122.5/122.5 kB 115.6 kB/s eta 0:00:00 Collecting idna<4,>=2.5 (from requests<3,>=2.31.0->yt-dlp==2024.5.27) Downloading https://mirrors.aliyun.com/pypi/packages/e5/3e/741d8c82801c347547f8a2a06aa57dbb1992be9e948df2ea0eda2c8b79e8/idna-3.7-py3-none-any.whl (66 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 66.8/66.8 kB 114.0 kB/s eta 0:00:00 Building wheels for collected packages: yt-dlp Building wheel for yt-dlp (pyproject.toml) ... done Created wheel for yt-dlp: filename=yt_dlp-2024.5.27-py3-none-any.whl size=2846509 sha256=08afbee9e62b82058ec8507fb49512011ea7562caa3238f16eca15deb45a3a75 Stored in directory: /private/var/folders/bj/nw1w4g1j37ddpgb6zmh3sfh80000gn/T/pip-ephem-wheel-cache-p4hmqhm0/wheels/4c/91/d1/c5369304e2f7afb660bb6eee093af5a7d3c0ea05a3c1e8c797 Successfully built yt-dlp Installing collected packages: brotli, websockets, urllib3, pycryptodomex, mutagen, idna, charset-normalizer, certifi, requests, yt-dlp Attempting uninstall: websockets Found existing installation: websockets 10.4 Uninstalling websockets-10.4: Successfully uninstalled websockets-10.4 Attempting uninstall: urllib3 Found existing installation: urllib3 1.26.15 Uninstalling urllib3-1.26.15: Successfully uninstalled urllib3-1.26.15 Attempting uninstall: idna Found existing installation: idna 3.4 Uninstalling idna-3.4: Successfully uninstalled idna-3.4 Attempting uninstall: charset-normalizer Found existing installation: charset-normalizer 3.1.0 Uninstalling charset-normalizer-3.1.0: Successfully uninstalled charset-normalizer-3.1.0 Attempting uninstall: certifi Found existing installation: certifi 2022.12.7 Uninstalling certifi-2022.12.7: Successfully uninstalled certifi-2022.12.7 Attempting uninstall: requests Found existing installation: requests 2.32.2 Uninstalling requests-2.32.2: Successfully uninstalled requests-2.32.2 Successfully installed brotli-1.1.0 certifi-2024.2.2 charset-normalizer-3.3.2 idna-3.7 mutagen-1.47.0 pycryptodomex-3.20.0 requests-2.32.2 urllib3-2.2.1 websockets-12.0 yt-dlp-2024.5.27

这个包的用法其实蛮简单的,探索后用以下的命令下载视频。

yt-dlp -R infinite --verbose https://www.youtube.com/playlist\?list\=PLXE2Bj4edhg7mmm1MQV2S6NFtpT6MOBh0

这里使用了-R infinite无限次重启续传下载视频,因为下载很容易终端,默认的10次完全不够。

需要注意的是,它会利用 ffmpeg 对下面的视频进行一些整合操作。所以需要安装:

https://evermeet.cx/ffmpeg/

Powered by Gridea