Skip to content

Commit

Permalink
feature: added gcam download support
Browse files Browse the repository at this point in the history
  • Loading branch information
code-rgb committed Aug 19, 2021
1 parent 9d29fcf commit 6b8abb2
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 14 deletions.
7 changes: 7 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions device_config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"codename": "begonia",
"android": 11,
"arch": "arm64-v8a",
"dpi": 480
Expand Down
25 changes: 15 additions & 10 deletions xapps2/apkdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging
import sys
from random import choice, sample
from typing import List
from typing import List, Optional

import pyppeteer

Expand All @@ -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:
Expand All @@ -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:
Expand Down
1 change: 1 addition & 0 deletions xapps2/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions xapps2/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
55 changes: 55 additions & 0 deletions xapps2/miscdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"(?<=<a\shref=\")https://(?P<cdn>[\w-]+)\.celsoazevedo\.com/file/(?P<path>\w+/(?P<filename>[\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

Expand Down Expand Up @@ -91,3 +114,35 @@ async def niksgapps(self, varient: str = "basic") -> Optional[str]:
r"<a href=\"(?P<link>\S+)\">direct\slink</a>", 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
3 changes: 1 addition & 2 deletions xapps2/playstoredl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import asyncio
import logging
from random import choice
from typing import Dict, Optional, Union
from urllib.parse import urlencode

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6b8abb2

Please sign in to comment.