-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyt-boat-int
executable file
·152 lines (136 loc) · 3.56 KB
/
yt-boat-int
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
142
143
144
145
146
147
148
149
150
151
152
#!/bin/bash
# Colour variables
g="\e[1;32m"
y="\e[0;93m"
r="\e[0m"
# File variables
queue_file="/home/leon/.local/share/yt-boat/newsboat.queue"
# Functions
ERR_ () {
echo -e "${y}yt-boat: line $LINENO: Error: ${1:-"Unknown: Please submit an issue or contact me \
as this is probably an error with the code itself"}${r}" 1>&2
exit 1
}
OK_ () {
echo -e "${g}${1}${r}" 1>&2
exit 0
}
QUEUE_ () {
echo -e "There are ${g}$(wc -l /home/leon/.local/share/yt-boat/newsboat.queue | cut -c 1)${r} vidoes in the queue:"
cat /home/leon/.local/share/yt-boat/newsboat.queue
}
HELP_ () {
echo -e "Usage:\nyt-boat [option]\noptions:\n\
-a --add [url] Adds video the full, provided url to the queue (eg if you want to download from a different frontend)\n\
-aa --add-alternative [url] Adds url to the queue\n\
-d --download Downloads videos in the queue\n\
-c --clear Clears the queue\n\
-q --queue Shows the urls in the queue\n\
-u --update Updates to the latest version of yt-boat\n\
-h --help Shows this help message\n\
\n\
In newsboat\n\
<macro> a Adds current video's ID to queue\n\
<macro> l Adds the full, provided url to the queue (eg if you want to download from a different frontend)\n\
<macro> d Downloads the urls in the queue\n\
<macro> c Clears the urls in the queue\n\
<macro> q Shows the urls in the queue\n\
<macro> u Updates to the latest version of yt-boat\n\
<macro> h Shows this help message"
}
# Options
while true; do
read -p "> " choice
case "$choice" in
a|add)
shift
read | echo "$1" ; for i in "$@"
do
echo "$i" | grep -o -P "(?:v=|\/embed\/|\/1\/|\/v\/)([^&\n?#]+)" | cut -c 3- >> $XDG_DATA_HOME/yt-boat/newsboat.queue
done
OK_ "Videos added to queue" || ERR_
;;
aa|add-alternative)
shift
for i in $@
do
echo $i >> $XDG_DATA_HOME/yt-boat/newsboat.queue
done
OK_ "Video added to queue"
;;
d|download)
if yt-dlp -a "$XDG_DATA_HOME/yt-boat/newsboat.queue"; then
: > $XDG_DATA_HOME/yt-boat/newsboat.queue
OK_ "Videos downloaded"
else
ERR_ "Probably unsupported url"
fi
;;
c|clear)
if : > $XDG_DATA_HOME/yt-boat/newsboat.queue; then
OK_ "Queue cleared"
else
ERR_
fi
;;
q|queue)
shift
if QUEUE_; then
OK_
else
ERR_ "Queue file may not exist, see FAQ's"
fi
;;
h|help)
if HELP_; then
OK_
else
ERR_
fi
;;
u|update)
if wget -o /tmp/log -P $XDG_DATA_HOME/yt-boat https://github.com/flufficat/yt-boat/releases/latest/download/yt-boat.tar.gz; then
tar -C $XDG_DATA_HOME/yt-boat -xf $XDG_DATA_HOME/yt-boat/yt-boat.tar.gz && \
chmod +x $XDG_DATA_HOME/yt-boat/yt-boat/yt-boat && \
sudo mv /usr/local/bin/yt-boat /usr/local/bin/yt-boat_old && \
sudo mv $XDG_DATA_HOME/yt-boat/yt-boat/yt-boat /usr/local/bin && \
sudo rm -r $XDG_DATA_HOME/yt-boat/yt-boat && \
sudo mv $XDG_DATA_HOME/yt-boat/yt-boat.tar.gz $XDG_DATA_HOME/Trash/files && \
if sudo mv /usr/local/bin/yt-boat_old $XDG_DATA_HOME/Trash/files; then
OK_ "Updated Sucessfully"
else
ERR_
fi
else
ERR_ "Download failure"
fi
;;
-hnb)
clear
if echo -e "$(HELP_)"; then
echo -e "${g}Press enter to go back to newsboat${r}"
read
OK_
else
ERR_
fi
;;
-qnb)
clear
if echo -e "$(QUEUE_)"; then
echo -e "${g}Press enter to go back to newsboat${r}"
read
OK_
else
ERR_
fi
;;
*)
shift
echo -e "${y}Not a valid option${r}"
HELP_
ERR_
;;
esac
shift
done