Fallback to sourceforge rss when opengapps api fails (#170)

This commit is contained in:
LoveSy 2022-01-09 19:11:54 +08:00 committed by GitHub
parent d28ed1f18b
commit 3e5dbc2633
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -148,16 +148,19 @@ jobs:
import os import os
import urllib.request import urllib.request
import json import json
import re
arch = "${{ matrix.arch }}" arch = "${{ matrix.arch }}"
variant = "${{ github.event.inputs.gapps_variant }}" variant = "${{ github.event.inputs.gapps_variant }}"
abi_map = {"x64" : "x86_64", "arm64": "arm64"} abi_map = {"x64" : "x86_64", "arm64": "arm64"}
try:
res = requests.get(f"https://api.opengapps.org/list") res = requests.get(f"https://api.opengapps.org/list")
j = json.loads(res.content) j = json.loads(res.content)
link = {i["name"]: i for i in j["archs"][abi_map[arch]]["apis"]["11.0"]["variants"]}[variant]["zip"] link = {i["name"]: i for i in j["archs"][abi_map[arch]]["apis"]["11.0"]["variants"]}[variant]["zip"]
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]}/.*{variant}.*\.zip/download', res.text).group().replace('.zip/download', '.zip').replace('sourceforge.net/projects/opengapps/files', 'downloads.sourceforge.net/project/opengapps')
print(f"downloading link: {link}", flush=True) print(f"downloading link: {link}", flush=True)