-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyt-boat-fish
executable file
·112 lines (97 loc) · 3.31 KB
/
yt-boat-fish
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
#!/usr/bin/fish
# Variables to change colour of text on terminal
set -g g '\e[1;32m'
set -g y '\e[0;93m'
set -g r '\e[0m'
# Location of the queue and info files
set -g QF "$XDG_DATA_HOME/yt-boat/queue"
set -g IF "$XDG_DATA_HOME/yt-boat/info"
# Functions - These allow for less repeating of code which makes it easier to manage and to read
function OK # Prints a success message, from input, in green
echo -e "$g$argv$r" 1>&2
end
function OK_EXIT # Prints a success message, from input, in green, then exits
echo -e "$g$argv$r" 1>&2
return 0
end
function ERR # Prints an error message, from input or a default, in yellow, then exits
echo -e "$y yt-boat: line $LINENO: Error: $argv:-"Unknown: Please submit an issue or contact me \
as this is probably an error with the code itself"$r" 1>&2
exit 1
end
function 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)
end
function 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"
end
argparse -i -X 1 'a/add=+' 'd/download' 'c/clear' 'q/queue' 'h/help' 'hnb' 'qnb' -- $argv
or return
# Options
if set -q _flag_a # Adds the url to the queue file
for i in "$_flag_a"
echo "$_flag_a" >> $QF
echo -n "$(yt-dlp --no-warnings --ignore-config --print title,duration_string $_flag_a) $g$_flag_a$r\n" >> $IF
end
OK_EXIT "Videos added to queue"
else if set -q _flag_d # Provides the queue file as a url file to yt-dlp
if yt-dlp -a "$QF"
: > $QF
: > $IF
OK_EXIT "Videos downloaded"
else
ERR "Probably unsupported url or invalid format hardcoded in your yt-dlp config"
end
else if set -q _flag_c # Clears the queue and info files, by overriding its contents with nothing
if : > $QF && : > $IF
OK_EXIT "Queue cleared"
else
ERR
end
else if set -q _flag_q # Calls the queue function
if QUEUE
OK
else
ERR "Queue file may not exist, see FAQ's"
end
else if set -q _flag_h # Calls the help function
if HELP
OK
else
ERR
end
else if set -q _flag_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)"
OK "Press enter to go back to newsboat"
read
OK
else
ERR
end
else if set -q _flag_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)"
OK "Press enter to go back to newsboat"
read
OK
else
ERR
end
else
echo -e "$y'$r$argv$y' is not a valid option$r" # Catches any mistaken command inputs and presents the available ones through the help dialoge
HELP
end