#!/bin/bash

# Generic script, the repo uses gitea actions workflow

wget "$1" \
  --progress=dot:mega \
  -O input.apk

curl -s https://api.github.com/repos/ReVanced/revanced-cli/releases/latest | \
  jq --raw-output '.assets[0] | .browser_download_url' | \
  wget --progress=dot:mega -i - -O revanced-cli.jar

curl -s https://api.github.com/repos/ReVanced/revanced-patches/releases/latest | \
  jq --raw-output '.assets[0] | .browser_download_url' | \
  wget --progress=dot -i - -O revanced-patches.rvp

java -jar revanced-cli.jar patch \
  --custom-aapt2-binary=lib/arm64-v8a/libaapt2.so \
  --keystore=youtube-revanced.keystore \
  -bp=revanced-patches.rvp \
  -o=youtube-revanced.apk \
  input.apk
