Skip to content

Instantly share code, notes, and snippets.

@scottj
Created March 9, 2026 21:33
Show Gist options
  • Select an option

  • Save scottj/e476e16ed5cc190092385c118628b225 to your computer and use it in GitHub Desktop.

Select an option

Save scottj/e476e16ed5cc190092385c118628b225 to your computer and use it in GitHub Desktop.
Download and play audio from Youtube
#!/usr/bin/env bash
# create array of links to youtube videos or playlists
declare -a ytLinks=(
"https://youtu.be/dQw4w9WgXcQ"
"https://youtu.be/LLFhKaqnWwk"
)
# ytdl binary name
ytdl=yt-dlp_macos
# update ytdl first
$ytdl -U
# download all the things, extracting audio to mp3
for y in ${ytLinks[@]}; do
$ytdl \
--extract-audio \
--audio-format mp3 \
--ignore-errors \
--download-archive .archive \
--path home:mp3 \
--yes-playlist \
--no-check-certificate \
$y
done
# playlist creation
ls -tr mp3 | awk '{print "mp3/" $0}' > music.m3u
# launch playlist
open music.m3u
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment