-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbatch_megadl.sh
executable file
·51 lines (39 loc) · 1.14 KB
/
batch_megadl.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
#!/bin/bash
while getopts d:f: flag; do
case "${flag}" in
d) destination=${OPTARG};;
f) file=${OPTARG};;
*) echo 'error' >&2
exit 1
esac
done
echo "Destination: $destination";
echo "Input File: $file";
# TODO - Only do this if the dir is not there
mkdir $destination
while read line; do
LINK=$line
SUB="mega.nz"
BROKEN_LINK_IDENTIFIER="/file/"
# If this line does not contain a mega.nz link, skip this part of the loop
if
[[ "$LINK" != *"$SUB"* ]]; then
echo "No link found on this line: $LINK"
continue
fi
# Remove anything that comes before 'https'
LINK=$(echo $LINK | sed 's/^.*\(https\)/https/');
# Now we need to determine if this link needs to be coerced and do so if needed
if
[[ "$LINK" == *"$BROKEN_LINK_IDENTIFIER"* ]]; then
echo "This link needs to be coerced"
# Need to replace /file/{restoflink} with /#!{restoflink}
replaceHashtag=${LINK/\#/!};
echo "Replacing hashtag: ${replaceHashtag}";
partToReplace="\/file\/"
replaceWith="/#!"
LINK=${replaceHashtag/$partToReplace/$replaceWith};
fi
echo "FinalLink: $LINK"
megadl "$LINK" --path=$destination;
done < $file