Skip to content
This repository was archived by the owner on Dec 6, 2025. It is now read-only.

Commit c03060b

Browse files
committed
feat: fetch versions lit for 5 pages in parallel
1 parent 8c732c5 commit c03060b

1 file changed

Lines changed: 81 additions & 63 deletions

File tree

modules/app/version.sh

Lines changed: 81 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,94 @@
11
#!/usr/bin/bash
22

33
scrapeVersionsList() {
4-
local PAGE VERSIONS
5-
PAGE=$("${CURL[@]}" -A "$USER_AGENT" "https://www.apkmirror.com/uploads/?appcategory=$APKMIRROR_APP_NAME" 2>&1)
4+
local PAGE_CONTENTS PAGE_JSON MERGED_JSON
5+
local IDX MAX_PAGE_COUNT
66

7-
if [ "$PAGE" == "" ]; then
7+
MAX_PAGE_COUNT=5
8+
9+
for ((IDX = 1; IDX <= MAX_PAGE_COUNT; IDX++)); do
10+
TMP_FILES[IDX]=$(mktemp)
11+
"${CURL[@]}" -A "$USER_AGENT" "https://www.apkmirror.com/uploads/page/$IDX/?appcategory=$APKMIRROR_APP_NAME" > "${TMP_FILES[$IDX]}" 2> /dev/null &
12+
done
13+
wait
14+
15+
for ((IDX = 1; IDX <= MAX_PAGE_COUNT; IDX++)); do
16+
PAGE_CONTENTS[IDX]=$(cat "${TMP_FILES[$IDX]}")
17+
rm -f "${TMP_FILES[$IDX]}"
18+
done
19+
20+
for ((IDX = 1; IDX <= MAX_PAGE_COUNT; IDX++)); do
21+
PAGE_JSON[IDX]=$(
22+
pup -c 'div.widget_appmanager_recentpostswidget div.listWidget div:not([class]) json{}' <<< "${PAGE_CONTENTS[$IDX]}" |
23+
jq -rc '
24+
.[].children as $CHILDREN |
25+
{
26+
version: $CHILDREN[1].children[0].children[1].text,
27+
info: $CHILDREN[0].children[0].children[1].children[0].children[0].children[0]
28+
} |
29+
{
30+
version: .version,
31+
tag: (
32+
.info.text | ascii_downcase |
33+
if test("beta") then
34+
"[BETA]"
35+
elif test("alpha") then
36+
"[ALPHA]"
37+
else
38+
"[STABLE]"
39+
end
40+
),
41+
url: .info.href
42+
}
43+
'
44+
)
45+
done
46+
47+
MERGED_JSON=$(jq -s '.' <<< "$(printf '%s\n' "${PAGE_JSON[@]}")")
48+
49+
if [[ "$MERGED_JSON" == "[]" ]]; then
850
notify msg "Unable to fetch versions !!\nThere is some problem with your internet connection. Disable VPN or Change your network."
951
TASK="CHOOSE_APP"
1052
return 1
1153
fi
1254

1355
readarray -t VERSIONS_LIST < <(
14-
pup -c 'div.widget_appmanager_recentpostswidget div.listWidget div:not([class]) json{}' <<< "$PAGE" |
15-
jq -rc \
16-
--arg PKG_NAME "$PKG_NAME" \
17-
--arg INSTALLED_VERSION "$INSTALLED_VERSION" \
18-
--arg ALLOW_APP_VERSION_DOWNGRADE "$ALLOW_APP_VERSION_DOWNGRADE" \
19-
--argjson AVAILABLE_PATCHES "$AVAILABLE_PATCHES" '
20-
(
21-
$AVAILABLE_PATCHES[] |
22-
select(.pkgName == $PKG_NAME) |
23-
.versions
24-
) as $SUPPORTED_VERSIONS |
25-
[
26-
.[].children |
27-
.[1].children.[0].children.[1].text as $VERSION |
28-
.[0].children.[0].children.[1].children.[0].children.[0].children.[0] as $INFO |
29-
{
30-
"version": ($VERSION),
31-
"tag": (
32-
if ($SUPPORTED_VERSIONS | index($VERSION)) != null then
33-
"[RECOMMENDED]"
34-
else
35-
(
36-
$INFO.text |
37-
if test("beta"; "i") then
38-
"[BETA]"
39-
elif test("alpha"; "i") then
40-
"[ALPHA]"
41-
else
42-
"[STABLE]"
43-
end
44-
)
45-
end
46-
),
47-
"url": $INFO.href
48-
}
49-
] |
50-
if $INSTALLED_VERSION != "" then
51-
if ($ALLOW_APP_VERSION_DOWNGRADE | test("off")) then
52-
.[0:(map(.version == $INSTALLED_VERSION) | index(true) + 1)]
53-
end |
54-
map(
55-
if .version == $INSTALLED_VERSION then
56-
.tag |= "[INSTALLED]"
57-
end
58-
)
59-
end |
60-
(
61-
if any(.[]; .tag == "[RECOMMENDED]") then
62-
(first(.[] | select(.tag == "[RECOMMENDED]"))), "Auto Select|[RECOMMENDED]"
63-
elif $INSTALLED_VERSION != "" then
64-
.[-1], "Auto Select|[INSTALLED]"
65-
else
66-
empty
67-
end,
68-
(
69-
.[] |
70-
., "\(.version)|\(.tag)"
71-
)
72-
)
73-
'
56+
jq -rc \
57+
--arg PKG_NAME "$PKG_NAME" \
58+
--arg INSTALLED_VERSION "$INSTALLED_VERSION" \
59+
--arg ALLOW_APP_VERSION_DOWNGRADE "$ALLOW_APP_VERSION_DOWNGRADE" \
60+
--argjson AVAILABLE_PATCHES "$AVAILABLE_PATCHES" '
61+
. as $ALL_VERSIONS |
62+
(
63+
$AVAILABLE_PATCHES[] |
64+
select(.pkgName == $PKG_NAME) |
65+
.versions
66+
) as $SUPPORTED_VERSIONS |
67+
$ALL_VERSIONS |
68+
map(
69+
.version as $VERSION |
70+
if ($SUPPORTED_VERSIONS | index($VERSION)) != null then
71+
.tag = "[RECOMMENDED]"
72+
elif .version == $INSTALLED_VERSION then
73+
.tag = "[INSTALLED]"
74+
else
75+
.
76+
end
77+
) |
78+
(
79+
if any(.[]; .tag == "[RECOMMENDED]") then
80+
(first(.[] | select(.tag == "[RECOMMENDED]"))), "Auto Select|[RECOMMENDED]"
81+
elif $INSTALLED_VERSION != "" then
82+
.[-1], "Auto Select|[INSTALLED]"
83+
else
84+
empty
85+
end
86+
),
87+
(
88+
.[] |
89+
., "\(.version)|\(.tag)"
90+
)
91+
' <<< "$MERGED_JSON"
7492
)
7593
}
7694

0 commit comments

Comments
 (0)