How to download mp3 tracks from youtube video using youtube dl

Information TechnologyLinux

There are several ways to download MP3 tracks from Youtube such as web applications, windows applications and command line tools in Linux. Youtube-DL is one of the best available tools in the market to download tracks from youtube. It is developed in Python programming language. This program can be used in almost all Linux distributions. If you haven’t heard about this tool then this article is for you.

Installing Youtube-DL

To install youtube-DL, use the following command –

$ sudo wget https://yt-dl.org/downloads/latest/youtube-dl -O /usr/local/bin/youtube-dl

The sample output should be like this –

--2016-03-08 11:41:21-- https://yt-dl.org/downloads/latest/youtube-dl
Resolving yt-dl.org (yt-dl.org)... 95.143.172.170, 2001:1a50:11:0:5f:8f:acaa:177
Connecting to yt-dl.org (yt-dl.org)|95.143.172.170|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://yt-dl.org/downloads/2016.03.06/youtube-dl [following]
--2016-03-08 11:41:23-- https://yt-dl.org/downloads/2016.03.06/youtube-dl
Connecting to yt-dl.org (yt-dl.org)|95.143.172.170|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1133512 (1.1M) [application/octet-stream]
Saving to: ‘/usr/local/bin/youtube-dl’
100%[======================================>] 11,33,512 218KB/s in 6.2s
2016-03-08 11:41:30 (180 KB/s) - ‘/usr/local/bin/youtube-dl’ saved [1133512/1133512]

Change youtube-dl directory permission to access youtube-dl command. To change the directory permission, use the following command –

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

To get more information about youtube-DL use the following command –

# youtube-dl --help

The above command should require root permission and its output should be like this –

Options:

-h, --help                  Print this help text and exit
--version                   Print program version and exit
-U, --update                Update this program to latest version. Make sure that you have sufficient permissions (run with sudo if needed)
-i, --ignore-errors         Continue on download errors, for example to skip unavailable videos in a playlist
--abort-on-error            Abort downloading of further videos (in the playlist or the command line) if an error occurs
--dump-user-agent           Display the current browser identification
--list-extractors           List all supported extractors
--extractor-descriptions    Output descriptions of all supported extractors
--force-generic-extractor   Force extraction to use the generic extractor
--default-search PREFIX     Use this prefix for unqualified URLs. For example "gvsearch2:" downloads two videos from google videos for youtube-dl "large apple". Use the value "auto" to let youtube-dl guess ("auto_warning" to emit a warning when guessing). "error" just throws an error. The default value "fixup_error" repairs broken URLs, but emits an error if this is not possible instead of searching.
--ignore-config             Do not read configuration files. When given in the global configuration file /etc /youtube-dl.conf:           Do not read the user configuration in ~/.config/youtube- dl/config (%APPDATA%/youtube-dl/config.txt on Windows)
--flat-playlist             Do not extract the videos of a playlist, only list them.
--mark-watched              Mark videos watched (YouTube only)
--no-mark-watched           Do not mark videos watched (YouTube only)
--no-color                  Do not emit color codes in output
.........................

Downloading a Video as MP3 Track

To convert music to different audio formats, youtube-dl needs either ffmpeg or avconv, and their help programs ffprobe or avprobe.

To install one of them, use the following command –

$ sudo apt-get install ffmpeg

The sample output should be like this –

Building dependency tree
Reading state information... Done
ffmpeg is already the newest version.
The following packages were automatically installed and are no longer required:
gcc-4.8-base:i386 libasn1-8-heimdal:i386 libasound2:i386
libasound2-plugins:i386 libasyncns0:i386 libavahi-client3:i386
libavahi-common-data:i386 libavahi-common3:i386 libbit-vector-perl
libcapi20-3:i386 libcarp-clan-perl libclass-method-modifiers-perl
libcups2:i386 libdata-random-perl libdate-calc-perl libdate-calc-xs-perl
libdrm-amdgpu1:i386 libdrm-intel1:i386 libdrm-nouveau2:i386
libdrm-radeon1:i386 libedit2:i386 libelf1:i386 libexif12:i386 libexpat1:i386
libffi6:i386 libflac8:i386 libfontconfig1:i386 libfreetype6:i386
libgcrypt11:i386 libgd-perl libgd3:i386 libgif4:i386
libgl1-mesa-dri-lts-wily:i386 libgl1-mesa-glx-lts-wily:i386
libglapi-mesa-lts-wily:i386 libglib2.0-0:i386 libglu1-mesa:i386
libgnome2-gconf-perl libgnutls26:i386 libgpg-error0:i386 libgphoto2-6:i386
libgphoto2-port10:i386 libgssapi-krb5-2:i386 libgssapi3-heimdal:i386
libgstreamer-plugins-base0.10-0:i386 libgstreamer0.10-0:i386
libhcrypto4-heimdal:i386 libheimbase1-heimdal:i386 libheimntlm0-heimdal:i386
libhx509-5-heimdal:i386 libice6:i386 libieee1284-3:i386
..........................

To download MP3 track, use the following command –

$ youtube-dl -x --audio-format mp3 --prefer-ffmpeg https://www.youtube.com/watch?v=jwD4AEVBL6Q

