Added channel support

This commit is contained in:
Jaidyn Ann 2016-12-22 19:14:27 -06:00
parent 5ecf3515bd
commit d0585eef1f
8 changed files with 271 additions and 30 deletions

4
INSTALL.md Normal file
View File

@ -0,0 +1,4 @@
Simple. Just move the "shelltube" script along with
the scripts in lib/ into your PATH.
Then-- boom, installed.
Groovy.

23
lib/st-download Executable file
View File

@ -0,0 +1,23 @@
#!/bin/sh
#####################
# Name: st-download.sh
# Date: 2016-12-22
# Lisc: ISC
# Main: jadedctrl
# Desc: No beer and no TV
# make Homer go
# something-something
# Cxu ne?
#####################
if type "wget" &> /dev/null
then
wget -q "$1" -O "$2"
elif type "curl" &> /dev/null
then
curl -s "$1" -o "$2"
else
echo "Please install wget or curl."
sleep 2
exit 1
fi

28
lib/st-video Executable file
View File

@ -0,0 +1,28 @@
#!/bin/sh
#####################
# Name: st-video.sh
# Date: 2016-12-22
# Lisc: ISC
# Main: jadedctrl
# Desc: Does a thing with
# a video-thingy thing
# dsfgbvesrht fd
#####################
if type "vlc" &> /dev/null
then
vlc "${1}"
elif type "mplayer" &> /dev/null
then
mplayer "${1}"
elif type "kaffeine" &> /dev/null
then
kaffeine "${2}"
else
sleep 2
echo "Please install either vlc, mplayer, or kaffeine."
exit 1
fi
# Mi sxatas iom da komputoro
# ... sed, gxi estas tre bona kaj mojosas

156
lib/yt-channel Executable file
View File

@ -0,0 +1,156 @@
#####################
# 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/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" ]
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/yt-channel_$RANDOM"
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'
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"
printf "${color}$item_num. "
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/\..*//')
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 "${color}$item_num. "
elif [ $item_num -lt 20 ]
then
printf "${color}$item_num. "
else
break
fi
echo -e "${color}$title${color2}"
printf " "
i=0
while [ $i -lt 9 ]
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

2
yt-down.sh → lib/yt-down Normal file → Executable file
View File

@ -43,7 +43,7 @@ function select_option ()
line=$((line+1)) line=$((line+1))
echo "${line}. $i" echo "${line}. $i"
done done
printf "\033[0;32m>>\033[0m " printf "\033[0;32m>>>\033[0m "
read -r n read -r n
if [ "$n" -le "$line" ]; if [ "$n" -le "$line" ];

0
yt-meta.sh → lib/yt-meta Normal file → Executable file
View File

25
yt-search.sh → lib/yt-search Normal file → Executable file
View File

@ -19,7 +19,8 @@ then
query="$(echo "$2" | sed 's/ /+/g')" query="$(echo "$2" | sed 's/ /+/g')"
output="$3" output="$3"
else else
query="$(echo "$arg" | sed 's/ /+/g')" interactive_mode=0
query="$(echo "$1" | sed 's/ /+/g')"
fi fi
function get_input() { function get_input() {
@ -56,13 +57,7 @@ function get_input() {
search_file="/tmp/yt-search_$RANDOM" search_file="/tmp/yt-search_$RANDOM"
if type "wget" &> /dev/null st-download https://youtube.com/results?search_query=$query $search_file
then
wget -q https://youtube.com/results?search_query=$query -O $search_file
elif type "curl" &> /dev/null
then
curl -s https://youtube.com/results?search_query=$query -o $search_file
fi
# Now for displaying the search results # Now for displaying the search results
temp_file="/tmp/yt-result_$RANDOM" temp_file="/tmp/yt-result_$RANDOM"
@ -113,13 +108,11 @@ do
author=$(echo "$LINE" | sed 's/.*\/user\///' | sed 's/".*//') author=$(echo "$LINE" | sed 's/.*\/user\///' | sed 's/".*//')
fi fi
if [ $interactive_mode -eq 1 ] if [ $item_num -lt 10 ]
then then
if [ $item_num -lt 10 ] printf "${color}$item_num. "
then else
printf "${color}$item_num. " printf "${color}$item_num. "
else
printf "${color}$item_num. "
fi fi
echo -e "${color}$title${color2}" echo -e "${color}$title${color2}"
printf " " printf " "
@ -150,13 +143,9 @@ do
fi fi
done done
printf " | $itemid\n" printf " | $itemid\n"
fi
done done
if [ $interactive_mode -eq 1 ] if [ $interactive_mode -eq 1 ]
then then
get_input get_input
fi fi
rm $temp_file

61
shelltube.sh → shelltube Normal file → Executable file
View File

@ -1,3 +1,5 @@
#!/bin/sh
#################### ####################
# Name: shelltube.sh # Name: shelltube.sh
# Date: 2016-12-11 # Date: 2016-12-11
@ -7,9 +9,33 @@
# avoids the YT API. # avoids the YT API.
##################### #####################
# Roadmap:
# v1.0 - [ ] Playlist support
# [X] Channel support
# [ ] Audio dl/stream
# [ ] Show related videos
# [ ] Channel & Playlist search
# [ ] Search filters
# [ ] Search & Channel sort-by
# [ ] Config video player, etc
# [ ] Overall better interface
# [ ] Cli args as commands
function search() { function search() {
output="/tmp/yt-search-$RANDOM" output="/tmp/yt-search-$RANDOM"
sh yt-search.sh -i "$1" $output yt-search -i "$1" $output
selected_video=$(cat $output)
metadata
}
function channel() {
output="/tmp/yt-channel-$RANDOM"
if echo "$1" | grep "^UC" > /dev/null
then
yt-channel -ic "$1" $output
else
yt-channel -iu "$1" $output
fi
selected_video=$(cat $output) selected_video=$(cat $output)
metadata metadata
} }
@ -19,22 +45,22 @@ function interactive() {
} }
function about() { function about() {
echo -e "\033[0;35mShelltube v0.3" echo -e "\033[0;35mShelltube v0.4"
echo -e "\033[0;32mDesc: \033[0;34mYT client written in shell." echo -e "\033[0;32mDesc: \033[0;34mYT client written in shell."
echo -e "\033[0;32mMain: \033[0;34mjadedml@openmailbox.org" echo -e "\033[0;32mMain: \033[0;34mjadedml@openmailbox.org"
echo -e "\033[0;32mLisc: \033[0;34mISC; yt-down.sh & yt-stream.sh GPLv2\033[0m" echo -e "\033[0;32mLisc: \033[0;34mISC; yt-down GPLv2\033[0m"
} }
function metadata() { function metadata() {
sh yt-meta.sh "$selected_video" yt-meta "$selected_video"
} }
function download() { function download() {
sh yt-down.sh "$selected_video" yt-down "$selected_video"
} }
function stream() { function stream() {
sh yt-down.sh -s "$selected_video" yt-down -s "$selected_video"
} }
function get_input() { function get_input() {
@ -52,9 +78,13 @@ function get_input() {
then then
search "$(echo "$n" | sed 's^/^^')" search "$(echo "$n" | sed 's^/^^')"
interactive interactive
elif echo "$n" | grep "^/ " > /dev/null elif echo "$n" | grep "^channel " > /dev/null
then then
search "$(echo "$n" | sed 's^/ ^^')" channel "$(echo "$n" | sed 's/channel //')"
interactive
elif echo "$n" | grep "^chan " > /dev/null
then
channel "$(echo "$n" | sed 's/chan //')"
interactive interactive
elif echo "$n" | grep "^video " > /dev/null elif echo "$n" | grep "^video " > /dev/null
then then
@ -62,7 +92,7 @@ function get_input() {
then then
selected_video="$(echo "$n" | sed 's/.*watch?v=//')" selected_video="$(echo "$n" | sed 's/.*watch?v=//')"
else else
selected_video="$(echo "$n" | sed 's/sel //')" selected_video="$(echo "$n" | sed 's/video //')"
fi fi
metadata metadata
interactive interactive
@ -76,6 +106,16 @@ function get_input() {
fi fi
metadata metadata
interactive interactive
elif echo "$n" | grep "^url " > /dev/null
then
if echo "$n" | grep "youtube.com"
then
selected_video="$(echo "$n" | sed 's/.*watch?v=//')"
else
selected_video="$(echo "$n" | sed 's/url //')"
fi
metadata
interactive
elif [ "$n" == "download" ] || [ "$n" == "dl" ] elif [ "$n" == "download" ] || [ "$n" == "dl" ]
then then
download download
@ -113,8 +153,9 @@ function help() {
echo "help | ? Display this message." echo "help | ? Display this message."
echo "metadata | md Display selected video's metadata." echo "metadata | md Display selected video's metadata."
echo "search | / Perform a search." echo "search | / Perform a search."
echo "channel | chan Show newest videos of a channel."
echo "stream | str Stream the selected video." echo "stream | str Stream the selected video."
echo "video | sel Select video based on URL or ID." echo "video | sel | url Select video based on URL or ID."
echo "Note about usage:" echo "Note about usage:"
echo "Both 'video ID; download' and 'download ID' are valid." echo "Both 'video ID; download' and 'download ID' are valid."
echo "You don't need to select a video to run commands on it," echo "You don't need to select a video to run commands on it,"