Ĉ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

158 lines
3.8 KiB
Plaintext
Raw Normal View History

2016-12-11 19:33:57 -06:00
#####################
2016-12-22 19:14:27 -06:00
# Name: yt-channel.sh
# Date: 2016-12-22
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-22 19:14:27 -06:00
interactive_mode=0
2016-12-23 11:12:07 -06:00
channel_file="/tmp/$(mktemp -u yt-channel_XXXXX)"
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.
if [ "$1" == "-u" ]
then
type="user"
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"
st-download https://youtube.com/user/$2/videos $channel_file
elif [ "$1" == "-c" ]
then
type="channel"
st-download https://youtube.com/channel/$2/videos $channel_file
elif [ "$1" == "-ic" ]
then
2016-12-11 19:33:57 -06:00
output="$3"
2016-12-22 19:14:27 -06:00
interactive_mode=1
type="channel"
st-download https://youtube.com/channel/$2/videos $channel_file
elif [ "$1" == "-uc" ] || [ -k "$2" ]
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
function 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
if [ "$n" == "exit" ]
then
exit
fi
test $n -ge 0 &> /dev/null
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-22 19:14:27 -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
2016-12-23 11:12:07 -06:00
temp_file="/tmp/$(mktemp -u yt-channel_XXXXX)"
2016-12-22 19:14:27 -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
cat $temp_file | while IFS='' read -r CUR_LINE
do
2016-12-22 19:14:27 -06:00
item_num=$(($item_num+1))
2016-12-11 19:33:57 -06:00
LINE="$(echo $CUR_LINE | sed 's/<span class=\"yt-badge \" >.*//')"
LINE="$(echo $LINE | sed 's/views<\/li>.*//')"
LINE="$(echo $LINE | sed 's/title="Verified"//')"
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 11:12:07 -06:00
printf '%s. %s\n' "$item_num" "$title"
printf '%s | %s | %s\n' "$type" "$items" "$itemid"
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
if [ $item_num -lt 10 ]
then
2016-12-23 11:12:07 -06:00
printf '%s. ' "$item_num"
2016-12-22 19:14:27 -06:00
elif [ $item_num -lt 20 ]
2016-12-11 19:33:57 -06:00
then
2016-12-23 11:12:07 -06:00
printf '%s. ' "$item_num"
2016-12-11 19:33:57 -06:00
else
2016-12-22 19:14:27 -06:00
break
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))
char=$(echo $duration | cut -c$i)
if [ -z $char ]
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
rm $temp_file