Skip to content

Commit 6b8abb2

Browse files
committed
feature: added gcam download support
1 parent 9d29fcf commit 6b8abb2

File tree

7 files changed

+82
-14
lines changed

7 files changed

+82
-14
lines changed

config.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,10 @@ custom:
8888
- app: Microsoft Teams
8989
package: com.microsoft.teams
9090
source: playstore
91+
92+
- app: Google Camera
93+
args:
94+
- best # Depends on device codename
95+
# or provide a direct link
96+
# - https://www.celsoazevedo.com/files/android/google-camera/f/changelog1500/
97+
source: gcam

device_config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"codename": "begonia",
23
"android": 11,
34
"arch": "arm64-v8a",
45
"dpi": 480

xapps2/apkdl.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import logging
33
import sys
44
from random import choice, sample
5-
from typing import List
5+
from typing import List, Optional
66

77
import pyppeteer
88

@@ -15,9 +15,10 @@
1515

1616
class ApkDL(Http, PlayStoreDL, MiscDL):
1717
browser: pyppeteer.browser.Browser
18-
user_agents: List[str]
18+
user_agents: Optional[List[str]]
1919

2020
def __init__(self) -> None:
21+
self.user_agents = None
2122
super().__init__()
2223

2324
async def load_useragents(self) -> None:
@@ -28,14 +29,18 @@ async def load_useragents(self) -> None:
2829
if resp.status == 200:
2930
text = await resp.text()
3031
self.user_agents = sample(text.split("\n"), 10)
31-
else:
32-
self.user_agents = [
33-
(
34-
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
35-
"AppleWebKit/537.36 (KHTML, like Gecko) "
36-
"Chrome/74.0.3729.157 Safari/537.36"
37-
)
38-
]
32+
33+
@property
34+
def ua(self) -> str:
35+
return (
36+
choice(self.user_agents)
37+
if self.user_agents
38+
else (
39+
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
40+
"AppleWebKit/537.36 (KHTML, like Gecko) "
41+
"Chrome/74.0.3729.157 Safari/537.36"
42+
)
43+
)
3944

4045
async def start(self) -> None:
4146
try:

xapps2/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
@dataclass
1010
class Device:
1111
android: Literal[9, 10, 11, 12]
12+
codename: str = ""
1213
arch: Literal["armeabi-v7a", "arm64-v8a", "x86", "x86_64"] = "arm64-v8a"
1314
dpi: Literal[120, 160, 240, 320, 480] = 480
1415
android_str: str = field(init=False)

xapps2/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ async def main():
5050
source = app["source"]
5151
if source in ("fdroid", "playstore"):
5252
tasks.append((apk_name, sem, getattr(apk_dl, source)(app["package"])))
53-
elif source == "github":
54-
tasks.append((apk_name, sem, apk_dl.github(*app["args"])))
53+
elif source in ("github", "gcam"):
54+
tasks.append((apk_name, sem, getattr(apk_dl, source)(*app["args"])))
5555

5656
urls = await asyncio.gather(*map(lambda x: limit_coro(*x), tasks))
5757

xapps2/miscdl.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,29 @@ class Sources:
1717
instander: str = "https://raw.githubusercontent.com/the-dise/the-dise.github.io/master/instander/ota.json"
1818

1919

20+
class Gcam:
21+
headers: Dict[str, str] = {
22+
"upgrade-insecure-requests": "1",
23+
"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",
24+
"sec-fetch-site": "same-site",
25+
"sec-fetch-mode": "navigate",
26+
"sec-fetch-user": "?1",
27+
"sec-fetch-dest": "document",
28+
"referer": "https://www.celsoazevedo.com/",
29+
"accept-language": "en-US,en;q=0.9",
30+
}
31+
regex: Pattern = re.compile(
32+
r"(?<=<a\shref=\")https://(?P<cdn>[\w-]+)\.celsoazevedo\.com/file/(?P<path>\w+/(?P<filename>[\w.-]+\.apk))(?=\">)"
33+
)
34+
cdns: Dict[str, str] = {
35+
"1-dontsharethislink": "7-dontsharethislink",
36+
"f": "temp4-f",
37+
}
38+
best: Dict[str, str] = {
39+
"begonia": "https://www.celsoazevedo.com/files/android/google-camera/dev-wichaya/f/dl3/"
40+
}
41+
42+
2043
class MiscDL:
2144
mixplorer_regex: Pattern
2245

@@ -91,3 +114,35 @@ async def niksgapps(self, varient: str = "basic") -> Optional[str]:
91114
r"<a href=\"(?P<link>\S+)\">direct\slink</a>", text
92115
):
93116
return match.group("link")
117+
118+
async def gcam(self, *args) -> Optional[str]:
119+
if not args:
120+
return
121+
122+
arg1 = args[0].strip()
123+
if arg1 == "best":
124+
gcam_link = Gcam.best.get(DEVICE.codename)
125+
elif arg1.startswith("https://"):
126+
gcam_link = arg1
127+
128+
if not gcam_link:
129+
return
130+
131+
async with self.http.get(gcam_link) as resp:
132+
assert resp.status == 200
133+
text = await resp.text()
134+
if match := Gcam.regex.search(text):
135+
cdn = match.group("cdn")
136+
if cdn in Gcam.cdns:
137+
return f"https://{Gcam.cdns[cdn]}.celsoazevedo.com/file/{match.group('path')}"
138+
139+
async with self.http.get(
140+
match.group(0),
141+
allow_redirects=True,
142+
headers={
143+
"authority": f"{cdn}.celsoazevedo.com",
144+
"User-Agent": self.ua,
145+
**Gcam.headers,
146+
},
147+
) as response:
148+
return response.url

xapps2/playstoredl.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import asyncio
44
import logging
5-
from random import choice
65
from typing import Dict, Optional, Union
76
from urllib.parse import urlencode
87

@@ -31,7 +30,7 @@ def __init__(self):
3130

3231
async def _playstore_fetch(self, package_name: str) -> Optional[str]:
3332
page = await self.browser.newPage()
34-
await page.setUserAgent(choice(self.user_agents))
33+
await page.setUserAgent(self.ua)
3534
url = f"{self.dl_site}?{urlencode({'package': package_name.strip(), **self.params})}"
3635
await page.goto(url)
3736
element = None

0 commit comments

Comments
 (0)