-
Notifications
You must be signed in to change notification settings - Fork 61
/
fetch_versions.sh
60 lines (53 loc) · 2.02 KB
/
fetch_versions.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
54
55
56
57
58
59
60
#!/bin/bash
UserAgent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36"
appName="$1"
apkmirrorAppName="$2"
patchesSource="$3"
currentVersion="$4"
storagePath="$5"
page1=$(curl --fail-early --connect-timeout 2 --max-time 5 -sL -A "$UserAgent" "https://www.apkmirror.com/uploads/?appcategory=$apkmirrorAppName" 2>&1)
[ "$page1" == "" ] && echo error && exit 1
readarray -t versions < <(pup -p 'div.widget_appmanager_recentpostswidget h5 a.fontBlack text{}' <<<"$page1")
supportedVers=$(jq -r --arg apkmirrorAppName "$apkmirrorAppName" '[.[] | select(.apkmirrorAppName == $apkmirrorAppName).versions[] | sub(" *[-, ] *"; "-"; "g")]' "$storagePath/$patchesSource-patches.json")
jq -r -n --arg appName "$appName-"\
--arg currentVersion "$currentVersion"\
--argjson supportedVers "$supportedVers"\
'($currentVersion | sub(" *[-, ] *"; "-"; "g")) as $installedVer |
[
[
$ARGS.positional[] |
sub("( -)|( &)"; ""; "g") |
sub("[()\\|]"; ""; "g") |
sub(" *[-, ] *"; "-"; "g") |
sub($appName; "")
] |
. |= . + $supportedVers |
unique |
reverse |
index($installedVer) as $index |
if $index == null then
.[]
else
.[0:($index + 1)][]
end | . as $version |
if (($supportedVers | index($version)) != null) then
$version, "[RECOMMENDED]"
elif ($version | test("beta|Beta|BETA")) then
$version | sub("(?<=[0-9])-[a-zA-Z]*$"; ""), "[BETA]"
elif ($version | test("alpha|Alpha|ALPHA")) then
$version | sub("(?<=[0-9])-[a-zA-Z]$"; ""), "[ALPHA]"
else
$version, "[STABLE]"
end
] |
if (. | index($installedVer)) != null then
.[-1] |= "[INSTALLED]"
else
.
end |
if ((. | index("[RECOMMENDED]")) != null) then
. |= ["Auto Select", "[RECOMMENDED]"] + .
else
.
end |
.[]' --args "${versions[@]}"