Add playlist support

This commit is contained in:
Jaidyn Ann 2017-01-05 23:57:29 -06:00
parent f1416eda07
commit 628c4be558
3 changed files with 176 additions and 17 deletions

View File

@ -1,10 +1,10 @@
![Shelltube](https://cloud.githubusercontent.com/assets/7250745/21452795/52fcd6ea-c901-11e6-871b-bd646f2d7c49.png) ![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
most command-line clients require. most command-line clients require.
Shelltube is written in pure shell; its only dependencies shellTube is written in pure shell; its only dependencies
are any modern shell (pdksh, bash, zsh), curl/wget, and are any modern shell (pdksh, bash, zsh), curl/wget, and
vlc/mplayer/kaffeine. vlc/mplayer/kaffeine.
@ -12,7 +12,7 @@ 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. 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! :)
@ -20,8 +20,8 @@ power through the downsides, though! :)
Usage 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`.
When running the script, you'll see a prompt: When running the script, you'll see a prompt:
``` ```
@ -38,13 +38,14 @@ In this prompt you can type any of the following commands:
| `exit` | Exit Shelltube. | | `exit` | Exit Shelltube. |
| (`?`) `help` | Display this message. | | (`?`) `help` | Display this message. |
| (`md`) `metadata [URL]` | Display selected/specified video's metadata. | | (`md`) `metadata [URL]` | Display selected/specified video's metadata. |
| (`//`) `playlist URL` `playlist ID` | View playlist based on `URL` or `ID`. |
| (`/`) `search TERM` | Perform a search for `TERM`. | | (`/`) `search TERM` | Perform a search for `TERM`. |
| (`str`) `stream [URL]` | Stream the selected/specified video. | | (`str`) `stream [URL]` | Stream the selected/specified video. |
| (`sel`) `video URL` `video ID` | Select video based on `URL` or `ID`. | | (`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):
1. By selecting a video and then doing something with it 1. By selecting a video and then doing something with it
2. By doing something and specifying the video 2. By doing something and specifying the video
@ -86,9 +87,3 @@ All of ST is released under the
Except for the `yt-down` script, which is released under the Except for the `yt-down` script, which is released under the
[GPLv2](https://www.gnu.org/licenses/gpl-2.0.html). [GPLv2](https://www.gnu.org/licenses/gpl-2.0.html).
Credit
--------
jadedctrl wrote most of ST, but iluaster wrote almost all of
`yt-down`

150
lib/yt-playlist Executable file
View File

@ -0,0 +1,150 @@
#####################
# Name: yt-playlist
# Lisc: ISC
# Main: jadedctrl
# Desc: List a playlist's videos
# in easy-to-read and easy-to
# -parse results
#####################
# Usage: yt-playlist "$playlist_ID"
if [ -e $HOME/.config/shelltube ]
then
. $HOME/.config/shelltube
else
results=21
fi
if [ -e "./lib/yt-meta" ]
then
alias yt-channel="./lib/yt-channel"
alias yt-search="./lib/yt-down"
alias yt-meta="./lib/yt-meta"
alias yt-search="./lib/yt-search"
alias yt-down="./lib/yt-channel"
alias st-download="./lib/st-download"
alias st-video="./lib/st-video"
fi
row=0
if [ "$1" == "-i" ]
then
interactive_mode=1
plist="$(echo "$2" | sed 's/ /+/g')"
output="$3"
else
interactive_mode=0
plist="$(echo "$1" | sed 's/ /+/g')"
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/.*data-video-id="//' | sed 's/".*//' > $output
else
echo "Bad input, mate. Type in a valid number or 'exit'."
get_input
fi
}
# If Google adds any extra features or changes the webpage
# layout, this script'll break immediately, haha.
# ... But at least we aren't using their API, right?
plist_file="/tmp/$(mktemp -u yt-search_XXXXXX)"
st-download https://youtube.com/playlist?list=$plist $plist_file
# Now for displaying the search results
temp_file="/tmp/$(mktemp -u yt-result_XXXXXX)"
grep "<tr class=\"pl-video yt-uix-tile \"" $plist_file > $temp_file
item_num=0
cat $temp_file | while IFS='' read -r CUR_LINE
do
item_num=$(($item_num+1))
if [ $row -eq 1 ]
then
#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'
printf '\033[1;31m'
row=1
fi
itemid=$(echo "$CUR_LINE" | sed 's/.*data-video-id="//' | sed 's/".*//')
title=$(echo "$CUR_LINE" | sed 's/.*data-title="//' | sed 's/".*//')
author=$(grep -C3 " $(echo $title)" "$plist_file" | grep "by <a href=" | sed 's/by.* >//' | sed 's/<\/a>.*//')
duration=$(grep -C9 " $(echo $title)" "$plist_file" | grep "<td class=\"pl-video-badges\">" | sed 's/.*">//' | sed 's^</span>.*^^')
if [ $item_num -ge $((results+1)) ]
then
break
elif [ $item_num -lt 10 ]
then
printf '%s. ' "$item_num"
else
printf '%s. ' "$item_num"
fi
printf '%s\n' "$title"
printf ' '
i=0
while [ $i -lt 16 ]
do
i=$((i+1))
char=$(echo $author | cut -c$i)
if [ -z $char ]
then
printf ' '
else
printf '%s' "$char"
fi
done
printf ' | '
i=0
while [ $i -lt 5 ]
do
i=$((i+1))
char=$(echo $duration | cut -c$i)
if [ -z $char ]
then
printf ' '
else
printf '%s' "$char"
fi
done
printf ' | %s\n' "$itemid"
done
printf '\033[0m'
if [ $interactive_mode -eq 1 ]
then
get_input
fi

View File

@ -5,11 +5,11 @@
# Lisc: ISC # Lisc: ISC
# Main: jadedctrl # 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 Vers=0.5
##################### #####################
# Roadmap: # Roadmap:
# v1.0 - [ ] Playlist support # v1.0 - [X] Playlist support
# [X] Channel support # [X] Channel support
# [ ] Audio dl/stream # [ ] Audio dl/stream
# [ ] Show related videos # [ ] Show related videos
@ -28,10 +28,10 @@ fi
if [ -e "./lib/yt-meta" ] if [ -e "./lib/yt-meta" ]
then then
alias yt-channel="./lib/yt-channel" alias yt-channel="./lib/yt-channel"
alias yt-search="./lib/yt-down"
alias yt-meta="./lib/yt-meta" alias yt-meta="./lib/yt-meta"
alias yt-playlist="./lib/yt-playlist"
alias yt-search="./lib/yt-search" alias yt-search="./lib/yt-search"
alias yt-down="./lib/yt-channel" alias yt-down="./lib/yt-down"
alias st-download="./lib/st-download" alias st-download="./lib/st-download"
alias st-video="./lib/st-video" alias st-video="./lib/st-video"
fi fi
@ -43,6 +43,13 @@ search() {
yt-meta "$selected_video" yt-meta "$selected_video"
} }
playlist() {
output="$(mktemp -u /tmp/yt_XXXXXX)"
yt-playlist -i "$1" "$output"
selected_video="$(cat "$output")"
yt-meta "$selected_video"
}
channel() { channel() {
output="$(mktemp -u /tmp/yt-channel_XXXXXX)" output="$(mktemp -u /tmp/yt-channel_XXXXXX)"
case "$1" in case "$1" in
@ -58,7 +65,7 @@ channel() {
} }
about() { about() {
printf '\033[35mShelltube v%s\033[m\n' "$Vers" printf '\n \033[1mshell\033[41m Tube \033[0;1;30m v%s\033[m\n\n' "$Vers"
printf '\033[32mDesc: \033[0;34mYT client written in shell.\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[32mMain: \033[0;34mjadedml@openmailbox.org\033[m\n'
printf '\033[32mLisc: \033[0;34mISC; yt-down GPLv2\033[m\n' printf '\033[32mLisc: \033[0;34mISC; yt-down GPLv2\033[m\n'
@ -72,6 +79,7 @@ download | dl Download the selected video.
exit | ctrl+c Exit Shelltube. exit | ctrl+c Exit Shelltube.
help | ? Display this message. help | ? Display this message.
metadata | md Display selected video's metadata. metadata | md Display selected video's metadata.
playlist | // Display a playlist's videos.
search | / Perform a search. search | / Perform a search.
channel | chan Show newest videos of a channel. channel | chan Show newest videos of a channel.
stream | str Stream the selected video. stream | str Stream the selected video.
@ -90,6 +98,12 @@ parse() {
help | '?' ) help | '?' )
help help
;; ;;
playlist )
playlist "$argument"
;;
//* )
playlist "${command#//}"
;;
search ) search )
search "$argument" search "$argument"
;; ;;