Instead of everytime dealing with youtube downloader websites, actually you can download it yourself. With this bash script you just need to enter the id of a youtube video or playlist, and you can download it.
- You need to download yt-dlp
- I am using mac, so just copied yt-dlp binary to
/usr/local/bin
folder. - Append the code below to your
~/.zprofile
file. (Or what ever bash file that suits you)
For downloading a video copy the video id and execute it like this:
ytv dQw4w9WgXcQ
Or you can download just the audio
yta dQw4w9WgXcQ
You can use it for youtube playlists as well.
ytp PLv1AUcJnyG9vMwxGQUDdWUFYoBownaUnp
- Video ID in a youtube link /watch?v=
aDaOgu2CQtI
- Playlist ID in a youtube playlist /playlist?list=
PLv1AUcJnyG9vMwxGQUDdWUFYoBownaUnp
Playlist function also creates a folder for each item in the playlist.
yt-dlp -o '%(playlist)s/%(playlist_index)s - %(title)s/%(title)s.%(ext)s' \
%(playlist)s
Playlist name%(playlist_index)s
Position number in playlist.%(title)s
Video title%(ext)s
Extension of the video.
Additionally you can make some changes for the final file name. This line below for replacing words, extra spaces etc.
--replace-in-metadata 'title' '^\s+|\s+$' '' \
Save thumnails:
--write-thumbnail
Creates a URL link file.
--write-link
Download subtitles if available.
--write-subs
See more about the parameters here.
ytv(){
yt-dlp -o '%(title)s/%(title)s.%(ext)s' \
--write-thumbnail \
--write-subs \
--write-link \
--quiet \
--write-description \
--progress \
--parse-metadata 'title:%(title)s' \
--replace-in-metadata 'title' 'FULL' '' \
--replace-in-metadata 'title' 'HD' '' \
--replace-in-metadata 'title' ' +' ' ' \
--replace-in-metadata 'title' '^\s+|\s+$' '' \
--exec "if [ -f '%(title)s/%(title)s.%(thumbnails_ext)s' ]; then ext='%(thumbnails_ext)s'; mv '%(title)s/%(title)s.$ext' '%(title)s/backdrop.$ext'; fi" \
"https://www.youtube.com/watch?v=$1"
}
# Download youtube videos as audio with yt-dlp
yta(){
yt-dlp -o '%(title)s/%(title)s.%(ext)s' \
--write-thumbnail \
--write-link \
--quiet \
--write-description \
--extract-audio \
--audio-format mp3 \
--progress \
--parse-metadata 'title:%(title)s' \
"https://www.youtube.com/watch?v=$1"
}
# Download Youtube Playlist with yt-dlp
ytp(){
yt-dlp -o '%(playlist)s/%(playlist_index)s - %(title)s/%(title)s.%(ext)s' \
--write-thumbnail \
--write-subs \
--write-link \
--quiet \
--write-description \
--progress \
--parse-metadata 'title:%(title)s' \
--replace-in-metadata 'title' 'FULL' '' \
--replace-in-metadata 'title' 'HD' '' \
--replace-in-metadata 'title' ' \|$' '' \
"https://www.youtube.com/playlist?list=$1"
}