Merge pull request #19 from sheeit/main

Use patches.json file instead of parsing the README
This commit is contained in:
Nikhil Badyal
2022-09-30 11:43:49 +05:30
committed by GitHub
+36 -52
View File
@@ -176,67 +176,51 @@ class Patches(object):
def __init__(self) -> None:
logger.debug("fetching all patches")
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 = []
for app in resp.text.split("### 📦 ")[1:]:
lines = app.splitlines()
patches = resp.json()
app_name = lines[0][1:-1]
app_patches = []
for line in lines:
patch = line.split("|")[1:-1]
if len(patch) == 3:
(n, d, v), a = [i.replace("`", "").strip() for i in patch], app_name
app_patches.append((n, d, a, v))
app_ids = {
"com.google.android.youtube": ("youtube", "_yt"),
"com.google.android.apps.youtube.music": ("youtube-music", "_ytm"),
"com.reddit.frontpage": ("reddit", "_reddit"),
"com.ss.android.ugc.trill": ("tiktok", "_tiktok"),
"com.twitter.android": ("twitter", "_twitter"),
"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 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 "music" in a:
music.append(patch)
elif "youtube" in a:
youtube.append(patch)
elif "trill" in a:
tiktok.append(patch)
elif "warnapp" in a:
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)}")
for patch in patches:
for compatible_package, version in [
(x["name"], x["versions"]) for x in patch["compatiblePackages"]
]:
if compatible_package in app_ids:
app_name = app_ids[compatible_package][1]
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)
for app_name, app_id in app_ids.values():
n_patches = len(getattr(self, app_id))
logger.debug(f"Total patches in {app_name} are {n_patches}")
def get(self, app: str) -> Tuple[List[Dict[str, str]], str]:
logger.debug("Getting patches for %s" % app)
if "twitter" == app:
patches = self._twitter
elif "reddit" == app:
patches = self._reddit
elif "youtube_music" == app:
patches = self._ytm
elif "youtube" == app:
patches = self._yt
elif "tiktok" == app:
patches = self._tiktok
elif "warnwetter" == app:
patches = self._warnwetter
else:
app_names = {
"reddit": "_reddit",
"tiktok": "_tiktok",
"twitter": "_twitter",
"warnwetter": "_warnwetter",
"youtube": "_yt",
"youtube_music": "_ytm",
}
if not (app_name := app_names.get(app)):
logger.debug("Invalid app name")
sys.exit(-1)
patches = getattr(self, app_name)
version = ""
if app in ("youtube", "youtube_music"):
version = next(i["version"] for i in patches if i["version"] != "all")