Proposing multiple changes #2

Merged
ghost merged 6 commits from master into master 2016-12-23 15:20:05 -06:00
6 changed files with 179 additions and 183 deletions

3
Makefile Normal file
View File

@ -0,0 +1,3 @@
install:
mkdir -p $(PREFIX)/bin
cp shelltube lib/* $(PREFIX)/bin/

View File

@ -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 Shelltube is a collection of (pretty POSIX) shell scripts to
browse YouTube quickly, efficiently, and without the bloat browse YouTube quickly, efficiently, and without the bloat
@ -13,8 +13,8 @@ for example, you don't have vlc, you can just modify a
single line and be good-to-go using another player. single line and be good-to-go using another player.
Also, Shelltube doesn't use the YouTube API at all. This Also, Shelltube doesn't use the YouTube API at all. This
avoids the annoying red-tapey stuff that goes with it-- IDs, avoids the annoying red-tapey stuff that goes with it -- IDs,
registration, quotas-- but has some disadvantages. We'll registration, quotas -- but has some disadvantages. We'll
power through the downsides, though! :) power through the downsides, though! :)
@ -23,65 +23,72 @@ Usage
Shelltube is quite simple to use; this tutorial will go over Shelltube is quite simple to use; this tutorial will go over
the usage of the wrapper script, shelltube.sh. the usage of the wrapper script, shelltube.sh.
When running the script, you'll see a prompt: When running the script, you'll see a prompt:
\>\>
```
>>
```
In this prompt you can type any of the following commands: 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. | (short) command syntax | description |
In {curly brackets}, required arguments are written. | --- | --- |
| (`!`) `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`. |
In [brackets], optional arguments are written. In [brackets], optional arguments are written.
You can use Shelltube in one of two ways (or both): 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
Method A entails using either the "video" or "search" command 1. By selecting a video and then doing something with it
to select a video, which will then be displayed before the prompt 2. By doing something and specifying the video
like so:
$VIDEO-ID-HERE \>\> Method A entails using either the `video` or `search`
When a video is selected, you use the "download", "stream", or command to select a video, which will then be displayed
"metadata" commands without arguments to act on the video. 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.
Method B entails just using the `download`, `stream`, or
`metadata` commands while using a URL or video ID as an
argument.
Method B entails just using the "download", "stream", or
"metadata" commands while using a URL or video ID as an argument.
For example: For example:
\>\> download $VIDEO-ID-HERE
```
>> download $VIDEO-ID-HERE
```
You could opt to not use this interactive wrapper script and instead You could opt to not use this interactive wrapper script and
just use the yt-down.sh, yt-search.sh, and yt-metadata.sh scripts instead just use the `yt-down`, `yt-search`, and
on their own. `yt-metadata` scripts on their own.
They are each pretty simple, and you can read their USAGE messages They are each pretty simple, and you can read their USAGE
at the top of each script. messages at the top of each script.
Licensing Licensing
----------- -----------
All of ST is released under the ISC license All of ST is released under the
(https://opensource.org/licenses/ISC) [ISC](https://opensource.org/licenses/ISC) license.
except for the yt-down.sh script, which is released under the GPLv2
(https://www.gnu.org/licenses/gpl-2.0.html) Except for the `yt-down` script, which is released under the
[GPLv2](https://www.gnu.org/licenses/gpl-2.0.html).
Credit Credit
-------- --------
jadedctrl wrote most of ST, but iluaster wrote almost all of jadedctrl wrote most of ST, but iluaster wrote almost all of
yt-down.sh `yt-down`

View File

@ -12,7 +12,7 @@
interactive_mode=0 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. # I really need to work out a better way to take flags.
# This is just awful. # This is just awful.
@ -82,7 +82,7 @@ function get_input() {
row=0 row=0
# Now for displaying the search results # 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 \ grep "href=\"\/watch?v=" $channel_file | grep "title=" | grep -v \
"<span class=\"yt-thumb-simple\"" > $temp_file "<span class=\"yt-thumb-simple\"" > $temp_file

View File

@ -21,7 +21,7 @@ else
fi fi
video_file="/tmp/$(mktemp -u yt-video_XXXXX)" video_file="/tmp/$(mktemp -u yt-video_XXXXXX)"
if type "wget" &> /dev/null if type "wget" &> /dev/null
then then
wget -q https://youtube.com/watch?v=$id -O $video_file wget -q https://youtube.com/watch?v=$id -O $video_file

View File

@ -55,12 +55,12 @@ function get_input() {
# layout, this script'll break immediately, haha. # layout, this script'll break immediately, haha.
# ... But at least we aren't using their API, right? # ... 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 st-download https://youtube.com/results?search_query=$query $search_file
# Now for displaying the search results # Now for displaying the search results
temp_file="/tmp/$(mktemp -u yt-result_XXXXX)" temp_file="/tmp/$(mktemp -u yt-result_XXXXXX)"
grep "<a href=\"\/watch?v=" $search_file | grep -v "<span class=\"yt-thumb-simple\"" > $temp_file grep "<a href=\"\/watch?v=" $search_file | grep -v "<span class=\"yt-thumb-simple\"" > $temp_file
item_num=0 item_num=0
cat $temp_file | while IFS='' read -r CUR_LINE cat $temp_file | while IFS='' read -r CUR_LINE

236
shelltube
View File

@ -5,8 +5,9 @@
# Date: 2016-12-11 # Date: 2016-12-11
# Lisc: ISC # Lisc: ISC
# Main: jadedctrl # Main: jadedctrl
# Desc: Full-shell YT client that # Desc: Full-shell YT client that avoids the YT API.
# avoids the YT API. ##################### Vers=0.4
#####################
# Roadmap: # Roadmap:
# v1.0 - [ ] Playlist support # v1.0 - [ ] Playlist support
@ -20,139 +21,124 @@
# [ ] Overall better interface # [ ] Overall better interface
# [ ] Cli args as commands # [ ] Cli args as commands
function search() { search() {
output="/tmp/$(mktemp -u yt-search_XXXXX)" output="$(mktemp -u /tmp/yt_XXXXXX)"
yt-search -i "$1" $output yt-search -i "$1" "$output"
selected_video=$(cat $output) selected_video="$(cat "$output")"
metadata
}
function channel() {
output="/tmp/$(mktemp -u yt-channel_XXXXX)"
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() {
printf '\033[0;35mShelltube v0.4.5\n'
printf '\033[0;32mDesc: \033[0;34mYT client written in shell.\n'
printf '\033[0;32mMain: \033[0;34mjadedml@openmailbox.org\n'
printf '\033[0;32mLisc: \033[0;34mISC; yt-down GPLv2\033[0m\n'
}
function metadata() {
yt-meta "$selected_video" yt-meta "$selected_video"
} }
function download() { channel() {
yt-down "$selected_video" output="$(mktemp -u /tmp/yt-channel_XXXXXX)"
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() { about() {
yt-down -s "$selected_video" 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'
} }
function get_input() { help() {
printf '\033[0;34m%s \033[0;32m>>\033[0m ' "$selected_video" printf "\
read -r n about | ! View the about page.
case $n in clear | cls Clear the screen.
help|'?') download | dl Download the selected video.
help ; interactive ;; exit | ctrl+c Exit Shelltube.
download|dl) help | ? Display this message.
download ; interactive ;; metadata | md Display selected video's metadata.
metadata|md) search | / Perform a search.
metadata ; interactive ;; channel | chan Show newest videos of a channel.
stream|str) stream | str Stream the selected video.
stream ; interactive ;; video | sel | url Select video based on URL or ID.
about|'!') Note about usage:
about ; interactive ;; Both 'video ID; download' and 'download ID' are valid. You don't need to
clear|cls) select a video to run commands on it, but if you use metadata, download, or
clear ; interactive ;; stream on an unselected video you must specify the ID or URL after the command.
exit) "
rm /tmp/yt-* ; exit ;; }
parse() {
command="$1" argument="$2"
case "$command" in
help | '?' )
help
;;
search )
search "$argument"
;;
/* )
search "${command#/}"
;;
channel )
channel "$argument"
;;
chan )
channel "$argument"
;;
video | sel | url )
case "$argument" in
*youtube.com* )
selected_video="$argument"
;;
*) *)
if [ "$n" ] && [ -z "${n%search *}" ] selected_video="$argument"
then ;;
search "${n#search }" esac
interactive yt-meta "$selected_video"
elif [ "$n" ] && [ -z "${n%/*}" ] ;;
then metadata | md )
search "${n#/}" selected_video="${argument:-$selected_video}"
interactive yt-meta "$selected_video"
elif [ "$n" ] && [ -z "${n%channel *}" ] ;;
then download | dl )
channel "${n#channel }" selected_video="${argument:-$selected_video}"
interactive yt-down "$selected_video"
elif [ "$n" ] && [ -z "${n%chan *}" ] ;;
then stream | str )
channel "${n#chan }" selected_video="${argument:-$selected_video}"
interactive yt-down -s "$selected_video"
elif echo "$n" | grep "^video " > /dev/null ;;
then about | ! )
if echo "$n" | grep "youtube.com" about
then ;;
selected_video="$(echo "$n" | sed 's/.*watch?v=//')" clear | cls )
else printf '\033[H\033[J'
selected_video="$(echo "$n" | sed 's/video //')" ;;
fi exit )
metadata rm -f "/tmp/yt-$$"
interactive exit
elif echo "$n" | grep "^sel " > /dev/null ;;
then '' ) ;;
if echo "$n" | grep "youtube.com" * )
then printf 'unknown command: "%s"\ntry "help"\n' "$command"
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
else
get_input
fi
;; ;;
esac esac
} }
if [ "$#" -gt 0 ]
then
for arg in "$@"
do
parse "${arg%% *}" "${arg#* }"
done
else
printf '\n \033[1mshell\033[41m Tube \033[0;1;30m v%s\033[m\n\n' "$Vers"
function help() { while printf '\033[0;34m%s \033[0;32m>>\033[m ' "$selected_video"
echo "about | ! View the about page." do
echo "clear | cls Clear the screen." read -r command argument
echo "download | dl Download the selected video." parse "$command" "$argument"
echo "exit | ctrl+c Exit Shelltube." done
echo "help | ? Display this message." fi
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."
}
printf '\033[0;35mShelltube v0.4.5'
interactive