Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save umidjons/8a15ba3813039626553929458e3ad1fc to your computer and use it in GitHub Desktop.
Save umidjons/8a15ba3813039626553929458e3ad1fc to your computer and use it in GitHub Desktop.
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
Copy link

AWESOME!!! thanks a lot! ;-)

@FredGreen09
Copy link

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
Copy link

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

This would make you lose some quality, right?

@giuscri
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
Copy link

but it says .web not .mp3 ?

@cryptid11
Copy link

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
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
Copy link

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

@ischroedi
Copy link

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

@freesmartsoft
Copy link

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

@norcaljohnny
Copy link

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

@proxymurder
Copy link

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

@TomVvV
Copy link

TomVvV commented Mar 6, 2019

my man

@kaotisk-hund
Copy link

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

@page-work
Copy link

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

@miguelalcantar
Copy link

@myns23
Copy link

myns23 commented Aug 28, 2019

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

@dagolinuxoid
Copy link

thx

@Mihoid
Copy link

Mihoid commented Feb 5, 2020

Grazie mille!

@GenericEric
Copy link

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
Copy link

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

@nawaljahmed
Copy link

thank you, simple and useful

@rcortezk9
Copy link

When using the following command I'm getting an error.

youtube-dl -i --extract-audio --audio-format mp3 --audio-quality 0 YT_URL (This happens with any YouTube URL I use)

ERROR: ffprobe/avprobe and ffmpeg/avconv not found. Please install one.

How can ffprobe/avprobe and ffmpeg/avconv?

@tdlmatias
Copy link

tdlmatias commented Jul 23, 2021

When using the following command I'm getting an error.

youtube-dl -i --extract-audio --audio-format mp3 --audio-quality 0 YT_URL (This happens with any YouTube URL I use)

ERROR: ffprobe/avprobe and ffmpeg/avconv not found. Please install one.

How can ffprobe/avprobe and ffmpeg/avconv?

Hi @rcortezk9 have installed ffmpeg on your system ?? Try to install then run the command again.. If you in Linux/Ubuntu

-$ sudo apt-get install ffmpeg,

  • or $ snap install ffmpeg
  • or if you on Mac - do $ brew install ffmpeg

Bear in mind that you need to have Snap installed or Brew for it work**

@t1u1
Copy link

t1u1 commented Dec 31, 2021

What about -f bestaudio? That seems to download the audio only version for me. The format is opus in webm container, not mp3, but that's okay with me, as most players work with it. I can convert to mp3 later if required.

@neiesc
Copy link

neiesc commented Jun 15, 2022

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