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
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.
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! :)
@ -23,65 +23,72 @@ 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:
\>\>
```
>>
```
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.
| (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`. |
In [brackets], optional arguments are written.
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
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.
1. By selecting a video and then doing something with it
2. By doing something and specifying the video
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.
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:
\>\> download $VIDEO-ID-HERE
```
>> download $VIDEO-ID-HERE
```
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.
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.
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`

View File

@ -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 \
"<span class=\"yt-thumb-simple\"" > $temp_file

View File

@ -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

View File

@ -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 "<a href=\"\/watch?v=" $search_file | grep -v "<span class=\"yt-thumb-simple\"" > $temp_file
item_num=0
cat $temp_file | while IFS='' read -r CUR_LINE

238
shelltube
View File

@ -5,8 +5,9 @@
# 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:
# v1.0 - [ ] Playlist support
@ -20,139 +21,124 @@
# [ ] Overall better interface
# [ ] Cli args as commands
function search() {
output="/tmp/$(mktemp -u yt-search_XXXXX)"
yt-search -i "$1" $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() {
search() {
output="$(mktemp -u /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_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() {
yt-down -s "$selected_video"
about() {
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() {
printf '\033[0;34m%s \033[0;32m>>\033[0m ' "$selected_video"
read -r n
case $n in
help|'?')
help ; interactive ;;
download|dl)
download ; interactive ;;
metadata|md)
metadata ; interactive ;;
stream|str)
stream ; interactive ;;
about|'!')
about ; interactive ;;
clear|cls)
clear ; interactive ;;
exit)
rm /tmp/yt-* ; exit ;;
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
;;
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 *}" ]
then
search "${n#search }"
interactive
elif [ "$n" ] && [ -z "${n%/*}" ]
then
search "${n#/}"
interactive
elif [ "$n" ] && [ -z "${n%channel *}" ]
then
channel "${n#channel }"
interactive
elif [ "$n" ] && [ -z "${n%chan *}" ]
then
channel "${n#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
else
get_input
fi
;;
selected_video="$argument"
;;
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 | ! )
about
;;
clear | cls )
printf '\033[H\033[J'
;;
exit )
rm -f "/tmp/yt-$$"
exit
;;
'' ) ;;
* )
printf 'unknown command: "%s"\ntry "help"\n' "$command"
;;
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() {
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."
}
printf '\033[0;35mShelltube v0.4.5'
interactive
while printf '\033[0;34m%s \033[0;32m>>\033[m ' "$selected_video"
do
read -r command argument
parse "$command" "$argument"
done
fi