diff --git a/.github/workflows/newapp-check.yml b/.github/workflows/newapp-check.yml index ce87b0e..8f24701 100644 --- a/.github/workflows/newapp-check.yml +++ b/.github/workflows/newapp-check.yml @@ -3,7 +3,14 @@ name: Check for new Revanced apps on: schedule: - cron: "0 0 * * *" + push: workflow_dispatch: + inputs: + CREATE_ISSUE: + description: "Create GitHub issue" + required: false + type: boolean + default: false jobs: status_check: @@ -33,9 +40,18 @@ jobs: id: status - name: Update Check - run: echo "${{ steps.status.outputs.changelog }}" + run: | + run: echo "${{ steps.status.outputs.changelog }}" + + - name: Upload status file + uses: actions/upload-artifact@main + with: + name: issue_body.md + path: status.md + if-no-files-found: error - name: Create Issue Action + if: inputs.CREATE_ISSUE uses: nashmaniac/create-issue-action@v1.2 with: title: Revanced apps Status diff --git a/.gitignore b/.gitignore index aba434d..fb39251 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ venv changelog.md .idea *.json +status.md diff --git a/scripts/status_check.py b/scripts/status_check.py index 25ae44b..d8dab4a 100644 --- a/scripts/status_check.py +++ b/scripts/status_check.py @@ -1,8 +1,12 @@ """Status check.""" +import json +import re from typing import List import requests +from bs4 import BeautifulSoup from google_play_scraper import app as gplay_app +from google_play_scraper.exceptions import GooglePlayScraperException from src.patches import Patches from src.utils import handle_response @@ -10,6 +14,46 @@ from src.utils import handle_response not_found_icon = "https://img.icons8.com/bubbles/500/android-os.png" +def apkmirror_scrapper(package_name: str) -> str: + """Apkmirror URL.""" + apk_mirror_base_url = "https://www.apkmirror.com" + check_if_exist = f"{apk_mirror_base_url}/wp-json/apkm/v1/app_exists/" + body = {"pnames": [package_name]} + check_header = { + "User-Agent": "APKUpdater-v" + "3.0.1", + "Authorization": "Basic YXBpLWFwa3VwZGF0ZXI6cm01cmNmcnVVakt5MDRzTXB5TVBKWFc4", + "Content-Type": "application/json", + } + response = json.loads( + requests.post( + check_if_exist, data=json.dumps(body), headers=check_header + ).content + ) + if response["data"][0]["exists"]: + headers = { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) " + "AppleWebKit/537.36 (KHTML, like Gecko)" + " Chrome/96.0.4664.93 Safari/537.36" + } + search_url = f"{apk_mirror_base_url}/?s={package_name}" + r = requests.get(search_url, headers=headers) + soup = BeautifulSoup(r.text, "html.parser") + sub_url = soup.select_one("div.bubble-wrap > img")["src"] + new_width = 500 + new_height = 500 + new_quality = 100 + + # regular expression pattern to match w=xx&h=xx&q=xx + pattern = r"(w=\d+&h=\d+&q=\d+)" + + # Replace the matched patterns with the new dimensions and q value + apk_mirror_url = apk_mirror_base_url + re.sub( + pattern, f"w={new_width}&h={new_height}&q={new_quality}", sub_url + ) + return apk_mirror_url + return not_found_icon + + def gplay_icon_scrapper(package_name: str) -> str: """Scrap Icon from Gplay.""" # noinspection PyBroadException @@ -17,9 +61,11 @@ def gplay_icon_scrapper(package_name: str) -> str: result = gplay_app( package_name, ) - if not result["icon"]: - raise ValueError() - return str(result["icon"]) + if result["icon"]: + return str(result["icon"]) + raise GooglePlayScraperException() + except GooglePlayScraperException: + return apkmirror_scrapper(package_name) except Exception: return not_found_icon @@ -57,7 +103,7 @@ def main() -> None: possible_apps.add(compatible_package["name"]) supported_app = set(Patches.support_app().keys()) - missing_support = possible_apps.difference(supported_app) + missing_support = sorted(possible_apps.difference(supported_app)) output = "New app found which aren't supported or outdated.\n\n" data = [] for index, app in enumerate(missing_support): @@ -72,6 +118,8 @@ def main() -> None: ) table = generate_markdown_table(data) output += table + with open("status.md", "w", encoding="utf_8") as status: + status.write(output) print(output)