Created
March 1, 2017 16:27
-
-
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.
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
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