2022-12-08 16:06:23 +08:00
|
|
|
#!/usr/bin/python3
|
2022-08-26 00:20:49 +08:00
|
|
|
#
|
2022-08-24 01:54:24 +08:00
|
|
|
# This file is part of MagiskOnWSALocal.
|
|
|
|
#
|
|
|
|
# MagiskOnWSALocal is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
# License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# MagiskOnWSALocal is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with MagiskOnWSALocal. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
#
|
2023-01-11 17:05:56 +08:00
|
|
|
# Copyright (C) 2023 LSPosed Contributors
|
2022-08-24 01:54:24 +08:00
|
|
|
#
|
|
|
|
|
2023-01-19 23:17:26 +08:00
|
|
|
from datetime import datetime
|
2022-08-24 01:54:24 +08:00
|
|
|
import sys
|
|
|
|
|
|
|
|
import requests
|
|
|
|
import json
|
|
|
|
import re
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
arch = sys.argv[1]
|
2022-09-10 15:40:21 +09:00
|
|
|
brand = sys.argv[2]
|
|
|
|
variant = sys.argv[3]
|
2023-03-26 20:31:44 +08:00
|
|
|
arg4 = sys.argv[4]
|
|
|
|
download_dir = Path.cwd().parent / "download" if arg4 == "" else Path(arg4)
|
2022-09-10 15:40:21 +09:00
|
|
|
tempScript = sys.argv[5]
|
2022-12-08 16:06:23 +08:00
|
|
|
android_api = sys.argv[6]
|
|
|
|
file_name = sys.argv[7]
|
2023-01-20 06:12:13 +08:00
|
|
|
print(f"Generating {brand} download link: arch={arch} variant={variant}", flush=True)
|
2022-08-24 01:54:24 +08:00
|
|
|
abi_map = {"x64": "x86_64", "arm64": "arm64"}
|
2022-12-08 16:06:23 +08:00
|
|
|
android_api_map = {"30": "11.0", "32": "12.1", "33": "13.0"}
|
2022-12-08 20:06:42 +08:00
|
|
|
release = android_api_map[android_api]
|
2022-09-10 15:40:21 +09:00
|
|
|
if brand == "OpenGApps":
|
|
|
|
try:
|
|
|
|
res = requests.get(f"https://api.opengapps.org/list")
|
|
|
|
j = json.loads(res.content)
|
|
|
|
link = {i["name"]: i for i in j["archs"][abi_map[arch]]
|
|
|
|
["apis"][release]["variants"]}[variant]["zip"]
|
2023-01-20 06:12:13 +08:00
|
|
|
DATE = j["archs"][abi_map[arch]]["date"]
|
2022-09-13 19:11:45 +08:00
|
|
|
print(f"DATE={DATE}", flush=True)
|
2022-09-10 15:40:21 +09:00
|
|
|
except Exception:
|
|
|
|
print("Failed to fetch from OpenGApps API, fallbacking to SourceForge RSS...")
|
|
|
|
res = requests.get(
|
|
|
|
f'https://sourceforge.net/projects/opengapps/rss?path=/{abi_map[arch]}&limit=100')
|
|
|
|
link = re.search(f'https://.*{abi_map[arch]}/.*{release}.*{variant}.*\.zip/download', res.text).group().replace(
|
|
|
|
'.zip/download', '.zip').replace('sourceforge.net/projects/opengapps/files', 'downloads.sourceforge.net/project/opengapps')
|
|
|
|
elif brand == "MindTheGapps":
|
2022-08-24 01:54:24 +08:00
|
|
|
res = requests.get(
|
2022-09-10 15:40:21 +09:00
|
|
|
f'https://sourceforge.net/projects/wsa-mtg/rss?path=/{abi_map[arch]}&limit=100')
|
2023-01-19 23:17:26 +08:00
|
|
|
matched = re.search(f'https://.*{release}.*{abi_map[arch]}.*\.zip/download', res.text)
|
|
|
|
if matched:
|
|
|
|
link = matched.group().replace(
|
|
|
|
'.zip/download', '.zip').replace('sourceforge.net/projects/wsa-mtg/files', 'downloads.sourceforge.net/project/wsa-mtg')
|
|
|
|
else:
|
|
|
|
print(f"Failed to fetch from SourceForge RSS, fallbacking to Github API...", flush=True)
|
2023-04-07 19:45:29 +09:00
|
|
|
res = requests.get(f"https://api.github.com/repos/Howard20181/MindTheGappsBuilder/releases/latest")
|
2023-01-19 23:17:26 +08:00
|
|
|
json_data = json.loads(res.content)
|
2023-01-20 06:12:13 +08:00
|
|
|
headers = res.headers
|
|
|
|
x_ratelimit_remaining = headers["x-ratelimit-remaining"]
|
2023-01-19 23:17:26 +08:00
|
|
|
if res.status_code == 200:
|
|
|
|
assets = json_data["assets"]
|
|
|
|
for asset in assets:
|
2023-03-08 22:40:19 +08:00
|
|
|
if re.match(f'.*{release}.*{abi_map[arch]}.*\.zip$', asset["name"]) and asset["content_type"] == "application/zip":
|
2023-01-19 23:17:26 +08:00
|
|
|
link = asset["browser_download_url"]
|
2023-01-20 06:12:13 +08:00
|
|
|
break
|
|
|
|
elif res.status_code == 403 and x_ratelimit_remaining == '0':
|
2023-01-19 23:17:26 +08:00
|
|
|
message = json_data["message"]
|
|
|
|
print(f"Github API Error: {message}", flush=True)
|
2023-01-20 06:12:13 +08:00
|
|
|
ratelimit_reset = headers["x-ratelimit-reset"]
|
|
|
|
ratelimit_reset = datetime.fromtimestamp(int(ratelimit_reset))
|
2023-01-19 23:17:26 +08:00
|
|
|
print(f"The current rate limit window resets in {ratelimit_reset}", flush=True)
|
|
|
|
exit(1)
|
2022-08-24 01:54:24 +08:00
|
|
|
|
|
|
|
print(f"download link: {link}", flush=True)
|
|
|
|
|
2022-08-26 02:33:27 +08:00
|
|
|
with open(download_dir/tempScript, 'a') as f:
|
|
|
|
f.writelines(f'{link}\n')
|
|
|
|
f.writelines(f' dir={download_dir}\n')
|
2022-12-08 16:06:23 +08:00
|
|
|
f.writelines(f' out={file_name}\n')
|