Skip to content

Instantly share code, notes, and snippets.

@FredLackeyOfficial
Created March 1, 2017 16:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FredLackeyOfficial/8c23ad0ab3e115c3069edb911fe873be to your computer and use it in GitHub Desktop.
Save FredLackeyOfficial/8c23ad0ab3e115c3069edb911fe873be to your computer and use it in GitHub Desktop.
Simple bash function to pull down videos and audio tracks from YouTube playlists.
get-tunes(){
local usage="get-tunes %PLAYLIST_OR_VIDEO_URL% [audio-only | video-only]";
local url="$1";
local option="$2";
local prefix="";
if [ -f "/usr/local/bin/youtube-dl" ]; then
prefix="/usr/local/bin/";
fi
if [ -z "${url}" ]; then
echo "Problem fetching track: Track URL not supplied";
echo "$usage";
elif [ -z "${option}" ]; then
echo "Fetching audio & video...";
eval "${prefix}youtube-dl --buffer-size 16K --keep-video --audio-format mp3 --extract-audio --embed-thumbnail --prefer-insecure --format mp4 --ignore-errors --output '%(title)s.%(ext)s' $1";
elif [[ "$option" == "audio-only" ]]; then
echo "Excluding video...";
eval "${prefix}youtube-dl --buffer-size 16K --audio-format mp3 --extract-audio --embed-thumbnail --prefer-insecure --ignore-errors --output '%(title)s.%(ext)s' $1";
elif [[ "$option" == "video-only" ]]; then
echo "Excluding audio...";
eval "${prefix}youtube-dl --buffer-size 16K --keep-video --prefer-insecure --format mp4 --ignore-errors --output '%(title)s.%(ext)s' $1";
else
echo "Problem fetching track: Unknown option supplied ($option)";
echo "$usage";
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment