forked from hare1039/anime-updater
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trace.sh
executable file
·52 lines (45 loc) · 1.12 KB
/
trace.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
SCRIPT=$(readlink -f "$0");
export SCRIPTPATH=$(dirname "$SCRIPT");
source $SCRIPTPATH/config.sh;
instance_sub()
{
local rate=$(cat ${trace_file});
if (( "$rate" <= 0 )); then
echo "Too meny mega instences. Skip.";
exit 0;
fi
# ok, instence - 1
let "rate = $rate - 1";
echo $rate > ${trace_file};
}
instance_plus()
{
local rate=$(cat ${trace_file});
# instence + 1
let "rate = $rate + 1";
echo $rate > ${trace_file};
}
instance_sub;
trap instance_plus EXIT;
INT-handler () {
echo "Cleaning up"
exit
}
trap INT-handler INT
SRC_DL_FUNC="source $SCRIPTPATH/dl-func.sh";
list=$(cat $SCRIPTPATH/list.json);
for row in $(echo "${list}" | jq -r '.[] | @base64'); do
_jq() {
echo ${row} | base64 --decode | jq -r ${1}
}
cd ${HOME};
for url in $(_jq '.url[]'); do
cd "$(_jq '.file_path')";
if [[ "$url" = *"mega"* ]]; then
$TIMEOUT bash -c "$SRC_DL_FUNC; megadl-from $url";
elif [[ "$url" = *"google.com"* ]]; then
$TIMEOUT bash -c "$SRC_DL_FUNC; gdrivedl-from $url";
fi
cd ${HOME};
done
done