The sample output should be like this –

[youtube] jwD4AEVBL6Q: Downloading webpage
[youtube] jwD4AEVBL6Q: Downloading video info webpage
[youtube] jwD4AEVBL6Q: Extracting video information
[youtube] jwD4AEVBL6Q: Downloading MPD manifest
[download] Destination: Bad Style - Time back-jwD4AEVBL6Q.m4a
[download] 100% of 7.45MiB in 00:08
[ffmpeg] Correcting container in "Bad Style - Time back-jwD4AEVBL6Q.m4a"
[ffmpeg] Destination: Bad Style - Time back-jwD4AEVBL6Q.mp3
Deleting original file Bad Style - Time back-jwD4AEVBL6Q.m4a (pass -k to keep)

The above command uses the below two options –

–extract-audio (short option -x) – Convert video files to audio-only files. –audio-format – specifies the audio format in which the file will be downloaded. The supported audio formats are “best”, “aac”, “vorbis”, “mp3”, “m4a”, “opus”, or “wav”; “best” is set by default.

Downloading Multiple Files from Playlist

To download multiple files from playlist, use the following command –

[youtube:playlist] PL9LUD5Kp855InMnKTaRy3LH3kTIYJyBzs: Downloading webpage
[download] Downloading playlist: Top Tracks - Imagine Dragons
[youtube:playlist] playlist Top Tracks - Imagine Dragons: Downloading 5 videos
[download] Downloading video 1 of 5
[youtube] mWRsgZuwf_8: Downloading webpage
[youtube] mWRsgZuwf_8: Downloading video info webpage
[youtube] mWRsgZuwf_8: Extracting video information
[youtube] mWRsgZuwf_8: Downloading js player en_US-vflteKQR7
[youtube] mWRsgZuwf_8: Downloading js player en_US-vflteKQR7
[download] Destination: Imagine Dragons - Demons (Official)-mWRsgZuwf_8.webm
[download] 100% of 3.38MiB in 00:06
[ffmpeg] Destination: Imagine Dragons - Demons (Official)-mWRsgZuwf_8.mp3
Deleting original file Imagine Dragons - Demons (Official)-mWRsgZuwf_8.webm (pass -k to keep)
[download] Downloading video 2 of 5
[youtube] ktvTqknDobU: Downloading webpage
[youtube] ktvTqknDobU: Downloading video info webpage
[youtube] ktvTqknDobU: Extracting video information
[youtube] ktvTqknDobU: Downloading js player en_US-vflteKQR7
[download] Destination: Imagine Dragons - Radioactive-ktvTqknDobU.webm
[download] 100% of 3.81MiB in 00:01
[ffmpeg] Destination: Imagine Dragons - Radioactive-ktvTqknDobU.mp3
Deleting original file Imagine Dragons - Radioactive-ktvTqknDobU.webm (pass -k to keep)
[download] Downloading video 3 of 5
[youtube] sENM2wA_FTg: Downloading webpage
[youtube] sENM2wA_FTg: Downloading video info webpage
[youtube] sENM2wA_FTg: Extracting video information
[download] Destination: Imagine Dragons - It's Time-sENM2wA_FTg.webm
[download] 100% of 3.81MiB in 00:01
[ffmpeg] Destination: Imagine Dragons - It's Time-sENM2wA_FTg.mp3
Deleting original file Imagine Dragons - It's Time-sENM2wA_FTg.webm (pass -k to keep)
[download] Downloading video 4 of 5
[youtube] w5tWYmIOWGk: Downloading webpage
[youtube] w5tWYmIOWGk: Downloading video info webpage
[youtube] w5tWYmIOWGk: Extracting video information
[download] Destination: Imagine Dragons - On Top Of The World (Official Music Video)-w5tWYmIOWGk.webm
[download] 100% of 3.92MiB in 00:03
[ffmpeg] Destination: Imagine Dragons - On Top Of The World (Official Music Video)-w5tWYmIOWGk.mp3
Deleting original file Imagine Dragons - On Top Of The World (Official Music Video)-w5tWYmIOWGk.webm (pass -k to keep)
[download] Downloading video 5 of 5
[youtube] VP9I8ZUwKpc: Downloading webpage
[youtube] VP9I8ZUwKpc: Downloading video info webpage
[youtube] VP9I8ZUwKpc: Extracting video information
[download] Destination: Imagine Dragons - Warriors (Lyric Video)-VP9I8ZUwKpc.webm
[download] 100% of 2.57MiB in 00:01
[ffmpeg] Destination: Imagine Dragons - Warriors (Lyric Video)-VP9I8ZUwKpc.mp3
Deleting original file Imagine Dragons - Warriors (Lyric Video)-VP9I8ZUwKpc.webm (pass -k to keep)
[download] Finished downloading playlist: Top Tracks - Imagine Dragons

Congratulations! Now, you know “How to Download MP3 Tracks from a YouTube Video Using YouTube-DL”. We’ll learn more about these types of commands in our next Linux post. Keep reading!

raja
Published on 21-Oct-2019 10:39:34
Advertisements