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
|
|
|
|
channel_file="/tmp/yt-channel_$RANDOM"
|
|
|
|
|
|
|
|
# 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() {
|
|
|
|
printf "\033[0;32m>>>\033[0m "
|
|
|
|
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-22 19:14:27 -06:00
|
|
|
temp_file="/tmp/yt-channel_$RANDOM"
|
|
|
|
|
|
|
|
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
|
|
|
|
color='\033[1;34m'
|
|
|
|
color2='\033[1;34m'
|
|
|
|
row=0
|
|
|
|
elif [ $row -eq 0 ]
|
|
|
|
then
|
|
|
|
color='\033[1;31m'
|
|
|
|
color2='\033[1;31m'
|
|
|
|
row=1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if echo "$LINE" | grep "View full playlist" > /dev/null
|
|
|
|
then
|
|
|
|
type="Playlist"
|
2016-12-22 19:14:27 -06:00
|
|
|
printf "${color}$item_num. "
|
2016-12-11 19:33:57 -06:00
|
|
|
title=$(echo "$LINE" | sed 's/.*title="//' | sed 's/".*//')
|
|
|
|
items=$(echo "$LINE" | sed 's/.*View full playlist (//' | sed 's/).*//')
|
|
|
|
echo -e "${color}$title"
|
|
|
|
echo -e "${color2}$type | $items | $itemid"
|
|
|
|
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
|
|
|
|
printf "${color}$item_num. "
|
|
|
|
elif [ $item_num -lt 20 ]
|
2016-12-11 19:33:57 -06:00
|
|
|
then
|
2016-12-22 19:14:27 -06:00
|
|
|
printf "${color}$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
|
|
|
|
echo -e "${color}$title${color2}"
|
|
|
|
printf " "
|
|
|
|
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
|
|
|
|
printf " "
|
|
|
|
else
|
|
|
|
printf "$char"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
printf " | $itemid\n"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ $interactive_mode -eq 1 ]
|
|
|
|
then
|
|
|
|
get_input
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
rm $temp_file
|