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
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: Autumn Farewell
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 Autumn Farewell.mp4

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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[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>'

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
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 bilibili.com
Title: [Hell's Hotel/Hazbin Hotel][Second Edition]"Madman" - Alastor's Song
Type: video
Stream:
[32-7] -------------------
Quality: Clear 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 [Hell's Hotel Hazbin Hotel][Second Edition]"Madman" - Alastor's Song.mp4


# Conversion to mp3 after download
ffmpeg -i "[Hell's Hotel Hazbin Hotel][Second Edition]"Madman" - Alastor's Song.mp4" "Hell's Hotel-Madman.mp3"

Installation:

1
2
3
4
5
$ brew install lux

Assuming the command operates smoothly and downloads the latest lux version in a globally unblocked setting
lux --version
lux: version v0.0.0, A fast and simple video downloader.

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

youtube-d-l

ffmpeg (optional)

Proxies (e.g., socks5). In unblocked settings, please disregard this.

Installation on Mac

  1. 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