139 lines
3.2 KiB
Bash
Executable File
139 lines
3.2 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
####################
|
|
# Name: shelltube.sh
|
|
# Date: 2016-12-11
|
|
# Lisc: ISC
|
|
# Main: jadedctrl
|
|
# Desc: Full-shell YT client that
|
|
# avoids the YT API.
|
|
#####################
|
|
|
|
# Roadmap:
|
|
# v1.0 - [ ] Playlist support
|
|
# [X] Channel support
|
|
# [ ] Audio dl/stream
|
|
# [ ] Show related videos
|
|
# [ ] Channel & Playlist search
|
|
# [ ] Search filters
|
|
# [ ] Search & Channel sort-by
|
|
# [ ] Config video player, etc
|
|
# [ ] Overall better interface
|
|
# [ ] Cli args as commands
|
|
|
|
search() {
|
|
output="$(mktemp /tmp/yt-XXXXXX)"
|
|
yt-search -i "$1" "$output"
|
|
selected_video="$(cat "$output")"
|
|
yt-meta "$selected_video"
|
|
}
|
|
|
|
channel() {
|
|
output="$(mktemp -u /tmp/yt-channel-XXXXXXX)"
|
|
case "$1" in
|
|
UC* )
|
|
yt-channel -ic "$1" "$output"
|
|
;;
|
|
* )
|
|
yt-channel -iu "$1" "$output"
|
|
;;
|
|
esac
|
|
selected_video="$(cat "$output")"
|
|
yt-meta "$selected_video"
|
|
}
|
|
|
|
about() {
|
|
printf '\033[35mShelltube v0.4\033[m\n'
|
|
printf '\033[32mDesc: \033[0;34mYT client written in shell.\033[m\n'
|
|
printf '\033[32mMain: \033[0;34mjadedml@openmailbox.org\033[m\n'
|
|
printf '\033[32mLisc: \033[0;34mISC; yt-down GPLv2\033[m\n'
|
|
}
|
|
|
|
help() {
|
|
printf "\
|
|
about | ! View the about page.
|
|
clear | cls Clear the screen.
|
|
download | dl Download the selected video.
|
|
exit | ctrl+c Exit Shelltube.
|
|
help | ? Display this message.
|
|
metadata | md Display selected video's metadata.
|
|
search | / Perform a search.
|
|
channel | chan Show newest videos of a channel.
|
|
stream | str Stream the selected video.
|
|
video | sel | url Select video based on URL or ID.
|
|
Note about usage:
|
|
Both 'video ID; download' and 'download ID' are valid. You don't need to
|
|
select a video to run commands on it, but if you use metadata, download, or
|
|
stream on an unselected video you must specify the ID or URL after the command.
|
|
"
|
|
}
|
|
|
|
parse() {
|
|
command="$1" argument="$2"
|
|
|
|
case "$command" in
|
|
help | '?' )
|
|
help
|
|
;;
|
|
search )
|
|
search "$argument"
|
|
;;
|
|
/* )
|
|
search "${command#/}"
|
|
;;
|
|
channel )
|
|
channel "$argument"
|
|
;;
|
|
chan )
|
|
channel "$argument"
|
|
;;
|
|
video | sel | url | metadata | md )
|
|
case "$argument" in
|
|
*youtube.com* )
|
|
selected_video="$argument"
|
|
;;
|
|
*)
|
|
selected_video="$argument"
|
|
;;
|
|
esac
|
|
yt-meta "$selected_video"
|
|
;;
|
|
download | dl )
|
|
yt-down "$selected_video"
|
|
;;
|
|
stream | str )
|
|
yt-down -s "$selected_video"
|
|
;;
|
|
about | ! )
|
|
about
|
|
;;
|
|
clear | cls )
|
|
printf '\033[H\033[J'
|
|
;;
|
|
exit )
|
|
rm -f "/tmp/yt-$$"
|
|
exit
|
|
;;
|
|
'' ) ;;
|
|
* )
|
|
printf 'unknown command: "%s"\ntry "help"\n' "$command"
|
|
;;
|
|
esac
|
|
}
|
|
|
|
printf '\n \033[1mshell\033[41m Tube \033[0;1;30m v%s\033[m\n\n' 0.3
|
|
|
|
if [ "$#" -gt 0 ]
|
|
then
|
|
for arg in "$@"
|
|
do
|
|
parse "${arg%% *}" "${arg#* }"
|
|
done
|
|
else
|
|
while printf '\033[0;34m%s \033[0;32m>>\033[m ' "$selected_video"
|
|
do
|
|
read -r command argument
|
|
parse "$command" "$argument"
|
|
done
|
|
fi
|