From 507886fafe57954d24dd6cae05201c5e83c2a57f Mon Sep 17 00:00:00 2001 From: josuah Date: Fri, 23 Dec 2016 10:54:20 +0000 Subject: [PATCH 1/5] added a makefile and made shellcheck happy for 'shelltube' --- Makefile | 3 + shelltube | 236 ++++++++++++++++++++++++------------------------------ 2 files changed, 106 insertions(+), 133 deletions(-) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..49c191d --- /dev/null +++ b/Makefile @@ -0,0 +1,3 @@ +install: + mkdir -p $(PREFIX)/bin + cp shellcheck lib/* $(PREFIX)/bin/ diff --git a/shelltube b/shelltube index 36cea5e..ad0ce4a 100755 --- a/shelltube +++ b/shelltube @@ -21,148 +21,118 @@ # [ ] Overall better interface # [ ] Cli args as commands -function search() { - output="/tmp/yt-search-$RANDOM" - 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 -} - -function interactive() { - get_input -} - -function about() { - 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 GPLv2\033[0m" -} - -function metadata() { +search() { + output="$(mktemp /tmp/yt-XXXXXX)" + yt-search -i "$1" "$output" + selected_video="$(cat "$output")" yt-meta "$selected_video" } -function download() { - yt-down "$selected_video" +channel() { + output="$(mktemp -u /tmp/yt-channel-XXXXXXX)" + case "$1" in + UC* ) + yt-channel -ic "$1" "$output" + ;; + * ) + yt-channel -iu "$1" "$output" + ;; + esac + selected_video="$(cat "$output")" + yt-meta "$selected_video" } -function stream() { - yt-down -s "$selected_video" +about() { + printf '\033[35mShelltube v0.4\033[m\n' + 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' } -function get_input() { - printf "\033[0;34m$selected_video \033[0;32m>>\033[0m " - read -r n - if [ "$n" == "help" ] || [ "$n" == "?" ] - then +help() { + printf "\ +about | ! View the about page. +clear | cls Clear the screen. +download | dl Download the selected video. +exit | ctrl+c Exit Shelltube. +help | ? Display this message. +metadata | md Display selected video's metadata. +search | / Perform a search. +channel | chan Show newest videos of a channel. +stream | str Stream the selected video. +video | sel | url Select video based on URL or ID. +Note about usage: +Both 'video ID; download' and 'download ID' are valid. You don't need to +select a video to run commands on it, but if you use metadata, download, or +stream on an unselected video you must specify the ID or URL after the command. +" +} + +parse() { + command="$1" argument="$2" + + case "$command" in + help | '?' ) help - interactive - elif echo "$n" | grep "^search " > /dev/null - then - search "$(echo "$n" | sed 's/search //')" - interactive - elif echo "$n" | grep "^/" > /dev/null - then - search "$(echo "$n" | sed 's^/^^')" - interactive - elif echo "$n" | grep "^channel " > /dev/null - then - 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 - if echo "$n" | grep "youtube.com" - then - selected_video="$(echo "$n" | sed 's/.*watch?v=//')" - else - selected_video="$(echo "$n" | sed 's/video //')" - fi - metadata - interactive - elif echo "$n" | grep "^sel " > /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/sel //')" - 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 - interactive - elif [ "$n" == "metadata" ] || [ "$n" == "md" ] - then - metadata - interactive - elif [ "$n" == "stream" ] || [ "$n" == "str" ] - then - stream - interactive - elif [ "$n" == "about" ] || [ "$n" == "!" ] - then + ;; + search ) + search "$argument" + ;; + /* ) + search "${command#/}" + ;; + channel ) + channel "$argument" + ;; + chan ) + channel "$argument" + ;; + video | sel | url | metadata | md ) + case "$argument" in + *youtube.com* ) + selected_video="$argument" + ;; + *) + selected_video="$argument" + ;; + esac + yt-meta "$selected_video" + ;; + download | dl ) + yt-down "$selected_video" + ;; + stream | str ) + yt-down -s "$selected_video" + ;; + about | ! ) about - interactive - elif [ "$n" == "clear" ] || [ "$n" == "cls" ] - then - clear - interactive - elif [ "$n" == "exit" ] - then - rm /tmp/yt-* + ;; + clear | cls ) + printf '\033[H\033[J' + ;; + exit ) + rm -f "/tmp/yt-$$" exit - else - get_input - fi + ;; + '' ) ;; + * ) + printf 'unknown command: "%s"\ntry "help"\n' "$command" + ;; + esac } -function help() { - echo "about | ! View the about page." - echo "clear | cls Clear the screen." - echo "download | dl Download the selected video." - echo "exit | ctrl+c Exit Shelltube." - 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 | 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," - echo "but if you use metadata, download, or stream on an" - echo "unselected video you must specify the ID or URL after the" - echo "command." -} - -echo -e "\033[0;35mShelltube v0.3" -interactive +printf '\033[35mShelltube v%s\033[m\n' 0.3 + +if [ "$#" -gt 0 ] +then + for arg in "$@" + do + parse "${arg%% *}" "${arg#* }" + done +else + while printf '\033[0;34m%s \033[0;32m>>\033[m ' "$selected_video" + do + read -r command argument + parse "$command" "$argument" + done +fi -- 2.46.0 From beda7bde7c3c9f2172bc2e91f30c6f6dd647a8e5 Mon Sep 17 00:00:00 2001 From: josuah Date: Fri, 23 Dec 2016 11:39:21 +0000 Subject: [PATCH 2/5] including the logo in the startup message --- shelltube | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shelltube b/shelltube index ad0ce4a..4567702 100755 --- a/shelltube +++ b/shelltube @@ -121,7 +121,7 @@ parse() { esac } -printf '\033[35mShelltube v%s\033[m\n' 0.3 +printf '\n \033[1mshell\033[41m Tube \033[0;1;30m v%s\033[m\n\n' 0.3 if [ "$#" -gt 0 ] then -- 2.46.0 From fb510dc9800a8c5982f22d6211d19040a07be163 Mon Sep 17 00:00:00 2001 From: josuah Date: Fri, 23 Dec 2016 19:13:21 +0000 Subject: [PATCH 3/5] formatting for the README --- README.md | 111 +++++++++++++++++++++++++++++------------------------- 1 file changed, 59 insertions(+), 52 deletions(-) diff --git a/README.md b/README.md index 865b073..dbf2750 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -#Shelltube +![Shelltube](https://cloud.githubusercontent.com/assets/7250745/21452795/52fcd6ea-c901-11e6-871b-bd646f2d7c49.png) Shelltube is a collection of (pretty POSIX) shell scripts to browse YouTube quickly, efficiently, and without the bloat @@ -9,79 +9,86 @@ are any modern shell (pdksh, bash, zsh), curl/wget, and vlc/mplayer/kaffeine. Even these dependencies, though, can easily be changed. If, -for example, you don't have vlc, you can just modify a +for example, you don't have vlc, you can just modify a single line and be good-to-go using another player. Also, Shelltube doesn't use the YouTube API at all. This -avoids the annoying red-tapey stuff that goes with it-- IDs, -registration, quotas-- but has some disadvantages. We'll +avoids the annoying red-tapey stuff that goes with it -- IDs, +registration, quotas -- but has some disadvantages. We'll power through the downsides, though! :) Usage ------- Shelltube is quite simple to use; this tutorial will go over -the usage of the wrapper script, shelltube.sh. -When running the script, you'll see a prompt: - \>\> +the usage of the wrapper script, shelltube.sh. +When running the script, you'll see a prompt: -In this prompt you can type any of the following commands: -(!) about -*View the about page.* -(cls) clear -*Clear the screen.* -(dl) download [URL] -*Download the selected/specified video.* -exit -*Exit Shelltube.* -(?) help -*Display this message.* -(md) metadata [URL] -*Display selected/specified video's MD.* -(/) search {term} -*Perform a search.* -(str) stream [URL] -*Stream the selected/specified video.* -(sel) video {URL} -*Select video based on URL or ID.* +``` + >> +``` -In (parenthesis), smaller aliases for the commands are written. -In {curly brackets}, required arguments are written. -In [brackets], optional arguments are written. +In this prompt you can type any of the following commands: -You can use Shelltube in one of two ways (or both): -**A)** By selecting a video and then doing something with it -**B)** By doing something and specifying the video +| (short) command syntax | description | +| --- | --- | +| (`!`) `about` | View the about page. | +| (`cls`) `clear` | Clear the screen. | +| (`dl`) `download [URL] ` | Download the selected/specified video. | +| `exit` | Exit Shelltube. | +| (`?`) `help` | Display this message. | +| (`md`) `metadata [URL]` | Display selected/specified video's metadata. | +| (`/`) `search TERM` | Perform a search for `TERM`. | +| (`str`) `stream [URL]` | Stream the selected/specified video. | +| (`sel`) `video URL` `video ID` | Select video based on `URL` or `ID`. | -Method A entails using either the "video" or "search" command -to select a video, which will then be displayed before the prompt -like so: -$VIDEO-ID-HERE \>\> -When a video is selected, you use the "download", "stream", or -"metadata" commands without arguments to act on the video. +In [brackets], optional arguments are written. -Method B entails just using the "download", "stream", or -"metadata" commands while using a URL or video ID as an argument. -For example: - \>\> download $VIDEO-ID-HERE +You can use Shelltube in one of two ways (or both): +1. By selecting a video and then doing something with it +2. By doing something and specifying the video -You could opt to not use this interactive wrapper script and instead -just use the yt-down.sh, yt-search.sh, and yt-metadata.sh scripts -on their own. +Method A entails using either the `video` or `search` +command to select a video, which will then be displayed +before the prompt like so: -They are each pretty simple, and you can read their USAGE messages -at the top of each script. +``` +$VIDEO-ID-HERE >> +``` + +When a video is selected, you use the `download`, `stream`, +or `metadata` commands without arguments to act on the +video. + +Method B entails just using the `download`, `stream`, or +`metadata` commands while using a URL or video ID as an +argument. + +For example: + +``` + >> download $VIDEO-ID-HERE +``` + +You could opt to not use this interactive wrapper script and +instead just use the `yt-down`, `yt-search`, and +`yt-metadata` scripts on their own. + +They are each pretty simple, and you can read their USAGE +messages at the top of each script. Licensing ----------- -All of ST is released under the ISC license -(https://opensource.org/licenses/ISC) -except for the yt-down.sh script, which is released under the GPLv2 -(https://www.gnu.org/licenses/gpl-2.0.html) +All of ST is released under the +[ISC](https://opensource.org/licenses/ISC) license. + +Except for the `yt-down` script, which is released under the +[GPLv2](https://www.gnu.org/licenses/gpl-2.0.html). + Credit -------- jadedctrl wrote most of ST, but iluaster wrote almost all of -yt-down.sh +`yt-down` -- 2.46.0 From 7c637d1ac9c4b6727169433861d4b54091dd3445 Mon Sep 17 00:00:00 2001 From: josuah Date: Fri, 23 Dec 2016 19:28:20 +0000 Subject: [PATCH 4/5] fixing mktemp calls, with 6 'X' rather than 5. --- lib/yt-channel | 4 ++-- lib/yt-meta | 2 +- lib/yt-search | 4 ++-- shelltube | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/yt-channel b/lib/yt-channel index 44ba51b..aa2c675 100755 --- a/lib/yt-channel +++ b/lib/yt-channel @@ -12,7 +12,7 @@ interactive_mode=0 -channel_file="/tmp/$(mktemp -u yt-channel_XXXXX)" +channel_file="/tmp/$(mktemp -u yt-channel_XXXXXX)" # I really need to work out a better way to take flags. # This is just awful. @@ -82,7 +82,7 @@ function get_input() { row=0 # Now for displaying the search results -temp_file="/tmp/$(mktemp -u yt-channel_XXXXX)" +temp_file="/tmp/$(mktemp -u yt-channel_XXXXXX)" grep "href=\"\/watch?v=" $channel_file | grep "title=" | grep -v \ " $temp_file diff --git a/lib/yt-meta b/lib/yt-meta index 9101d90..062a942 100755 --- a/lib/yt-meta +++ b/lib/yt-meta @@ -21,7 +21,7 @@ else fi -video_file="/tmp/$(mktemp -u yt-video_XXXXX)" +video_file="/tmp/$(mktemp -u yt-video_XXXXXX)" 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 0b11ff6..84df494 100755 --- a/lib/yt-search +++ b/lib/yt-search @@ -55,12 +55,12 @@ function get_input() { # layout, this script'll break immediately, haha. # ... But at least we aren't using their API, right? -search_file="/tmp/$(mktemp -u yt-search_XXXXX)" +search_file="/tmp/$(mktemp -u yt-search_XXXXXX)" st-download https://youtube.com/results?search_query=$query $search_file # Now for displaying the search results -temp_file="/tmp/$(mktemp -u yt-result_XXXXX)" +temp_file="/tmp/$(mktemp -u yt-result_XXXXXX)" grep " $temp_file item_num=0 cat $temp_file | while IFS='' read -r CUR_LINE diff --git a/shelltube b/shelltube index ce892e3..7f1a822 100755 --- a/shelltube +++ b/shelltube @@ -22,14 +22,14 @@ # [ ] Cli args as commands search() { - output="$(mktemp /tmp/yt-XXXXXX)" + output="$(mktemp -u /tmp/yt_XXXXXX)" yt-search -i "$1" "$output" selected_video="$(cat "$output")" yt-meta "$selected_video" } channel() { - output="$(mktemp -u /tmp/yt-channel-XXXXXXX)" + output="$(mktemp -u /tmp/yt-channel_XXXXXX)" case "$1" in UC* ) yt-channel -ic "$1" "$output" -- 2.46.0 From 993425d20501c14147563339836d0e45d8df6e8c Mon Sep 17 00:00:00 2001 From: josuah Date: Fri, 23 Dec 2016 19:35:58 +0000 Subject: [PATCH 5/5] tested and fixed my changes --- shelltube | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/shelltube b/shelltube index 7f1a822..7db5367 100755 --- a/shelltube +++ b/shelltube @@ -87,7 +87,7 @@ parse() { chan ) channel "$argument" ;; - video | sel | url | metadata | md ) + video | sel | url ) case "$argument" in *youtube.com* ) selected_video="$argument" @@ -98,10 +98,16 @@ parse() { esac yt-meta "$selected_video" ;; + metadata | md ) + selected_video="${argument:-$selected_video}" + yt-meta "$selected_video" + ;; download | dl ) + selected_video="${argument:-$selected_video}" yt-down "$selected_video" ;; stream | str ) + selected_video="${argument:-$selected_video}" yt-down -s "$selected_video" ;; about | ! ) -- 2.46.0