Repository navigation
Expand file tree
/
Copy pathsdkmanager.lua
More file actions
105 lines (90 loc) · 3 KB
/
Copy pathsdkmanager.lua
File metadata and controls
105 lines (90 loc) · 3 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
--[[
Android SDK command-line tools (sdkmanager) for VMR.
Crawled live from the Android Studio download page.
https://developer.android.com/studio
--]]
local C = dofile(__vmr_plugin_dir .. "/_vmr_common.lua")
-- global variables
plugin_name = "sdkmanager"
sdk_name = "sdkmanager"
plugin_version = "0.1"
homepage = "https://developer.android.com/studio"
-- installer config
ic = C.installer({
flag_files = {
windows = { "bin", "lib" },
linux = { "bin", "lib" },
darwin = { "bin", "lib" },
},
binary_dirs = {
windows = { { "bin" } },
linux = { { "bin" } },
darwin = { { "bin" } },
},
})
-- spider
local DOWNLOAD_URL = "https://developer.android.com/studio?hl=en"
local HOST = "https://dl.google.com/android/repository"
local OS_MAP = {
windows = "windows",
linux = "linux",
mac = "darwin",
}
local function parseOs(platform)
local osStr = OS_MAP[platform]
if osStr then
return osStr
end
-- The download table labels Apple rows "Mac (Intel)" / "Mac (ARM)".
if vmrHasPrefix(platform, "mac") then
return "darwin"
end
return ""
end
function crawl()
local vl = vmrNewVersionList()
-- A browser User-Agent makes developer.android.com redirect into an OAuth flow; the page is
-- served directly for a plain client (this matches the upstream Go crawler's default UA).
local resp = vmrGetResponse(DOWNLOAD_URL, 600, {})
-- The command-line tools table is the second `table.download` on the page.
local tableSel = vmrEq(vmrInitSelection(resp, "table.download"), 1)
local rows = vmrFind(tableSel, "tr")
vmrEach(rows, function(idx, ss)
if idx == 0 then
return
end
local tds = vmrFind(ss, "td")
local platform = vmrToLower(vmrTrimSpace(vmrText(vmrEq(tds, 0))))
local fName = vmrTrimSpace(vmrText(vmrFind(vmrEq(tds, 1), "button")))
if platform == "" or fName == "" then
return
end
-- File names look like `commandlinetools-win-15859902_latest.zip` or
-- `commandlinetools-mac_x86_64-15859902_latest.zip`; the build number is the numeric
-- part of the last dash-separated segment (a bare first-digit regexp would match the
-- "86"/"64" inside "x86_64").
local parts, nParts = vmrSplit(fName, "-")
local tail = fName
if nParts > 0 then
tail = parts[nParts]
end
local versionName = vmrRegexpFindString("(\\d+)", tail)
if versionName == "" then
return
end
local sum = vmrTrimSpace(vmrText(vmrEq(tds, 3)))
local item = {}
item["url"] = vmrUrlJoin(HOST, fName)
item["arch"] = "any"
item["os"] = parseOs(platform)
item["sum"] = sum
if sum ~= "" then
item["sum_type"] = "sha256"
end
item["installer"] = vmrInstallerUnarchiver
item["size"] = 0
item["lts"] = ""
vmrAddItem(vl, versionName, item)
end)
return vl
end