Last active
December 19, 2021 20:55
-
-
Save clhenrick/4ed063dfabf0ba244c2649e34df5fbeb to your computer and use it in GitHub Desktop.
Downloads and converts a YouTube video to an MP3 file. Credit: https://superuser.com/questions/611881/converting-a-youtube-video-to-mp3-using-ffmpeg-without-youtube-dl
This file contains hidden or 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
#!/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