-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathget_takeout.sh
53 lines (51 loc) · 1.59 KB
/
get_takeout.sh
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
#!/usr/bin/env bash
# get_takeout.sh by @yottabit42 (Jacob McDonald), rev. 2024-10-06 #1.
echo "Usage:"
echo
echo "${0}"
echo
echo "Prompts for cURL(s) to download in parallel, using server-supplied"
echo "filenames, modifying if necessary to prevent overwriting existing"
echo "files with the same name. Up to 50 cURL entries are allowed. An empty"
echo "entry ends the series."
echo
echo "Note: you probably should not use 50 cURLs without really knowing what"
echo " you are doing. Typical home and business networks and machines can"
echo " handle between 3 and 10 simultaneous downloads in parallel."
echo
if [[ ! $(which curl) ]]; then
echo "Please install 'curl' first, e.g., 'sudo apt install curl'. Exiting."
exit
fi
if [[ ! $(which cut) ]]; then
echo "Please install 'cut' first, e.g., 'sudo apt install cut'. Exiting."
exit
fi
for (( i=0; i<=49; i++ )); do
echo -n "Paste cURL, then press Enter, or Enter alone to end: "
while IFS='' read -r; do
if [[ "${REPLY: -1}" != '\' || -z "${REPLY}" ]]; then
cURL[i]+="${REPLY}"
break
fi
cURL[i]+="${REPLY}"
done
cURL[i]="${cURL[i]//curl /}"
cURL[i]="${cURL[i]//[$'\t\r\n\\']/}"
if [[ -z "${cURL[i]}" ]]; then
break
fi
done
if [[ -z "${cURL[0]}" ]]; then
exit
fi
for (( i=1; i<=$(("${#cURL[@]}"-1)); i++ )); do
if [[ ! -z "${cURL[i]}" ]]; then
cURL[0]+=" "
cURL[0]+=$(echo "${cURL[i]}" | cut -d ' ' -f 1)
fi
done
trapCmd="echo -e '\nAn error occurred during download. Check your files:'; "
trapCmd+="ls -lh; exit 1"
trap "${trapCmd}" ERR
eval curl --remote-name-all --parallel-immediate -JLOZ ${cURL[0]}