Ĉi tiu deponejo arĥiviĝis je 2024-01-29. Vi povas vidi kaj elŝuti dosierojn, sed ne povas puŝi nek raporti problemojn nek tirpeti.
shellTube/shelltube

210 lines
5.1 KiB
Plaintext
Raw Normal View History

2016-12-22 19:14:27 -06:00
#!/bin/sh
2016-12-11 19:33:57 -06:00
####################
# Name: shelltube.sh
# Lisc: ISC
# Main: jadedctrl
2016-12-23 12:37:20 -06:00
# Desc: Full-shell YT client that avoids the YT API.
2017-01-08 00:10:36 -06:00
Vers=0.5.1
2016-12-11 19:33:57 -06:00
#####################
2016-12-22 19:14:27 -06:00
# Roadmap:
2017-01-05 23:57:29 -06:00
# v1.0 - [X] Playlist support
2016-12-22 19:14:27 -06:00
# [X] Channel support
# [ ] Audio dl/stream
# [ ] Show related videos
2017-01-07 12:09:38 -06:00
# [|] Channel & Playlist search
2016-12-22 19:14:27 -06:00
# [ ] Search filters
# [ ] Search & Channel sort-by
2016-12-23 23:15:53 -06:00
# [X] Config video player, etc
2016-12-22 19:14:27 -06:00
# [ ] Overall better interface
2016-12-26 03:58:01 -06:00
# [x] Cli args as commands
2016-12-22 19:14:27 -06:00
2016-12-26 03:58:01 -06:00
if [ -e "$HOME/.config/shelltube" ]
2016-12-23 23:15:53 -06:00
then
2016-12-26 03:58:01 -06:00
. "$HOME/.config/shelltube"
2016-12-23 23:15:53 -06:00
fi
2017-01-05 22:38:38 -06:00
if [ -e "./lib/yt-meta" ]
then
alias yt-channel="./lib/yt-channel"
alias yt-meta="./lib/yt-meta"
2017-01-05 23:57:29 -06:00
alias yt-playlist="./lib/yt-playlist"
2017-01-05 22:38:38 -06:00
alias yt-search="./lib/yt-search"
2017-01-05 23:57:29 -06:00
alias yt-down="./lib/yt-down"
2017-01-05 22:38:38 -06:00
alias st-download="./lib/st-download"
alias st-video="./lib/st-video"
fi
search() {
output="$(mktemp -u /tmp/yt_XXXXXX)"
yt-search -i "$1" "$output"
2017-01-08 00:10:36 -06:00
if sed -n ${1}p "$output" | grep "^PL" > /dev/null
2017-01-07 11:07:16 -06:00
then
2017-01-08 00:10:36 -06:00
playlist "$(sed -n ${1}p "$output")"
2017-01-07 11:07:16 -06:00
else
2017-01-08 00:10:36 -06:00
selected_video="$(sed -n ${1}p "$output")"
2017-01-07 11:07:16 -06:00
yt-meta "$selected_video"
fi
2016-12-11 19:33:57 -06:00
}
2017-01-05 23:57:29 -06:00
playlist() {
output="$(mktemp -u /tmp/yt_XXXXXX)"
yt-playlist -i "$1" "$output"
2017-01-07 12:09:38 -06:00
selected_video="$(sed -n ${1}p "$output")"
2017-01-05 23:57:29 -06:00
yt-meta "$selected_video"
}
channel() {
output="$(mktemp -u /tmp/yt-channel_XXXXXX)"
case "$1" in
UC* )
yt-channel -ic "$1" "$output"
;;
* )
yt-channel -iu "$1" "$output"
;;
esac
2017-01-08 00:10:36 -06:00
selected_video="$(sed -n 1p "$output")"
2016-12-22 19:14:27 -06:00
yt-meta "$selected_video"
2016-12-11 19:33:57 -06:00
}
about() {
2017-01-05 23:57:29 -06:00
printf '\n \033[1mshell\033[41m Tube \033[0;1;30m v%s\033[m\n\n' "$Vers"
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'
2016-12-11 19:33:57 -06:00
}
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.
2017-01-05 23:57:29 -06:00
playlist | // Display a playlist's videos.
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.
2017-01-08 00:10:36 -06:00
queue | lq List videos in the queue.
squeue | sq Stream all videos in the queue.
dqueue | dq Download all videos in the queue.
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.
"
2016-12-11 19:33:57 -06:00
}
parse() {
command="$1" argument="$2"
case "$command" in
help | '?' )
2016-12-11 19:33:57 -06:00
help
;;
2017-01-05 23:57:29 -06:00
playlist )
playlist "$argument"
;;
//* )
playlist "${command#//}"
;;
search )
search "$argument"
;;
/* )
2016-12-23 23:15:53 -06:00
search "${command#/} $argument"
;;
channel )
channel "$argument"
;;
chan )
channel "$argument"
;;
2016-12-23 13:35:58 -06:00
video | sel | url )
case "$argument" in
*youtube.com* )
selected_video="$argument"
;;
*)
selected_video="$argument"
;;
esac
yt-meta "$selected_video"
;;
2016-12-23 13:35:58 -06:00
metadata | md )
selected_video="${argument:-$selected_video}"
yt-meta "$selected_video"
;;
download | dl )
2016-12-23 13:35:58 -06:00
selected_video="${argument:-$selected_video}"
yt-down "$selected_video"
;;
stream | str )
2016-12-23 13:35:58 -06:00
selected_video="${argument:-$selected_video}"
yt-down -s "$selected_video"
;;
2017-01-07 12:09:38 -06:00
queue | lq )
cat /tmp/yt-queue | while IFS='' read -r CUR_LINE
do
yt-meta "$CUR_LINE"
done
;;
cqueue | cq )
rm /tmp/yt-queue
touch /tmp/yt-queue
;;
dqueue | dq )
for LINE in $(cat /tmp/yt-queue)
do
2017-01-08 00:10:36 -06:00
yt-down -D "$LINE"
grep -v "$LINE" /tmp/yt-queue > /tmp/yt-queue.tmp
mv /tmp/yt-queue.tmp /tmp/yt-queue
2017-01-07 12:09:38 -06:00
done
;;
squeue | sq )
for LINE in $(cat /tmp/yt-queue)
do
2017-01-08 00:10:36 -06:00
yt-down -S "$LINE"
grep -v "$LINE" /tmp/yt-queue > /tmp/yt-queue.tmp
mv /tmp/yt-queue.tmp /tmp/yt-queue
2017-01-07 12:09:38 -06:00
done
;;
about | ! )
2016-12-11 19:33:57 -06:00
about
;;
clear | cls )
printf '\033[H\033[J'
;;
exit )
rm -f "/tmp/yt-$$"
2016-12-11 19:33:57 -06:00
exit
;;
'' ) ;;
* )
2017-01-07 11:07:16 -06:00
echo "Unknown command: \"$command\""
echo "Try \"help\" or \"?\""
;;
esac
2016-12-11 19:33:57 -06:00
}
if [ "$#" -gt 0 ]
then
for arg in "$@"
do
parse "${arg%% *}" "${arg#* }"
done
else
2016-12-23 12:37:20 -06:00
printf '\n \033[1mshell\033[41m Tube \033[0;1;30m v%s\033[m\n\n' "$Vers"
2016-12-23 11:12:07 -06:00
while printf '\033[0;34m%s \033[0;32m>>\033[m ' "$selected_video"
do
read -r command argument
parse "$command" "$argument"
done
fi