-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathandroid.py
162 lines (147 loc) · 5.07 KB
/
android.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import json
from bs4 import BeautifulSoup
from requests import get
from zthon import zedub
from ..core.managers import edit_delete, edit_or_reply
plugin_category = "آخرى"
@zedub.zed_cmd(
pattern="magisk$",
command=("magisk", plugin_category),
info={
"header": "To Get latest Magisk releases",
"usage": "{tr}magisk",
},
)
async def kakashi(event):
"Get latest Magisk releases"
magisk_repo = "https://raw.githubusercontent.com/topjohnwu/magisk-files/"
magisk_dict = {
"⦁ **Stable**": f"{magisk_repo}master/stable.json",
"⦁ **Beta**": f"{magisk_repo}master/beta.json",
"⦁ **Canary**": f"{magisk_repo}master/canary.json",
}
releases = "**Latest Magisk Releases**\n\n"
for name, release_url in magisk_dict.items():
data = get(release_url).json()
releases += (
f'{name}: [APK v{data["magisk"]["version"]}]({data["magisk"]["link"]}) | '
f'[Changelog]({data["magisk"]["note"]})\n'
)
await edit_or_reply(event, releases)
@zedub.zed_cmd(
pattern="device(?: |$)(\S*)",
command=("device", plugin_category),
info={
"header": "To get android device name/model from its codename",
"usage": "{tr}device <codename>",
"examples": "{tr}device whyred",
},
)
async def device_info(event):
"get android device name from its codename"
textx = await event.get_reply_message()
codename = event.pattern_match.group(1)
if not codename:
if textx:
codename = textx.text
else:
return await edit_delete(event, "`Usage: .device <codename> / <model>`")
data = json.loads(
get(
"https://raw.githubusercontent.com/androidtrackers/"
"certified-android-devices/master/by_device.json"
).text
)
if results := data.get(codename):
reply = f"**Search results for `{codename}` :**\n\n"
for item in results:
reply += (
f"**Brand**: `{item['brand']}`\n"
f"**Name**: `{item['name']}`\n"
f"**Model**: `{item['model']}`\n\n"
)
else:
reply = f"`Couldn't find info about {codename}!`\n"
await edit_or_reply(event, reply)
@zedub.zed_cmd(
pattern="codename(?: |)([\S]*)(?: |)([\s\S]*)",
command=("codename", plugin_category),
info={
"header": "To Search for android device codename",
"usage": "{tr}codename <brand> <device>",
"examples": "{tr}codename Xiaomi Redmi Note 5 Pro",
},
)
async def codename_info(event):
textx = await event.get_reply_message()
brand = event.pattern_match.group(1).lower()
device = event.pattern_match.group(2).lower()
if brand and device:
pass
elif textx:
brand = textx.text.split(" ")[0]
device = " ".join(textx.text.split(" ")[1:])
else:
return await edit_delete(event, "`Usage: .codename <brand> <device>`")
data = json.loads(
get(
"https://raw.githubusercontent.com/androidtrackers/"
"certified-android-devices/master/by_brand.json"
).text
)
devices_lower = {k.lower(): v for k, v in data.items()}
devices = devices_lower.get(brand)
if not devices:
return await edit_or_reply(event, f"__I couldn't find {brand}.__")
if results := [
i
for i in devices
if i["name"].lower() == device.lower() or i["model"].lower() == device.lower()
]:
reply = f"**Search results for {brand} {device}**:\n\n"
if len(results) > 8:
results = results[:8]
for item in results:
reply += (
f"**Device**: `{item['device']}`\n"
f"**Name**: `{item['name']}`\n"
f"**Model**: `{item['model']}`\n\n"
)
else:
reply = f"`Couldn't find {device} codename!`\n"
await edit_or_reply(event, reply)
@zedub.zed_cmd(
pattern="twrp(?: |$)(\S*)",
command=("twrp", plugin_category),
info={
"header": "To Get latest twrp download links for android device.",
"usage": "{tr}twrp <codename>",
"examples": "{tr}twrp whyred",
},
)
async def twrp(event):
"get android device twrp"
textx = await event.get_reply_message()
device = event.pattern_match.group(1)
if device:
pass
elif textx:
device = textx.text.split(" ")[0]
else:
return await edit_delete(event, "`Usage: .twrp <codename>`")
url = get(f"https://dl.twrp.me/{device}/")
if url.status_code == 404:
reply = f"`Couldn't find twrp downloads for {device}!`\n"
return await edit_delete(event, reply)
page = BeautifulSoup(url.content, "lxml")
download = page.find("table").find("tr").find("a")
dl_link = f"https://dl.twrp.me{download['href']}"
dl_file = download.text
size = page.find("span", {"class": "filesize"}).text
date = page.find("em").text.strip()
reply = (
f"**Latest TWRP for {device}:**\n"
f"[{dl_file}]({dl_link}) - __{size}__\n"
f"**Updated:** __{date}__\n"
)
await edit_or_reply(event, reply)