Skip to content

Instantly share code, notes, and snippets.

@Phate6660
Last active February 28, 2020 22:12
Show Gist options
  • Save Phate6660/7617dace4020ad420a7fb322004a8dc7 to your computer and use it in GitHub Desktop.
Save Phate6660/7617dace4020ad420a7fb322004a8dc7 to your computer and use it in GitHub Desktop.
A shitty script for youtube playback and downloading using youtube-dl and mpv.
#!/bin/bash
### Foreward
##
## This script is most likely shit, and you'd be better off making your own.
##
### Functions
play() {
echo -e "
What would you like to play?
1. Video
2. Song
3. Nevermind, Go Back
"
read -p "> " ans2
case $ans2 in
1)
echo -e "
What would you like to do?
1. Play from URL
2. Play from search
3. Nevermind, Go Back
"
read -p "> " ans3
case $ans3 in
1)
echo "Please input the URL."
read -p "> " ans4
mpv "$ans4"
exit 0
;;
2)
echo "Please input your search."
read -p "> " ans5
ans5="${ans5// /+}"
mpv "ytdl://ytsearch:$ans5"
exit 0
;;
3) play;;
esac;;
2)
echo -e "
What would you like to do?
1. Play from URL
2. Play from search
3. Nevermind, Go Back
"
read -p "> " ans6
case $ans6 in
1)
echo "Please input the URL."
read -p "> " ans7
mpv "$ans7" --ytdl-format bestaudio
exit 0
;;
2)
echo "Please input your search."
read -p "> " ans8
ans8="${ans8// /+}"
mpv "ytdl://ytsearch:$ans8" --ytdl-format bestaudio
exit 0
;;
3) play;;
esac;;
3) main;;
esac
}
download() {
echo "Download location defaults to \"$HOME/.youtube\"."
dir="$HOME/.youtube"
[[ -d "$dir" ]] || mkdir "$dir"
cd "$dir"
clear && echo -e "
How would you like to download?
1. Through URL.
2. Through search.
3. Verify current directory.
4. Quit
"
read -p "> " ans10
case $ans10 in
1)
echo "Please input the URL."
read -p "> " ans11
youtube-dl \
--write-thumbnail \
--add-metadata \
--format "bestvideo[height<=?1080][fps<=?60][vcodec!=vp9]+bestaudio/best" \
-o "%(uploader)s/%(title)s.%(ext)s" \
"$ans11"
exit 0
;;
2)
echo "Please input your search."
read -p "> " ans11
ans11="${ans11// /+}"
youtube-dl \
--write-thumbnail \
--add-metadata \
--format "bestvideo[height<=?1080][fps<=?60][vcodec!=vp9]+bestaudio/best" \
-o "%(uploader)s/%(title)s.%(ext)s" \
"ytsearch://$ans11"
exit 0
;;
3) echo "The current working directory is $(pwd)." && sleep 3 && download;;
4) exit 1;;
esac
}
download_playlist() {
echo "Download location defaults to \"$HOME/.youtube\"."
dir="$HOME/.youtube"
[[ -d "$dir" ]] || mkdir "$dir"
cd "$dir"
clear && echo -e "
How would you like to download?
1. Through URL.
2. Through search.
3. Verify current directory.
4. Quit
"
read -p "> " ans12
case $ans12 in
1)
echo "Please input the URL."
read -p "> " ans13
youtube-dl \
--write-thumbnail \
--add-metadata \
--format "bestvideo[height<=?1080][fps<=?60][vcodec!=vp9]+bestaudio/best" \
-o "%(uploader)s/%(playlist)s/%(playlist_index)s. %(title)s.%(ext)s" \
"$ans13"
exit 0
;;
2)
echo "Please input your search."
read -p "> " ans14
ans14="${ans14// /+}"
youtube-dl \
--write-thumbnail \
--add-metadata \
--format "bestvideo[height<=?1080][fps<=?60][vcodec!=vp9]+bestaudio/best" \
-o "%(uploader)s/%(playlist)s/%(playlist_index)s. %(title)s.%(ext)s" \
"ytsearch://$ans14"
exit 0
;;
3) echo "The current working directory is $(pwd)." && sleep 3 && download_playlist;;
4) exit 1;;
esac
}
main() {
clear
echo -e "
What would you like to do?
1. Play
2. Download (Single)
3. Download (Playlist)
4. Quit
"
read -p "> " ans
case $ans in
1) clear && play;;
2) clear && download;;
3) clear && download_playlist;;
4) clear && exit 1;;
esac
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment