-
Notifications
You must be signed in to change notification settings - Fork 2
/
obsolete-ani-cli-batch
166 lines (146 loc) · 5 KB
/
obsolete-ani-cli-batch
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/usr/bin/env bash
# This script was updated and modified by Junaid Shaik. It is obsolete. Do Not Work On This.
echo "This is a wrapper for ani-cli that makes it easier to batch download multiple anime"
# Functions
# Display a menu
# This function draws a menu to get user input. Pass a string of text as the first argument and then pass the menu entry options as other arguments when calling the function.
# The function will store the user's choice in the first argument / string of text
function showmenu() {
echo "Choose an option by selecting it's S.no:"
# Define variables
# i is used to iterate over the arguments passed to the function and to display them as a numbered list
# j is used to skip displaying the first argument as it isn't an option to be displayed but a way to hold the user choice
local i=1
local j=1
# Draw a menu and list the options
for option in "$@"; do
if [[ $j -eq 1 ]]; then
let "j++"
else
echo"";
echo -n " $i."; echo "$option"
echo;
let "i++"
fi
done
# Read the user choice
read -n 1 choice
echo ""
# Iterate over the arguments (except the first one) using the variable 'a' to locate the user's choice
local a=1
local b=1
for option in "$@"; do
if [[ $b -eq 1 ]]; then
let "b++"
else
if [[ $a -eq $choice ]]; then
# On finding the choice, set it to the 1st argument so it can be accessed outside of the function
firstarg=$1
eval "$(echo "$firstarg")=$option"
break
else
let "a++"
fi
fi
done
}
# Selecting a download location
echo; echo "Please provide a download location."
echo "Default is current running directory."
echo "Please note, I don't check permissions yet!"
# TODO: Check perms
directory="$(pwd)"
read directory
while [ ! -d $directory ];
do
echo "Either I don't know what this is or it's not a directory."
echo "Please provide a download location:"
read directory
done
if [[ "" == "$directory" ]];
then
echo "Keeping current directory."
else
echo "Changing to $directory."
cd $directory
fi
echo
addanime=true
command="ani-cli -d"
validchoice=false
while [ $addanime == true ]
do
echo "What do you want to download?"
read animename
echo "Running ani-cli's search operation"
echo "Exit after finding the correct S.no and episode range"
ani-cli -d $animename
#searchresult=$(timeout 5s ani-cli $animename)
#clear
#echo $searchresult
echo "What number on the list was your anime?"
read selection
command=$(echo $command $animename -S $selection)
clear
echo "What range of episodes do you want to download?"
read range
command=$(echo $command -r $range)
echo "Do you want to specify a download quality (y/n)?"
read -n 1 qualitychoice
if [ $qualitychoice == y ]; then
showmenu quality 240p 360p 480p 720p
command=$(echo $command -q $quality)
else
echo
fi
echo "What do you want to do?"
echo "1.Continue adding anime"
echo "2.Execute the download command"
echo "3.Print the download command and await further instructions"
echo "4.Cancel operation and quit"
until [ $validchoice == true ]
do
read choice
case $choice in
1|add)
command=$(echo $command "; ani-cli -d" )
addanime=true
validchoice=true
;;
2|execute)
#$command
#if [ $? == 0 ]; then
# addanime=false
#else
# echo "Download failed! Printing the download command."
# echo $command
# addanime=false
#fi
clear
echo "The script's downloader is experiencing issues rn."
echo "Just copy and paste this command as a temporary alternative"
echo $command
#remove the next line if you uncomment the first 8 lines in this code block.
addanime=false
validchoice=true
;;
3|print)
clear && echo "Printing the download command."
echo $command
echo "respond with a ? to view all the available choices"
validchoice=false
;;
4|cancel)
echo "Cancelling pending operations and quitting."
addanime=false
validchoice=true
;;
*)
echo "Please make a valid choice!"
echo "Valid choices include 1, 2, 3, 4, add, execute, print and cancel"
validchoice=false
;;
esac
done
validchoice=false
done