How to Download Audio and Video from Various Video Sites (Including YouTube) Using lux and youtube-dl
An efficient tool for swiftly downloading audio and video, supporting various major video platforms.
November 2023: Transitioning to lux
When within certain restricted networks, the support for downloading YouTube content is not ideal. A solution is provided below:
1 | HTTPS_PROXY="socks5://127.0.0.1:7890" lux "https://www.youtube.com/watch?v=5Dm9XTbnN-M" |
It’s important to note that we now predominantly use HTTPS_PROXY before the command line. Hence, this is the streamlined command:
HTTPS_PROXY=”available proxy address” lux “URL address for music playback”
December 2023 Update: [To be tested]
yt-dlp
An implementation in Python, after youtube-dl ceased development, one fork has now become 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 by using a third-party package manager. For detailed instructions, refer to the wiki.
https://github.com/yt-dlp/yt-dlp?tab=readme-ov-file#readme
1 | [youtube] cEEWJ9LcBXk: Downloading webpage |
Given the extensive disrepair of youtube-dl, alternatives are now being sought, such as you-get or the lux solution. Despite repeated attempts, you-get consistently fails, leading to its abandonment. The transition to lux was thus pursued.
Project link: https://github.com/iawia002/lux
Tested on November 15, 2023, it effortlessly downloads Bilibili videos as well:
1 | lux "https://www.bilibili.com/video/BV1iy4y1u7n3/?vd_source=dabd362cb0c2607dd58ee4300223b109" |
Installation:
1 | $ brew install lux |
All these youtube-dl executable files can be downloaded in the Mac directory: /usr/local/bin. However, using brew to install has led them to another location.
Converting MP4 to MP3 using ffmpeg
ffmpeg -i {input file} {output file}
That simple and straightforward.
Related Content
If you’re interested in related YouTube content, the following resources may be of assistance:
youtube-dl Tool Has Become Inoperative
As of June 20, 2023, testing resulted in an error:
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 objmember
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 objmember
KeyError: ‘QV’
After trying two methods to ensure an update to the latest version:
youtube-dl is up-to-date (2021.12.17)
The error persists, indicating that this tool is no longer functional.
Background
Downloading video or audio has grown increasingly complex, partly due to websites requiring automatic adaption of audio and video quality (audio sampling rate and video resolution). Using just the URL for downloading (as in some browser plugins) often leads to video-only downloads without audio.
In unblocked settings (and for those wanting to download YouTube audio and video), please disregard this article. Alternatively, access YouTube using a network accelerator.
Tools
ffmpeg (optional)
Proxies (e.g., socks5). In unblocked settings, please disregard this.
Installation on Mac
- Open Terminal and type:
sudo curl -L https://yt-dl.org/downloads/latest/youtube-dl -o /usr/local/bin/youtube-dl
1 | sudo chmod a+rx /usr/local/bin/youtube-dl |
\2. Download ffmpeg for use (optional; one potential use is to download only audio from YouTube)
After downloading, extract to the same directory: /usr/local/bin/
Grant permissions: sudo chmod a+rx /usr/local/bin/ffmpeg
Example
Run in Terminal:
youtube-dl –proxy ‘socks5://127.0.0.1:10804/‘ ‘https://www.youtube.com/watch?v=RrUQoAOC9\_w‘
Use a socks5 proxy, connect to the local 10804 port, and download the video (including audio).
youtube-dl –extract-audio –format bestaudio –proxy ‘socks5://127.0.0.1:10804/‘ ‘https://www.youtube.com/watch?v=RrUQoAOC9\_w‘
Requires ffmpeg support, uses a proxy, and downloads only the audio file.
A combined example for converting to mp4 (please adjust the sock5 proxy and port to your specific situation, such as 1080):
youtube-dl –proxy ‘socks5://127.0.0.1:10804/‘ ‘https://www.youtube.com/watch?v=5MrM4-4xw7M‘ –format mp4
Quoted from:
A trick for downloading 4K videos from YouTube to your hard drive https://www.bilibili.com/read/cv9635822
Detailed usage instructions for youtube-dl https://github.com/ytdl-org/youtube-dl/blob/master/README.md#options