Skip to content

Instantly share code, notes, and snippets.

@clhenrick
Last active December 19, 2021 20:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clhenrick/4ed063dfabf0ba244c2649e34df5fbeb to your computer and use it in GitHub Desktop.
Save clhenrick/4ed063dfabf0ba244c2649e34df5fbeb to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
# dependencies:
# - youtube-dl: https://ytdl-org.github.io/youtube-dl/
# - ffmpeg: https://ffmpeg.org/
# make sure youtube-dl dep exists
if ! command -v youtube-dl &> /dev/null
then
echo "required dependency youtube-dl not found, exiting."
exit 1
fi
# $1 is an env variable for the URL of the YouTube video being downloaded
if [[ $1 ]]
then
echo "Downloading and converting YouTube video for $1..."
# -x = Convert video files to audio-only files
# --audio-format mp3 = convert to mp3 file format
youtube-dl -x --audio-format mp3 $1
exit 0
else
echo "usage: ./youtube-to-mp3.sh <url>"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment