mirror of
https://github.com/LSPosed/MagiskOnWSALocal.git
synced 2025-09-02 10:41:17 +00:00
Simplify GApps and Magisk link generation scripts
Removed GitHub API authentication and asset parsing logic from generateGappsLink.py and generateMagiskLink.py. Now, download links are constructed directly using static URLs for the latest release assets, improving reliability and reducing complexity.
This commit is contained in:
parent
5066f5a9d9
commit
07e6d5baa4
2 changed files with 33 additions and 103 deletions
|
@ -15,32 +15,11 @@
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with MagiskOnWSALocal. If not, see <https://www.gnu.org/licenses/>.
|
# along with MagiskOnWSALocal. If not, see <https://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
# Copyright (C) 2024 LSPosed Contributors
|
# Copyright (C) 2025 LSPosed Contributors
|
||||||
#
|
#
|
||||||
|
|
||||||
from datetime import datetime
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import requests
|
|
||||||
import json
|
|
||||||
import re
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
class BearerAuth(requests.auth.AuthBase):
|
|
||||||
def __init__(self, token):
|
|
||||||
self.token = token
|
|
||||||
|
|
||||||
def __call__(self, r):
|
|
||||||
r.headers["authorization"] = "Bearer " + self.token
|
|
||||||
return r
|
|
||||||
|
|
||||||
|
|
||||||
github_auth = None
|
|
||||||
if Path.cwd().joinpath('token').exists():
|
|
||||||
with open(Path.cwd().joinpath('token'), 'r') as token_file:
|
|
||||||
github_auth = BearerAuth(token_file.read())
|
|
||||||
print("Using token file for authentication", flush=True)
|
|
||||||
arch = sys.argv[1]
|
arch = sys.argv[1]
|
||||||
arg2 = sys.argv[2]
|
arg2 = sys.argv[2]
|
||||||
download_dir = Path.cwd().parent / "download" if arg2 == "" else Path(arg2)
|
download_dir = Path.cwd().parent / "download" if arg2 == "" else Path(arg2)
|
||||||
|
@ -51,29 +30,12 @@ print(f"Generating GApps download link: arch={arch}", flush=True)
|
||||||
abi_map = {"x64": "x86_64", "arm64": "arm64"}
|
abi_map = {"x64": "x86_64", "arm64": "arm64"}
|
||||||
android_api_map = {"30": "11.0", "32": "12.1", "33": "13.0"}
|
android_api_map = {"30": "11.0", "32": "12.1", "33": "13.0"}
|
||||||
release = android_api_map[android_api]
|
release = android_api_map[android_api]
|
||||||
res = requests.get(f"https://api.github.com/repos/LSPosed/WSA-Addon/releases/latest", auth=github_auth)
|
|
||||||
json_data = json.loads(res.content)
|
|
||||||
headers = res.headers
|
|
||||||
x_ratelimit_remaining = headers["x-ratelimit-remaining"]
|
|
||||||
if res.status_code == 200:
|
|
||||||
download_files = {}
|
download_files = {}
|
||||||
assets = json_data["assets"]
|
download_files[f"gapps-{release}.rc"] = f"https://github.com/LSPosed/WSA-Addon/releases/latest/download/gapps-{release}.rc"
|
||||||
for asset in assets:
|
download_files[f"gapps-{release}-{abi_map[arch]}.img"] = f"https://github.com/LSPosed/WSA-Addon/releases/latest/download/gapps-{release}-{abi_map[arch]}.img"
|
||||||
if re.match(rf'gapps.*{release}.*\.rc$', asset["name"]):
|
with open(download_dir / tempScript, "a") as f:
|
||||||
download_files[asset["name"]] = asset["browser_download_url"]
|
|
||||||
elif re.match(rf'gapps.*{release}.*{abi_map[arch]}.*\.img$', asset["name"]):
|
|
||||||
download_files[asset["name"]] = asset["browser_download_url"]
|
|
||||||
with open(download_dir/tempScript, 'a') as f:
|
|
||||||
for key, value in download_files.items():
|
for key, value in download_files.items():
|
||||||
print(f"download link: {value}\npath: {download_dir / key}\n", flush=True)
|
print(f"download link: {value}\npath: {download_dir / key}\n", flush=True)
|
||||||
f.writelines(value + '\n')
|
f.writelines(value + "\n")
|
||||||
f.writelines(f' dir={download_dir}\n')
|
f.writelines(f" dir={download_dir}\n")
|
||||||
f.writelines(f' out={key}\n')
|
f.writelines(f" out={key}\n")
|
||||||
elif res.status_code == 403 and x_ratelimit_remaining == '0':
|
|
||||||
message = json_data["message"]
|
|
||||||
print(f"Github API Error: {message}", flush=True)
|
|
||||||
ratelimit_reset = headers["x-ratelimit-reset"]
|
|
||||||
ratelimit_reset = datetime.fromtimestamp(int(ratelimit_reset))
|
|
||||||
print(
|
|
||||||
f"The current rate limit window resets in {ratelimit_reset}", flush=True)
|
|
||||||
exit(1)
|
|
||||||
|
|
|
@ -15,55 +15,42 @@
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with MagiskOnWSALocal. If not, see <https://www.gnu.org/licenses/>.
|
# along with MagiskOnWSALocal. If not, see <https://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
# Copyright (C) 2023 LSPosed Contributors
|
# Copyright (C) 2025 LSPosed Contributors
|
||||||
#
|
#
|
||||||
|
|
||||||
from datetime import datetime
|
|
||||||
import re
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import requests
|
import requests
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
class BearerAuth(requests.auth.AuthBase):
|
|
||||||
def __init__(self, token):
|
|
||||||
self.token = token
|
|
||||||
|
|
||||||
def __call__(self, r):
|
|
||||||
r.headers["authorization"] = "Bearer " + self.token
|
|
||||||
return r
|
|
||||||
|
|
||||||
|
|
||||||
github_auth = None
|
|
||||||
if Path.cwd().joinpath('token').exists():
|
|
||||||
with open(Path.cwd().joinpath('token'), 'r') as token_file:
|
|
||||||
github_auth = BearerAuth(token_file.read())
|
|
||||||
print("Using token file for authentication", flush=True)
|
|
||||||
|
|
||||||
magisk_ver = sys.argv[1]
|
magisk_ver = sys.argv[1]
|
||||||
download_dir = Path.cwd().parent / \
|
download_dir = (Path.cwd().parent / "download" if sys.argv[2] == "" else Path(sys.argv[2]))
|
||||||
"download" if sys.argv[2] == "" else Path(sys.argv[2])
|
|
||||||
tempScript = sys.argv[3]
|
tempScript = sys.argv[3]
|
||||||
download_files = {}
|
download_files = {}
|
||||||
cdn_hosts=["cdn.jsdelivr.net", "fastly.jsdelivr.net", "testingcf.jsdelivr.net", "gcore.jsdelivr.net"]
|
cdn_hosts = [
|
||||||
print(
|
"cdn.jsdelivr.net",
|
||||||
f"Generating Magisk download link: release type={magisk_ver}", flush=True)
|
"fastly.jsdelivr.net",
|
||||||
|
"testingcf.jsdelivr.net",
|
||||||
|
"gcore.jsdelivr.net",
|
||||||
|
]
|
||||||
|
print(f"Generating Magisk download link: release type={magisk_ver}", flush=True)
|
||||||
magisk_link = None
|
magisk_link = None
|
||||||
if not magisk_ver:
|
if not magisk_ver:
|
||||||
magisk_ver = "stable"
|
magisk_ver = "stable"
|
||||||
if magisk_ver == "stable" or magisk_ver == "beta" or magisk_ver == "canary" or magisk_ver == "debug":
|
if (
|
||||||
|
magisk_ver == "stable"
|
||||||
|
or magisk_ver == "beta"
|
||||||
|
or magisk_ver == "canary"
|
||||||
|
or magisk_ver == "debug"
|
||||||
|
):
|
||||||
try:
|
try:
|
||||||
magisk_link = json.loads(requests.get(
|
magisk_link = json.loads(requests.get(f"https://topjohnwu.github.io/magisk-files/{magisk_ver}.json").content)["magisk"]["link"]
|
||||||
f"https://topjohnwu.github.io/magisk-files/{magisk_ver}.json").content)['magisk']['link']
|
|
||||||
download_files[f"magisk-{magisk_ver}.zip"] = magisk_link
|
download_files[f"magisk-{magisk_ver}.zip"] = magisk_link
|
||||||
except Exception:
|
except Exception:
|
||||||
print("Failed to fetch from GitHub API, fallbacking to jsdelivr...")
|
print("Failed to fetch from GitHub API, fallbacking to jsdelivr...")
|
||||||
for host in cdn_hosts:
|
for host in cdn_hosts:
|
||||||
try:
|
try:
|
||||||
magisk_link = json.loads(requests.get(
|
magisk_link = json.loads(requests.get(f"https://{host}/gh/topjohnwu/magisk-files@master/{magisk_ver}.json").content)["magisk"]["link"]
|
||||||
f"https://{host}/gh/topjohnwu/magisk-files@master/{magisk_ver}.json").content)['magisk']['link']
|
|
||||||
download_files[f"magisk-{magisk_ver}.zip"] = magisk_link
|
download_files[f"magisk-{magisk_ver}.zip"] = magisk_link
|
||||||
break
|
break
|
||||||
except Exception:
|
except Exception:
|
||||||
|
@ -73,30 +60,11 @@ if magisk_ver == "stable" or magisk_ver == "beta" or magisk_ver == "canary" or m
|
||||||
if magisk_link is None:
|
if magisk_link is None:
|
||||||
print("Failed to fetch Magisk download link", flush=True)
|
print("Failed to fetch Magisk download link", flush=True)
|
||||||
exit(1)
|
exit(1)
|
||||||
res = requests.get(
|
|
||||||
f"https://api.github.com/repos/LSPosed/WSA-Addon/releases/latest", auth=github_auth)
|
|
||||||
json_data = json.loads(res.content)
|
|
||||||
headers = res.headers
|
|
||||||
x_ratelimit_remaining = headers["x-ratelimit-remaining"]
|
|
||||||
if res.status_code == 200:
|
|
||||||
assets = json_data["assets"]
|
|
||||||
for asset in assets:
|
|
||||||
if re.match(f'cust.img$', asset["name"]):
|
|
||||||
download_files[asset["name"]] = asset["browser_download_url"]
|
|
||||||
break
|
|
||||||
|
|
||||||
elif res.status_code == 403 and x_ratelimit_remaining == '0':
|
download_files["cust.img"] = "https://github.com/LSPosed/WSA-Addon/releases/latest/download/cust.img"
|
||||||
message = json_data["message"]
|
with open(download_dir / tempScript, "a") as f:
|
||||||
print(f"Github API Error: {message}", flush=True)
|
|
||||||
ratelimit_reset = headers["x-ratelimit-reset"]
|
|
||||||
ratelimit_reset = datetime.fromtimestamp(int(ratelimit_reset))
|
|
||||||
print(
|
|
||||||
f"The current rate limit window resets in {ratelimit_reset}", flush=True)
|
|
||||||
exit(1)
|
|
||||||
with open(download_dir/tempScript, 'a') as f:
|
|
||||||
for key, value in download_files.items():
|
for key, value in download_files.items():
|
||||||
print(
|
print(f"download link: {value}\npath: {download_dir / key}\n", flush=True)
|
||||||
f"download link: {value}\npath: {download_dir / key}\n", flush=True)
|
f.writelines(value + "\n")
|
||||||
f.writelines(value + '\n')
|
f.writelines(f" dir={download_dir}\n")
|
||||||
f.writelines(f' dir={download_dir}\n')
|
f.writelines(f" out={key}\n")
|
||||||
f.writelines(f' out={key}\n')
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue