Ĉ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
Executable File

#####################
# Name: yt-channel.sh
# Date: 2016-12-22
# Lisc: ISC
# Main: jadedctrl
# Desc: Display a channel's videos
# or details in easy-to-read
# and easy-to-parse results.
#####################
# Usage: yt-channel.sh [-uci] userid||channel
interactive_mode=0
channel_file="/tmp/$(mktemp -u yt-channel_XXXXX)"
# 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" ]
then
output="$3"
interactive_mode=1
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
output="$3"
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
else
echo "Usage: yt-channel.sh [-uc] userid||channel"
exit 1
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
sed -n ${n}p $temp_file | sed 's/.*href="\/watch?v=//' | sed 's/".*//' > $output
else
echo "Bad input, mate. Type in a valid number or 'exit'."
get_input
fi
}
row=0
# Now for displaying the search results
temp_file="/tmp/$(mktemp -u yt-channel_XXXXX)"
grep "href=\"\/watch?v=" $channel_file | grep "title=" | grep -v \
"<span class=\"yt-thumb-simple\"" > $temp_file
item_num=0
cat $temp_file | while IFS='' read -r CUR_LINE
do
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"//')"
if [ $row -eq 1 ]
then
#color='\033[1;34m'
#color2='\033[1;34m'
printf '\033[1;34m'
row=0
elif [ $row -eq 0 ]
then
#color='\033[1;31m'
#color2='\033[1;31m'
printf '\033[1;31m'
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/).*//')
printf '%s. %s\n' "$item_num" "$title"
printf '%s | %s | %s\n' "$type" "$items" "$itemid"
else
type="Video"
duration=$(echo "$LINE" | sed 's/.*Duration: //' | sed 's/\..*//')
itemid=$(echo "$LINE" | sed 's/.*href="\/watch?v=//' | sed 's/".*//')
title=$(echo "$LINE" | sed 's/.* title="//' | sed 's/".*//')
if [ $item_num -lt 10 ]
then
printf '%s. ' "$item_num"
elif [ $item_num -lt 20 ]
then
printf '%s. ' "$item_num"
else
break
fi
echo "$title"
printf ' '
i=0
while [ $i -lt 9 ]
do
i=$((i+1))
char=$(echo $duration | cut -c$i)
if [ -z $char ]
then
printf ' '
else
printf '%s' "$char"
fi
done
printf ' | %s\n' "$itemid"
fi
done
if [ $interactive_mode -eq 1 ]
then
get_input
fi
rm $temp_file