diff --git a/config.yaml b/config.yaml index c777830..660b3dc 100644 --- a/config.yaml +++ b/config.yaml @@ -88,3 +88,10 @@ custom: - app: Microsoft Teams package: com.microsoft.teams source: playstore + + - app: Google Camera + args: + - best # Depends on device codename + # or provide a direct link + # - https://www.celsoazevedo.com/files/android/google-camera/f/changelog1500/ + source: gcam diff --git a/device_config.json b/device_config.json index c3036e3..a6b0494 100644 --- a/device_config.json +++ b/device_config.json @@ -1,4 +1,5 @@ { + "codename": "begonia", "android": 11, "arch": "arm64-v8a", "dpi": 480 diff --git a/xapps2/apkdl.py b/xapps2/apkdl.py index 3b2672a..6cb213d 100644 --- a/xapps2/apkdl.py +++ b/xapps2/apkdl.py @@ -2,7 +2,7 @@ import logging import sys from random import choice, sample -from typing import List +from typing import List, Optional import pyppeteer @@ -15,9 +15,10 @@ class ApkDL(Http, PlayStoreDL, MiscDL): browser: pyppeteer.browser.Browser - user_agents: List[str] + user_agents: Optional[List[str]] def __init__(self) -> None: + self.user_agents = None super().__init__() async def load_useragents(self) -> None: @@ -28,14 +29,18 @@ async def load_useragents(self) -> None: if resp.status == 200: text = await resp.text() self.user_agents = sample(text.split("\n"), 10) - else: - self.user_agents = [ - ( - "Mozilla/5.0 (Windows NT 10.0; Win64; x64) " - "AppleWebKit/537.36 (KHTML, like Gecko) " - "Chrome/74.0.3729.157 Safari/537.36" - ) - ] + + @property + def ua(self) -> str: + return ( + choice(self.user_agents) + if self.user_agents + else ( + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) " + "AppleWebKit/537.36 (KHTML, like Gecko) " + "Chrome/74.0.3729.157 Safari/537.36" + ) + ) async def start(self) -> None: try: diff --git a/xapps2/config.py b/xapps2/config.py index 4d2d308..2b5c67c 100644 --- a/xapps2/config.py +++ b/xapps2/config.py @@ -9,6 +9,7 @@ @dataclass class Device: android: Literal[9, 10, 11, 12] + codename: str = "" arch: Literal["armeabi-v7a", "arm64-v8a", "x86", "x86_64"] = "arm64-v8a" dpi: Literal[120, 160, 240, 320, 480] = 480 android_str: str = field(init=False) diff --git a/xapps2/main.py b/xapps2/main.py index d547691..e2a3292 100644 --- a/xapps2/main.py +++ b/xapps2/main.py @@ -50,8 +50,8 @@ async def main(): source = app["source"] if source in ("fdroid", "playstore"): tasks.append((apk_name, sem, getattr(apk_dl, source)(app["package"]))) - elif source == "github": - tasks.append((apk_name, sem, apk_dl.github(*app["args"]))) + elif source in ("github", "gcam"): + tasks.append((apk_name, sem, getattr(apk_dl, source)(*app["args"]))) urls = await asyncio.gather(*map(lambda x: limit_coro(*x), tasks)) diff --git a/xapps2/miscdl.py b/xapps2/miscdl.py index 0644cb1..7eed096 100644 --- a/xapps2/miscdl.py +++ b/xapps2/miscdl.py @@ -17,6 +17,29 @@ class Sources: instander: str = "https://raw.githubusercontent.com/the-dise/the-dise.github.io/master/instander/ota.json" +class Gcam: + headers: Dict[str, str] = { + "upgrade-insecure-requests": "1", + "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9", + "sec-fetch-site": "same-site", + "sec-fetch-mode": "navigate", + "sec-fetch-user": "?1", + "sec-fetch-dest": "document", + "referer": "https://www.celsoazevedo.com/", + "accept-language": "en-US,en;q=0.9", + } + regex: Pattern = re.compile( + r"(?<=[\w-]+)\.celsoazevedo\.com/file/(?P\w+/(?P[\w.-]+\.apk))(?=\">)" + ) + cdns: Dict[str, str] = { + "1-dontsharethislink": "7-dontsharethislink", + "f": "temp4-f", + } + best: Dict[str, str] = { + "begonia": "https://www.celsoazevedo.com/files/android/google-camera/dev-wichaya/f/dl3/" + } + + class MiscDL: mixplorer_regex: Pattern @@ -91,3 +114,35 @@ async def niksgapps(self, varient: str = "basic") -> Optional[str]: r"\S+)\">direct\slink", text ): return match.group("link") + + async def gcam(self, *args) -> Optional[str]: + if not args: + return + + arg1 = args[0].strip() + if arg1 == "best": + gcam_link = Gcam.best.get(DEVICE.codename) + elif arg1.startswith("https://"): + gcam_link = arg1 + + if not gcam_link: + return + + async with self.http.get(gcam_link) as resp: + assert resp.status == 200 + text = await resp.text() + if match := Gcam.regex.search(text): + cdn = match.group("cdn") + if cdn in Gcam.cdns: + return f"https://{Gcam.cdns[cdn]}.celsoazevedo.com/file/{match.group('path')}" + + async with self.http.get( + match.group(0), + allow_redirects=True, + headers={ + "authority": f"{cdn}.celsoazevedo.com", + "User-Agent": self.ua, + **Gcam.headers, + }, + ) as response: + return response.url diff --git a/xapps2/playstoredl.py b/xapps2/playstoredl.py index f3704b6..e9bb083 100644 --- a/xapps2/playstoredl.py +++ b/xapps2/playstoredl.py @@ -2,7 +2,6 @@ import asyncio import logging -from random import choice from typing import Dict, Optional, Union from urllib.parse import urlencode @@ -31,7 +30,7 @@ def __init__(self): async def _playstore_fetch(self, package_name: str) -> Optional[str]: page = await self.browser.newPage() - await page.setUserAgent(choice(self.user_agents)) + await page.setUserAgent(self.ua) url = f"{self.dl_site}?{urlencode({'package': package_name.strip(), **self.params})}" await page.goto(url) element = None