From 3e5dbc2633269778fbc086ddbdc82be7e8fe7401 Mon Sep 17 00:00:00 2001 From: LoveSy Date: Sun, 9 Jan 2022 19:11:54 +0800 Subject: [PATCH] Fallback to sourceforge rss when opengapps api fails (#170) --- .github/workflows/magisk.yml | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/.github/workflows/magisk.yml b/.github/workflows/magisk.yml index 4f9d489..bc5cedb 100644 --- a/.github/workflows/magisk.yml +++ b/.github/workflows/magisk.yml @@ -148,16 +148,19 @@ jobs: import os import urllib.request import json + import re arch = "${{ matrix.arch }}" variant = "${{ github.event.inputs.gapps_variant }}" abi_map = {"x64" : "x86_64", "arm64": "arm64"} - - 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"]["11.0"]["variants"]}[variant]["zip"] + 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"]["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)