diff --git a/Makefile b/Makefile index 49c191d..1f7c4f5 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,3 @@ install: mkdir -p $(PREFIX)/bin - cp shellcheck lib/* $(PREFIX)/bin/ + cp shelltube lib/* $(PREFIX)/bin/ diff --git a/lib/yt-channel b/lib/yt-channel index a29cf12..44ba51b 100755 --- a/lib/yt-channel +++ b/lib/yt-channel @@ -12,7 +12,7 @@ interactive_mode=0 -channel_file="/tmp/yt-channel_$RANDOM" +channel_file="/tmp/$(mktemp -u yt-channel_XXXXX)" # I really need to work out a better way to take flags. # This is just awful. @@ -51,7 +51,7 @@ else fi function get_input() { - printf "\033[0;32m>>>\033[0m " + printf '\033[0;32m>>>\033[0m ' read -r n if [ "$n" == "exit" ] @@ -82,7 +82,7 @@ function get_input() { row=0 # Now for displaying the search results -temp_file="/tmp/yt-channel_$RANDOM" +temp_file="/tmp/$(mktemp -u yt-channel_XXXXX)" grep "href=\"\/watch?v=" $channel_file | grep "title=" | grep -v \ " $temp_file @@ -96,24 +96,25 @@ do if [ $row -eq 1 ] then - color='\033[1;34m' - color2='\033[1;34m' + #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' + #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" - 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" + 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/\..*//') @@ -122,15 +123,15 @@ do if [ $item_num -lt 10 ] then - printf "${color}$item_num. " + printf '%s. ' "$item_num" elif [ $item_num -lt 20 ] then - printf "${color}$item_num. " + printf '%s. ' "$item_num" else break fi - echo -e "${color}$title${color2}" - printf " " + echo "$title" + printf ' ' i=0 while [ $i -lt 9 ] do @@ -138,12 +139,12 @@ do char=$(echo $duration | cut -c$i) if [ -z $char ] then - printf " " + printf ' ' else - printf "$char" + printf '%s' "$char" fi done - printf " | $itemid\n" + printf ' | %s\n' "$itemid" fi done diff --git a/lib/yt-down b/lib/yt-down index 2bd86f7..2612981 100755 --- a/lib/yt-down +++ 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/lib/yt-meta b/lib/yt-meta index a4a355d..9101d90 100755 --- a/lib/yt-meta +++ b/lib/yt-meta @@ -14,14 +14,14 @@ then id="$(echo $1 | sed 's/.*video_id=//')" elif [ -z $1 ] then - "No video specified." + echo "No video specified." exit 1 else id="$1" fi -video_file="/tmp/yt-video_$RANDOM" +video_file="/tmp/$(mktemp -u yt-video_XXXXX)" if type "wget" &> /dev/null then wget -q https://youtube.com/watch?v=$id -O $video_file diff --git a/lib/yt-search b/lib/yt-search index 727d7bd..0b11ff6 100755 --- a/lib/yt-search +++ b/lib/yt-search @@ -24,7 +24,7 @@ else fi function get_input() { - printf "\033[0;32m>>>\033[0m " + printf '\033[0;32m>>>\033[0m ' read -r n if [ "$n" == "exit" ] @@ -55,15 +55,15 @@ function get_input() { # layout, this script'll break immediately, haha. # ... But at least we aren't using their API, right? -search_file="/tmp/yt-search_$RANDOM" +search_file="/tmp/$(mktemp -u yt-search_XXXXX)" st-download https://youtube.com/results?search_query=$query $search_file # Now for displaying the search results -temp_file="/tmp/yt-result_$RANDOM" +temp_file="/tmp/$(mktemp -u yt-result_XXXXX)" grep " $temp_file item_num=0 -cat $temp_file | while IFS='' read -r CUR_LINE +cat $temp_file | while IFS='' read -r CUR_LINE do item_num=$(($item_num+1)) # These tags trip up 'title=' and '" >' queries later on. Strip 'em. @@ -73,13 +73,15 @@ do if [ $row -eq 1 ] then - color='\033[1;34m' - color2='\033[1;34m' + #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' + #color='\033[1;31m' + #color2='\033[1;31m' + printf '\033[1;31m' row=1 fi @@ -88,12 +90,12 @@ do type="Playlist" if [ $interactive_mode -eq 1 ] then - printf "${color}$item_num. " + printf '%s. ' "$item_num" fi 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" + printf '%s\n' "$title" + printf '%s | %s | %s\n' "$type" "$items" "$itemid" else type="Video" duration=$(echo "$LINE" | sed 's/.*Duration: //' | sed 's/\..*//') @@ -110,12 +112,12 @@ do if [ $item_num -lt 10 ] then - printf "${color}$item_num. " + printf '%s. ' "$item_num" else - printf "${color}$item_num. " + printf '%s. ' "$item_num" fi - echo -e "${color}$title${color2}" - printf " " + printf '%s\n' "$title" + printf ' ' fi i=0 while [ $i -lt 16 ] @@ -124,12 +126,12 @@ do char=$(echo $author | cut -c$i) if [ -z $char ] then - printf " " + printf ' ' else - printf "$char" + printf '%s' "$char" fi done - printf " | " + printf ' | ' i=0 while [ $i -lt 5 ] do @@ -137,14 +139,16 @@ do char=$(echo $duration | cut -c$i) if [ -z $char ] then - printf " " + printf ' ' else - printf "$char" + printf '%s' "$char" fi done - printf " | $itemid\n" + printf ' | %s\n' "$itemid" done +printf '\033[0m' + if [ $interactive_mode -eq 1 ] then get_input diff --git a/shelltube b/shelltube index 4567702..ce892e3 100755 --- a/shelltube +++ b/shelltube @@ -5,8 +5,8 @@ # Date: 2016-12-11 # Lisc: ISC # Main: jadedctrl -# Desc: Full-shell YT client that -# avoids the YT API. +# Desc: Full-shell YT client that avoids the YT API. + Vers=0.4 ##################### # Roadmap: @@ -43,7 +43,7 @@ channel() { } about() { - printf '\033[35mShelltube v0.4\033[m\n' + printf '\033[35mShelltube v%s\033[m\n' "$Vers" printf '\033[32mDesc: \033[0;34mYT client written in shell.\033[m\n' printf '\033[32mMain: \033[0;34mjadedml@openmailbox.org\033[m\n' printf '\033[32mLisc: \033[0;34mISC; yt-down GPLv2\033[m\n' @@ -121,8 +121,6 @@ parse() { esac } -printf '\n \033[1mshell\033[41m Tube \033[0;1;30m v%s\033[m\n\n' 0.3 - if [ "$#" -gt 0 ] then for arg in "$@" @@ -130,6 +128,8 @@ then parse "${arg%% *}" "${arg#* }" done else + printf '\n \033[1mshell\033[41m Tube \033[0;1;30m v%s\033[m\n\n' "$Vers" + while printf '\033[0;34m%s \033[0;32m>>\033[m ' "$selected_video" do read -r command argument