This repository has been archived by the owner on Jan 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
yt
141 lines (121 loc) Β· 3.8 KB
/
yt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/bin/sh
########################################
# name: yt
# lisc: gnu gplv3
# main: jadedctrl
# desc: browse youtube from the terminal
########################################
# ... there's got to be a better way to
# source this.
if test -e ytlib.sh; then
. ./ytlib.sh
elif test -e lib/ytlib.sh; then
. ./lib/ytlib.sh
elif test -e ../lib/ytlib.sh; then
. ../lib/ytlib.sh
elif test -e /usr/local/lib/ytlib.sh; then
. /usr/local/lib/ytlib.sh
elif test -e /usr/lib/ytlib.sh; then
. /usr/lib/ytlib.sh
else
echo "ytlib.sh not found."
exit 5
fi
# --------------------------------------
# Show usage message of shelltube itself
function yt_usage {
echo "usage: yt command subcommand [arguments]"
echo " yt (v)ideo [...]"
echo " yt (p)laylist [...]"
exit 2
}
# --------------------------------------
if test -z "$1"; then
yt_usage
fi
# --------------------------------------
# Show usage message of the video subcommand
function video_usage {
echo "usage: yt video (s)earch [...]"
echo " yt video (t)itle [...]"
echo " yt video (d)esc [...]"
echo " yt video (a)uthor [...]"
echo " yt video (v)iews [...]"
echo " yt video (D)ate [...]"
exit 2
}
# Pass on commands to video subcommand
function video_invocation {
local command="$1"
local arguments="$(echo "$@" | awk '{$1=""; print}')"
if test -z "$command"; then
video_usage
elif test "$(length "$arguments")" -eq 0; then
arguments="-h"
fi
case "$command" in
"search") video_search_invocation $arguments;;
"s") video_search_invocation $arguments;;
"d") video_desc_invocation $arguments;;
"desc") video_desc_invocation $arguments;;
"D") video_uploaded_invocation $arguments;;
"date") video_uploaded_invocation $arguments;;
"views") video_views_invocation $arguments;;
"v") video_views_invocation $arguments;;
"author") video_author_invocation $arguments;;
"a") video_author_invocation $arguments;;
"title") video_title_invocation $arguments;;
"t") video_title_invocation $arguments;;
"help") video_usage;;
"h") video_usage;;
esac
}
# --------------------------------------
# Show playlist usage message
function playlist_usage {
echo "usage: yt playlist (s)earch [...]"
echo " yt playlist (l)ist [...]"
echo " yt playlist (t)itle [...]"
echo " yt playlsit (a)uthor [...]"
echo " yt playlist (v)iews [...]"
echo " yt playlist (D)ate [...]"
exit 2
}
# Pass on commands to the playlist subcommand
function playlist_invocation {
local command="$1"
local arguments="$(echo "$@" | awk '{$1=""; print}')"
if test -z "$command"; then
playlist_usage
elif test "$(length "$arguments")" -eq 0; then
arguments="-h"
fi
case "$command" in
"search") playlist_search_invocation $arguments;;
"s") playlist_search_invocation $arguments;;
"views") playlist_views_invocation $arguments;;
"v") playlist_views_invocation $arguments;;
"author") playlist_author_invocation $arguments;;
"a") playlist_author_invocation $arguments;;
"date") playlist_uploaded_invocation $arguments;;
"D") playlist_uploaded_invocation $arguments;;
"title") playlist_title_invocation $arguments;;
"t") playlist_title_invocation $arguments;;
"list") playlist_list_invocation $arguments;;
"l") playlist_list_invocation $arguments;;
"help") playlist_usage;;
"h") playlist_usage;;
esac
}
# --------------------------------------
# actual invocation
command="$1"
arguments="$(echo "$@" | awk '{$1=""; print}')"
case "$command" in
*video) video_invocation $arguments;;
*v) video_invocation $arguments;;
*channel) channel_invocation $arguments;;
*c) channel_invocation $arguments;;
*playlist) playlist_invocation $arguments;;
*p) playlist_invocation $arguments;;
esac