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 commented May 14, 2018

AWESOME!!! thanks a lot! ;-)

@FredGreen09

This comment has been minimized.

Copy link

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 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 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 commented Jul 3, 2018

but it says .web not .mp3 ?

@cryptid11

This comment has been minimized.

Copy link

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 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 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 commented Aug 22, 2018

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

@freesmartsoft

This comment has been minimized.

Copy link

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 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 commented Jan 31, 2019

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

@ishankhatri90

This comment has been minimized.

Copy link

ishankhatri90 commented Feb 3, 2019

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

First, you need to navigate to the folder in cmd and then start processing.

@TomVvV

This comment has been minimized.

Copy link

TomVvV commented Mar 6, 2019

my man

@kaotisk-hund

This comment has been minimized.

Copy link

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 commented May 13, 2019

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

@miguelalcantar

This comment has been minimized.

Copy link

miguelalcantar commented May 15, 2019

@myns23

This comment has been minimized.

Copy link

myns23 commented Aug 28, 2019

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

@dagolinuxoid

This comment has been minimized.

Copy link

dagolinuxoid commented Nov 1, 2019

thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.