-
Notifications
You must be signed in to change notification settings - Fork 0
/
yt-boat
executable file
·126 lines (110 loc) · 3.74 KB
/
yt-boat
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
#!/bin/bash
# Variables to change colour of text on terminal
g="\e[1;32m"
y="\e[0;93m"
r="\e[0m"
# Location of the queue and info files
QF="$XDG_DATA_HOME/yt-boat/queue"
IF="$XDG_DATA_HOME/yt-boat/info"
# Functions - These allow for less repeating of code which makes it easier to manage and to read
OK () { # Prints a success message, from input, in green
echo -e "${g}$1${r}" 1>&2
}
OK_EXIT () { # Prints a success message, from input, in green, then exits
echo -e "${g}$1${r}" 1>&2
exit 0
}
ERR () { # Prints an error message, from input or a default, in yellow, then exits
echo -e "${y}yt-boat: 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
}
QUEUE () { # Shows the queue; containing titles, durations and video url's
echo -e "There are ${g}$(wc -l $QF | cut -c 1)${r} vidoes in the queue:" # Prints the number of url's in the queue, with the number in green
echo -e $(cat $IF)
}
HELP () { # Prints the help dialogue
echo -e "Usage:\nyt-boat [option]\noptions:\n\
a add [url] Adds video the provided 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\
h help Shows this help message\n\
\n\
In newsboat\n\
<macro> a Adds current video's url to queue\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> h Shows this help message"
}
# Options
while test "$#" -gt 0; do
case "$1" in
a|add|-a|--add) # Adds a video to the queue
shift
for i in "$@"
do
echo "$i" >> $QF # Adds the url to the queue file
echo -n "$(yt-dlp --no-warnings --ignore-config --print title,duration_string $i) $g$i$r\n" >> $IF
done
OK_EXIT "Videos added to queue"
;;
d|download|-d|--download) # Provides the queue file as a url file to yt-dlp
if yt-dlp -a "$QF"; then
: > $QF # Clears the queue file, by overriding its contents with nothing, only if yt-dlp reports a successful download
: > $IF # Clears the info file, by overriding its contents with nothing, only if yt-dlp reports a successful download
OK_EXIT "Videos downloaded"
else
ERR "Probably unsupported url or invalid format hardcoded in your yt-dlp config" # Otherwise simply errors so that the yt-dlp provlem can be resolved and the queue is not lost because it would be a pain to add all of the videos again
fi
;;
c|clear|-c|--clear) # Clears the queue and info files, by overriding its contents with nothing
if : > $QF && : > $IF; then
OK_EXIT "Queue cleared"
else
ERR
fi
;;
q|queue|-q|--queue) # Calls the queue function
shift
if QUEUE; then
OK_EXIT
else
ERR "Queue file may not exist, see FAQ's"
fi
;;
h|help|-h|--help) # Calls the help function
if HELP; then
OK_EXIT
else
ERR
fi
;;
-hnb) # Calls the help function but because newsboat runs macros in a different way as it is run on the terminal it needs to be passed through as the output of echo
clear
if echo -e "$(HELP)"; then
OK "Press enter to go back to newsboat"
read
OK_EXIT
else
ERR
fi
;;
-qnb) # Calls the queue function but because newsboat runs macros in a different way as it is run on the terminal it needs to be passed through as the output of echo
clear
if echo -e "$(QUEUE)"; then
OK "Press enter to go back to newsboat"
read
OK_EXIT
else
ERR
fi
;;
*) # Catches any mistaken command inputs and presents the available ones through the help dialoge
echo -e "${y}'${r}${1}${y}' is not a valid option${r}"
HELP
;;
esac
shift
done