Created
August 21, 2021 18:14
-
-
Save epochblue/814a2f8ca72a60b1bd629ad69660b834 to your computer and use it in GitHub Desktop.
A silly Bash script for playing YouTube audio files on macOS.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# Download the audio from a YouTube video, the play it using the Mac's built-in | |
# `afplay`. | |
# | |
# Note: requires `youtube-tl` (https://github.com/ytdl-org/youtube-dl) | |
# | |
yt_url=$1 | |
tmp_file="/tmp/play.m4a" | |
clean_up_and_exit() { | |
rm "$tmp_file" | |
exit $? | |
} | |
play() { | |
youtube-dl --audio-format=m4a -f 'bestaudio[ext=m4a]' -o "$tmp_file" "$yt_url" 2>&1 > /dev/null | |
afplay "$tmp_file" | |
rm "$tmp_file" | |
} | |
trap clean_up_and_exit SIGINT | |
trap clean_up_and_exit SIGTERM | |
play |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment