🎨 Use patches.json instead of README

This commit is contained in:
Nikhil Badyal
2022-09-30 12:24:00 +05:30
parent 7ef7e02322
commit 30804615e5
+58 -75
View File
@@ -176,93 +176,76 @@ 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] revanced_app_ids = {
if app_name in [ "com.reddit.frontpage": ("reddit", "_reddit"),
"com.google.android.apps.youtube.music", "com.ss.android.ugc.trill": ("tiktok", "_tiktok"),
"com.google.android.youtube", "com.twitter.android": ("twitter", "_twitter"),
"com.vanced.android.youtube", "de.dwd.warnapp": ("warnwetter", "_warnwetter"),
}
for app_name in (revanced_app_ids[x][1] for x in revanced_app_ids):
setattr(self, app_name, [])
for patch in patches:
for compatible_package, version in [
(x["name"], x["versions"]) for x in patch["compatiblePackages"]
]: ]:
continue if compatible_package in revanced_app_ids:
app_patches = [] app_name = revanced_app_ids[compatible_package][1]
for line in lines: p = {x: patch[x] for x in ["name", "description"]}
patch = line.split("|")[1:-1] p["app"] = compatible_package
if len(patch) == 3: p["version"] = version[-1] if version else "all"
(n, d, v), a = [i.replace("`", "").strip() for i in patch], app_name getattr(self, app_name).append(p)
app_patches.append((n, d, a, v))
available_patches.extend(app_patches[2:]) resp_extended = session.get(
"https://raw.githubusercontent.com/inotia00/revanced-patches/revanced-extended/patches.json"
youtube, music, twitter, reddit, tiktok, warnwetter = [], [], [], [], [], []
for n, d, a, v in available_patches:
patch = {"name": n, "description": d, "app": a, "version": v}
if "twitter" in a:
twitter.append(patch)
elif "reddit" in a:
reddit.append(patch)
elif "trill" in a:
tiktok.append(patch)
elif "warnapp" in a:
warnwetter.append(patch)
resp = session.get(
"https://raw.githubusercontent.com/inotia00/revanced-patches/revanced-extended/README.md"
) )
for app in resp.text.split("### 📦 ")[1:]: extended_patches = resp_extended.json()
lines = app.splitlines() revanced_extended_app_ids = {
"com.google.android.youtube": ("youtube", "_yt"),
"com.google.android.apps.youtube.music": ("youtube-music", "_ytm"),
}
for app_name in (
revanced_extended_app_ids[x][1] for x in revanced_extended_app_ids
):
setattr(self, app_name, [])
app_name = lines[0][1:-1] for patch in extended_patches:
app_patches = [] for compatible_package, version in [
for line in lines: (x["name"], x["versions"]) for x in patch["compatiblePackages"]
patch = line.split("|")[1:-1] ]:
if len(patch) == 3: if compatible_package in revanced_extended_app_ids:
(n, d, v), a = [i.replace("`", "").strip() for i in patch], app_name app_name = revanced_extended_app_ids[compatible_package][1]
app_patches.append((n, d, a, v)) p = {x: patch[x] for x in ["name", "description"]}
p["app"] = compatible_package
p["version"] = version[-1] if version else "all"
getattr(self, app_name).append(p)
available_patches.extend(app_patches[2:]) for app_name, app_id in revanced_extended_app_ids.values():
n_patches = len(getattr(self, app_id))
for n, d, a, v in available_patches: logger.debug(f"Total patches in {app_name} are {n_patches}")
patch = {"name": n, "description": d, "app": a, "version": v} for app_name, app_id in revanced_app_ids.values():
if "music" in a: n_patches = len(getattr(self, app_id))
music.append(patch) logger.debug(f"Total patches in {app_name} are {n_patches}")
elif "youtube" in a:
youtube.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")