Created
April 22, 2020 14:15
-
-
Save rajeshisnepali/06dc1bbc6f61240f7aecbcec2a0da607 to your computer and use it in GitHub Desktop.
Download youtube video/audio from CLI
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 | |
# download video/audio from youtube for another sites | |
#### Format for video | |
#./yt-download.sh 'url' 'specifiy type [video,audio]' 'download_location' | |
URL=$1 | |
DOWNLOAD_AS=${2:-'video'} | |
if [[ -z $(command -v youtube-dl) ]]; then | |
echo 'Downloading youtube-dl'; | |
sudo wget https://yt-dl.org/downloads/latest/youtube-dl -O /usr/local/bin/youtube-dl | |
sudo chmod a+rx /usr/local/bin/youtube-dl | |
fi | |
if [[ $DOWNLOAD_AS == 'video' ]]; then | |
DOWNLOAD_LOCATION=${3:-'~/Videos'} | |
youtube-dl -f 'bestvideo[ext=mp4][height<=1080]+bestaudio[ext=m4a]/bestvideo+bestaudio' --merge-output-format mp4 -o $DOWNLOAD_LOCATION'/%(title)s.%(ext)s' $URL | |
elif [[ $DOWNLOAD_AS == 'audio' ]]; then | |
DOWNLOAD_LOCATION=${3:-'~/Music'} | |
youtube-dl --extract-audio --audio-format mp3 -o $DOWNLOAD_LOCATION'/%(title)s.%(ext)s' $URL | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment