diff --git a/INSTALL.md b/INSTALL.md new file mode 100644 index 0000000..3df433c --- /dev/null +++ b/INSTALL.md @@ -0,0 +1,4 @@ +Simple. Just move the "shelltube" script along with +the scripts in lib/ into your PATH. +Then-- boom, installed. +Groovy. diff --git a/lib/st-download b/lib/st-download new file mode 100755 index 0000000..adf53c9 --- /dev/null +++ b/lib/st-download @@ -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 diff --git a/lib/st-video b/lib/st-video new file mode 100755 index 0000000..719f1ea --- /dev/null +++ b/lib/st-video @@ -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 diff --git a/lib/yt-channel b/lib/yt-channel new file mode 100755 index 0000000..a29cf12 --- /dev/null +++ b/lib/yt-channel @@ -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 \ + " $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/.*//')" + 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 diff --git a/yt-down.sh b/lib/yt-down old mode 100644 new mode 100755 similarity index 98% rename from yt-down.sh rename to lib/yt-down index 4f92e17..2bd86f7 --- a/yt-down.sh +++ b/lib/yt-down @@ -43,7 +43,7 @@ function select_option () line=$((line+1)) echo "${line}. $i" done - printf "\033[0;32m>>\033[0m " + printf "\033[0;32m>>>\033[0m " read -r n if [ "$n" -le "$line" ]; diff --git a/yt-meta.sh b/lib/yt-meta old mode 100644 new mode 100755 similarity index 100% rename from yt-meta.sh rename to lib/yt-meta diff --git a/yt-search.sh b/lib/yt-search old mode 100644 new mode 100755 similarity index 87% rename from yt-search.sh rename to lib/yt-search index 474159e..727d7bd --- a/yt-search.sh +++ b/lib/yt-search @@ -19,7 +19,8 @@ then query="$(echo "$2" | sed 's/ /+/g')" output="$3" else - query="$(echo "$arg" | sed 's/ /+/g')" + interactive_mode=0 + query="$(echo "$1" | sed 's/ /+/g')" fi function get_input() { @@ -56,13 +57,7 @@ function get_input() { search_file="/tmp/yt-search_$RANDOM" -if type "wget" &> /dev/null -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 +st-download https://youtube.com/results?search_query=$query $search_file # Now for displaying the search results temp_file="/tmp/yt-result_$RANDOM" @@ -113,13 +108,11 @@ do author=$(echo "$LINE" | sed 's/.*\/user\///' | sed 's/".*//') fi - if [ $interactive_mode -eq 1 ] - then - if [ $item_num -lt 10 ] - then - printf "${color}$item_num. " - else - printf "${color}$item_num. " + if [ $item_num -lt 10 ] + then + printf "${color}$item_num. " + else + printf "${color}$item_num. " fi echo -e "${color}$title${color2}" printf " " @@ -150,13 +143,9 @@ do fi done printf " | $itemid\n" - fi done if [ $interactive_mode -eq 1 ] then get_input fi - - -rm $temp_file diff --git a/shelltube.sh b/shelltube old mode 100644 new mode 100755 similarity index 65% rename from shelltube.sh rename to shelltube index 8d3d187..36cea5e --- a/shelltube.sh +++ b/shelltube @@ -1,3 +1,5 @@ +#!/bin/sh + #################### # Name: shelltube.sh # Date: 2016-12-11 @@ -7,9 +9,33 @@ # 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() { 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) metadata } @@ -19,22 +45,22 @@ function interactive() { } 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;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() { - sh yt-meta.sh "$selected_video" + yt-meta "$selected_video" } function download() { - sh yt-down.sh "$selected_video" + yt-down "$selected_video" } function stream() { - sh yt-down.sh -s "$selected_video" + yt-down -s "$selected_video" } function get_input() { @@ -52,9 +78,13 @@ function get_input() { then search "$(echo "$n" | sed 's^/^^')" interactive - elif echo "$n" | grep "^/ " > /dev/null + elif echo "$n" | grep "^channel " > /dev/null 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 elif echo "$n" | grep "^video " > /dev/null then @@ -62,7 +92,7 @@ function get_input() { then selected_video="$(echo "$n" | sed 's/.*watch?v=//')" else - selected_video="$(echo "$n" | sed 's/sel //')" + selected_video="$(echo "$n" | sed 's/video //')" fi metadata interactive @@ -76,6 +106,16 @@ function get_input() { fi metadata 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" ] then download @@ -113,8 +153,9 @@ function help() { echo "help | ? Display this message." echo "metadata | md Display selected video's metadata." echo "search | / Perform a search." + echo "channel | chan Show newest videos of a channel." 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 "Both 'video ID; download' and 'download ID' are valid." echo "You don't need to select a video to run commands on it,"