Ĉ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/lib/yt-channel

187 lines
4.5 KiB
Plaintext
Raw Normal View History

2016-12-26 03:58:01 -06:00
#!/bin/sh
2016-12-11 19:33:57 -06:00
#####################
2016-12-22 19:14:27 -06:00
# Name: yt-channel.sh
2016-12-11 19:33:57 -06:00
# Lisc: ISC
# Main: jadedctrl
2016-12-22 19:14:27 -06:00
# Desc: Display a channel's videos
# or details in easy-to-read
# and easy-to-parse results.
2016-12-11 19:33:57 -06:00
#####################
2016-12-22 19:14:27 -06:00
# Usage: yt-channel.sh [-uci] userid||channel
2016-12-11 19:33:57 -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
else
results=21
fi
2016-12-11 19:33:57 -06:00
2017-01-05 22:38:38 -06:00
if [ -e "./lib/yt-meta" ]
then
alias yt-channel="./lib/yt-channel"
alias yt-search="./lib/yt-down"
alias yt-meta="./lib/yt-meta"
alias yt-search="./lib/yt-search"
alias yt-down="./lib/yt-channel"
alias st-download="./lib/st-download"
alias st-video="./lib/st-video"
fi
2016-12-22 19:14:27 -06:00
interactive_mode=0
channel_file="/tmp/$(mktemp -u yt-channel_XXXXXX)"
2016-12-22 19:14:27 -06:00
# I really need to work out a better way to take flags.
# This is just awful.
# ... I'll cross that bridge later.
2016-12-26 03:58:01 -06:00
if [ "$1" = "-u" ]
2016-12-22 19:14:27 -06:00
then
type="user"
2016-12-26 03:58:01 -06:00
st-download "https://youtube.com/user/$2/videos" "$channel_file"
elif [ "$1" = "-iu" ]
2016-12-11 19:33:57 -06:00
then
2016-12-22 19:14:27 -06:00
output="$3"
2016-12-11 19:33:57 -06:00
interactive_mode=1
2016-12-22 19:14:27 -06:00
type="user"
2016-12-26 03:58:01 -06:00
st-download "https://youtube.com/user/$2/videos" "$channel_file"
elif [ "$1" = "-c" ]
2016-12-22 19:14:27 -06:00
then
type="channel"
2016-12-26 03:58:01 -06:00
st-download "https://youtube.com/channel/$2/videos" "$channel_file"
elif [ "$1" = "-ic" ]
2016-12-22 19:14:27 -06:00
then
2016-12-11 19:33:57 -06:00
output="$3"
2016-12-22 19:14:27 -06:00
interactive_mode=1
type="channel"
2016-12-26 03:58:01 -06:00
st-download "https://youtube.com/channel/$2/videos" "$channel_file"
elif [ "$1" = "-uc" ] || [ -k "$2" ]
2016-12-22 19:14:27 -06:00
then
echo "Usage: yt-channel.sh [-uci] userid||channel [output]"
echo "Make sure to use either the -u flag or the -c flag--"
echo "*not* both! Also, specify a userid or channel name."
exit 1
2016-12-11 19:33:57 -06:00
else
2016-12-22 19:14:27 -06:00
echo "Usage: yt-channel.sh [-uc] userid||channel"
exit 1
2016-12-11 19:33:57 -06:00
fi
2016-12-26 03:58:01 -06:00
get_input() {
2016-12-23 11:12:07 -06:00
printf '\033[0;32m>>>\033[0m '
2016-12-11 19:33:57 -06:00
read -r n
2016-12-26 03:58:01 -06:00
if [ "$n" = "exit" ]
2016-12-11 19:33:57 -06:00
then
exit
fi
2016-12-26 03:58:01 -06:00
test $n -ge 0
2016-12-11 19:33:57 -06:00
if [ $? -gt 1 ]
then
echo "Bad input, mate. Type in a valid number or 'exit'."
get_input
elif [ $n -gt 20 ]
then
echo "Out of range. Type in a valid number or 'exit'."
get_input
elif [ $n -gt 0 ] && [ $n -lt 20 ]
then
2016-12-26 03:58:01 -06:00
sed -n "${n}p" "$temp_file" | sed 's/.*href="\/watch?v=//' | sed 's/".*//' > "$output"
2016-12-11 19:33:57 -06:00
else
echo "Bad input, mate. Type in a valid number or 'exit'."
get_input
fi
}
2016-12-22 19:14:27 -06:00
row=0
2016-12-11 19:33:57 -06:00
# Now for displaying the search results
temp_file="/tmp/$(mktemp -u yt-channel_XXXXXX)"
2016-12-22 19:14:27 -06:00
2016-12-26 03:58:01 -06:00
grep "href=\"\/watch?v=" "$channel_file" | grep "title=" | grep -v \
"<span class=\"yt-thumb-simple\"" > "$temp_file"
2016-12-11 19:33:57 -06:00
item_num=0
2016-12-26 03:58:01 -06:00
cat "$temp_file" | while IFS='' read -r CUR_LINE
2016-12-11 19:33:57 -06:00
do
2016-12-26 03:58:01 -06:00
item_num=$((item_num+1))
LINE="$(echo "$CUR_LINE" | sed 's/<span class=\"yt-badge \" >.*//')"
LINE="$(echo "$LINE" | sed 's/views<\/li>.*//')"
LINE="$(echo "$LINE" | sed 's/title="Verified"//')"
2016-12-11 19:33:57 -06:00
if [ $row -eq 1 ]
then
2016-12-23 11:12:07 -06:00
#color='\033[1;34m'
#color2='\033[1;34m'
printf '\033[1;34m'
2016-12-11 19:33:57 -06:00
row=0
elif [ $row -eq 0 ]
then
2016-12-23 11:12:07 -06:00
#color='\033[1;31m'
#color2='\033[1;31m'
printf '\033[1;31m'
2016-12-11 19:33:57 -06:00
row=1
fi
if echo "$LINE" | grep "View full playlist" > /dev/null
then
type="Playlist"
title=$(echo "$LINE" | sed 's/.*title="//' | sed 's/".*//')
items=$(echo "$LINE" | sed 's/.*View full playlist (//' | sed 's/).*//')
2016-12-23 23:15:53 -06:00
if [ $item_num -ge $((results+1)) ]
then
break
elif [ $item_num -lt 10 ]
then
printf '%s. ' "$item_num"
else
printf '%s. ' "$item_num"
fi
printf '%s' "$title"
printf ' '
printf '%s | %s' "$type" "$items"
printf ' '
2016-12-11 19:33:57 -06:00
else
type="Video"
duration=$(echo "$LINE" | sed 's/.*Duration: //' | sed 's/\..*//')
2016-12-22 19:14:27 -06:00
itemid=$(echo "$LINE" | sed 's/.*href="\/watch?v=//' | sed 's/".*//')
2016-12-11 19:33:57 -06:00
title=$(echo "$LINE" | sed 's/.* title="//' | sed 's/".*//')
2016-12-22 19:14:27 -06:00
2016-12-23 23:15:53 -06:00
if [ $item_num -ge $((results+1)) ]
2016-12-22 19:14:27 -06:00
then
2016-12-23 23:15:53 -06:00
break
elif [ $item_num -lt 10 ]
2016-12-11 19:33:57 -06:00
then
2016-12-23 23:15:53 -06:00
printf '%s. ' "$item_num"
2016-12-11 19:33:57 -06:00
else
2016-12-23 23:15:53 -06:00
printf '%s. ' "$item_num"
2016-12-11 19:33:57 -06:00
fi
2016-12-23 11:12:07 -06:00
echo "$title"
printf ' '
2016-12-11 19:33:57 -06:00
i=0
2016-12-22 19:14:27 -06:00
while [ $i -lt 9 ]
2016-12-11 19:33:57 -06:00
do
i=$((i+1))
2016-12-26 03:58:01 -06:00
char=$(echo "$duration" | cut -c$i)
if [ -z "$char" ]
2016-12-11 19:33:57 -06:00
then
2016-12-23 11:12:07 -06:00
printf ' '
2016-12-11 19:33:57 -06:00
else
2016-12-23 11:12:07 -06:00
printf '%s' "$char"
2016-12-11 19:33:57 -06:00
fi
done
2016-12-23 11:12:07 -06:00
printf ' | %s\n' "$itemid"
2016-12-11 19:33:57 -06:00
fi
done
if [ $interactive_mode -eq 1 ]
then
get_input
fi
2016-12-23 23:15:53 -06:00
printf '\033[0m'
2016-12-11 19:33:57 -06:00
2016-12-26 03:58:01 -06:00
rm "$temp_file"