mirror of
https://github.com/sotam0316/docker-py-revanced.git
synced 2026-04-25 11:58:37 +09:00
Use patches.json file instead of parsing the README
This commit is contained in:
@@ -176,67 +176,51 @@ class Patches(object):
|
|||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
logger.debug("fetching all patches")
|
logger.debug("fetching all patches")
|
||||||
resp = session.get(
|
resp = session.get(
|
||||||
"https://raw.githubusercontent.com/revanced/revanced-patches/main/README.md"
|
"https://raw.githubusercontent.com/revanced/revanced-patches/main/patches.json"
|
||||||
)
|
)
|
||||||
available_patches = []
|
patches = resp.json()
|
||||||
for app in resp.text.split("### 📦 ")[1:]:
|
|
||||||
lines = app.splitlines()
|
|
||||||
|
|
||||||
app_name = lines[0][1:-1]
|
app_ids = {
|
||||||
app_patches = []
|
"com.google.android.youtube": ("youtube", "_yt"),
|
||||||
for line in lines:
|
"com.google.android.apps.youtube.music": ("youtube-music", "_ytm"),
|
||||||
patch = line.split("|")[1:-1]
|
"com.reddit.frontpage": ("reddit", "_reddit"),
|
||||||
if len(patch) == 3:
|
"com.ss.android.ugc.trill": ("tiktok", "_tiktok"),
|
||||||
(n, d, v), a = [i.replace("`", "").strip() for i in patch], app_name
|
"com.twitter.android": ("twitter", "_twitter"),
|
||||||
app_patches.append((n, d, a, v))
|
"de.dwd.warnapp": ("warnwetter", "_warnwetter"),
|
||||||
|
}
|
||||||
|
|
||||||
available_patches.extend(app_patches[2:])
|
for app_name in (app_ids[x][1] for x in app_ids):
|
||||||
|
setattr(self, app_name, [])
|
||||||
|
|
||||||
youtube, music, twitter, reddit, tiktok, warnwetter = [], [], [], [], [], []
|
for patch in patches:
|
||||||
for n, d, a, v in available_patches:
|
for compatible_package, version in [
|
||||||
patch = {"name": n, "description": d, "app": a, "version": v}
|
(x["name"], x["versions"]) for x in patch["compatiblePackages"]
|
||||||
if "twitter" in a:
|
]:
|
||||||
twitter.append(patch)
|
if compatible_package in app_ids:
|
||||||
elif "reddit" in a:
|
app_name = app_ids[compatible_package][1]
|
||||||
reddit.append(patch)
|
p = {x: patch[x] for x in ["name", "description"]}
|
||||||
elif "music" in a:
|
p["app"] = compatible_package
|
||||||
music.append(patch)
|
p["version"] = version[-1] if version else "all"
|
||||||
elif "youtube" in a:
|
getattr(self, app_name).append(p)
|
||||||
youtube.append(patch)
|
|
||||||
elif "trill" in a:
|
for app_name, app_id in app_ids.values():
|
||||||
tiktok.append(patch)
|
n_patches = len(getattr(self, app_id))
|
||||||
elif "warnapp" in a:
|
logger.debug(f"Total patches in {app_name} are {n_patches}")
|
||||||
warnwetter.append(patch)
|
|
||||||
self._yt = youtube
|
|
||||||
self._ytm = music
|
|
||||||
self._twitter = twitter
|
|
||||||
self._reddit = reddit
|
|
||||||
self._tiktok = tiktok
|
|
||||||
self._warnwetter = warnwetter
|
|
||||||
logger.debug(f"Total patches in youtube are {len(youtube)}")
|
|
||||||
logger.debug(f"Total patches in youtube-music are {len(music)}")
|
|
||||||
logger.debug(f"Total patches in twitter are {len(twitter)}")
|
|
||||||
logger.debug(f"Total patches in reddit are {len(reddit)}")
|
|
||||||
logger.debug(f"Total patches in tiktok are {len(tiktok)}")
|
|
||||||
logger.debug(f"Total patches in warnwetter are {len(warnwetter)}")
|
|
||||||
|
|
||||||
def get(self, app: str) -> Tuple[List[Dict[str, str]], str]:
|
def get(self, app: str) -> Tuple[List[Dict[str, str]], str]:
|
||||||
logger.debug("Getting patches for %s" % app)
|
logger.debug("Getting patches for %s" % app)
|
||||||
if "twitter" == app:
|
app_names = {
|
||||||
patches = self._twitter
|
"reddit": "_reddit",
|
||||||
elif "reddit" == app:
|
"tiktok": "_tiktok",
|
||||||
patches = self._reddit
|
"twitter": "_twitter",
|
||||||
elif "youtube_music" == app:
|
"warnwetter": "_warnwetter",
|
||||||
patches = self._ytm
|
"youtube": "_yt",
|
||||||
elif "youtube" == app:
|
"youtube_music": "_ytm",
|
||||||
patches = self._yt
|
}
|
||||||
elif "tiktok" == app:
|
if not (app_name := app_names.get(app)):
|
||||||
patches = self._tiktok
|
|
||||||
elif "warnwetter" == app:
|
|
||||||
patches = self._warnwetter
|
|
||||||
else:
|
|
||||||
logger.debug("Invalid app name")
|
logger.debug("Invalid app name")
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
|
patches = getattr(self, app_name)
|
||||||
version = ""
|
version = ""
|
||||||
if app in ("youtube", "youtube_music"):
|
if app in ("youtube", "youtube_music"):
|
||||||
version = next(i["version"] for i in patches if i["version"] != "all")
|
version = next(i["version"] for i in patches if i["version"] != "all")
|
||||||
|
|||||||
Reference in New Issue
Block a user