Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Download Audio from YouTube with youtube-dl

Download Audio from YouTube

-i - ignore errors

-c - continue

-t - use video title as file name

--extract-audio - extract audio track

--audio-format mp3 - convert to mp3

--audio-quality 0 - the best audio quality

--yes-playlist - affirm that url points to a playlist

YT_URL - video url from youtube

# Download single entry
youtube-dl -i --extract-audio --audio-format mp3 --audio-quality 0 YT_URL

# Download playlist
youtube-dl -ict --yes-playlist --extract-audio --audio-format mp3 --audio-quality 0 https://www.youtube.com/playlist?list=UUCvVpbYRgYjMN7mG7qQN0Pg

# Download playlist, --download-archive downloaded.txt add successfully downloaded files into downloaded.txt
youtube-dl --download-archive downloaded.txt --no-overwrites -ict --yes-playlist --extract-audio --audio-format mp3 --audio-quality 0 --socket-timeout 5 https://www.youtube.com/playlist?list=UUCvVpbYRgYjMN7mG7qQN0Pg

# Retry until success, no -i option
while ! youtube-dl --download-archive downloaded.txt --no-overwrites -ct --yes-playlist --extract-audio --audio-format mp3 --audio-quality 0 --socket-timeout 5 <YT_PlayList_URL>; do echo DISCONNECTED; sleep 5; done
@mzalazar

This comment has been minimized.

Copy link

@mzalazar mzalazar commented May 14, 2018

AWESOME!!! thanks a lot! ;-)

@FredGreen09

This comment has been minimized.

Copy link

@FredGreen09 FredGreen09 commented May 20, 2018

Thanks for sharing your information. It helps me a lot. But I do prefer https://tubegeter.com/ Because this is the easiest way to download videos from YouTube. You can try it.

@UnluckyLuke

This comment has been minimized.

Copy link

@UnluckyLuke UnluckyLuke commented Jun 6, 2018

But you do say that it will convert to MP3. From what format, AAC?

This would make you lose some quality, right?

@giuscri

This comment has been minimized.

Copy link

@giuscri giuscri commented Jun 26, 2018

Use

-o "%(title)s.%(ext)s"

instead of -t option, to avoid the video ID in the filename.

@ariesabao

This comment has been minimized.

Copy link

@ariesabao ariesabao commented Jul 3, 2018

but it says .web not .mp3 ?

@cryptid11

This comment has been minimized.

Copy link

@cryptid11 cryptid11 commented Jul 16, 2018

this doesnt works anymore, at least with some playlist like this one https://www.youtube.com/watch?v=9szNGXja85M&list=RDn4Xp6g-_UUw (notice link https://www.youtube.com/playlist?list=RDn4Xp6g-_UUw doesnt works at all) is this maybe a new move from youtube now miserably try to sell possibility to listen music with screen off?

@creio

This comment has been minimized.

Copy link

@creio creio commented Jul 27, 2018

Aliases bash. youtube.com/arch

Track

mp3 () {
	youtube-dl --ignore-errors -f bestaudio --extract-audio --audio-format mp3 --audio-quality 0 -o '~/Music/youtube/%(title)s.%(ext)s' "$1"
}

mp3 https://www.youtube.com/watch?v=2_b6SpGr4-c

Playlist

mp3p () {
	youtube-dl --ignore-errors -f bestaudio --extract-audio --audio-format mp3 --audio-quality 0 -o '~/Music/youtube/%(playlist)s/%(playlist_index)s - %(title)s.%(ext)s' "$1"
}

album https://www.youtube.com/watch?v=-F7A24f6gNc&list=RD-F7A24f6gNc

dlv () {
	youtube-dl --ignore-errors -o '~/Videos/youtube/%(title)s.%(ext)s' "$1"
}
dlp () {
	youtube-dl --ignore-errors -o '~/Videos/youtube/%(playlist)s/%(title)s.%(ext)s' "$1"
}
@VMatrix1900

This comment has been minimized.

Copy link

@VMatrix1900 VMatrix1900 commented Aug 13, 2018

WARNING: --title is deprecated. Use -o "%(title)s-%(id)s.%(ext)s" instead.
@ischroedi

This comment has been minimized.

Copy link

@ischroedi ischroedi commented Aug 22, 2018

well done friends, thank you for done this stuff :D

@freesmartsoft

This comment has been minimized.

Copy link

@freesmartsoft freesmartsoft commented Sep 5, 2018

as far as i know the web service: https://video-box.org is using youtube-dl on the server side

@norcaljohnny

This comment has been minimized.

Copy link

@norcaljohnny norcaljohnny commented Oct 30, 2018

I get extractor errors for extracting an mp3 unless I use this code
youtube-dl -x --audio-format mp3

@Wiruu

This comment has been minimized.

Copy link

@Wiruu Wiruu commented Jan 31, 2019

hello, the file is saving in the /Users/ directory; is there a way to modify that?

@TomVvV

This comment has been minimized.

Copy link

@TomVvV TomVvV commented Mar 6, 2019

my man

@kaotisk-hund

This comment has been minimized.

Copy link

@kaotisk-hund kaotisk-hund commented Mar 16, 2019

How to do the same thing with code? I have trouble extracting audio from the videos.

@page-work

This comment has been minimized.

Copy link

@page-work page-work commented May 13, 2019

HI guys! Is there a config file for youtube-dl?!

@miguelalcantar

This comment has been minimized.

Copy link

@miguelalcantar miguelalcantar commented May 15, 2019

@myns23

This comment has been minimized.

Copy link

@myns23 myns23 commented Aug 28, 2019

Thank you so match its work for my playlist.. :)

@dagolinuxoid

This comment has been minimized.

Copy link

@dagolinuxoid dagolinuxoid commented Nov 1, 2019

thx

@Mihoid

This comment has been minimized.

Copy link

@Mihoid Mihoid commented Feb 5, 2020

Grazie mille!

@GenericEric

This comment has been minimized.

Copy link

@GenericEric GenericEric commented Dec 16, 2020

Great stuff! Added this to my aliases in aliasrc.
yt="youtube-dl --add-metadata -i"
yta="youtube-dl -i --extract-audio --audio-format-mp3 --audio-auality 0" \

@tdlmatias

This comment has been minimized.

Copy link

@tdlmatias tdlmatias commented Dec 21, 2020

Hi there, I have used very recently youtube-dl to extract a audio as mp3 - obs you need to have ffmpeg for this to work properly.
--> youtube-dl -x --embed-thumbnail --audio-format mp3 https://www.youtube.com/watch?v=VIDEOID

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment