-
Notifications
You must be signed in to change notification settings - Fork 18
/
main.py
136 lines (104 loc) · 3.79 KB
/
main.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
from apkmirror import Version, Variant
from build_variants import build_apks
from download_bins import download_apkeditor, download_revanced_bins
import github
from utils import panic, merge_apk, publish_release, report_to_telegram
from download_bins import download_release_asset
import apkmirror
import os
import argparse
def get_latest_release(versions: list[Version]) -> Version | None:
for i in versions:
if i.version.find("release") >= 0:
return i
def process(latest_version: Version):
# get bundle and universal variant
variants: list[Variant] = apkmirror.get_variants(latest_version)
download_link: Variant | None = None
for variant in variants:
if variant.is_bundle and variant.arcithecture == "universal":
download_link = variant
break
if download_link is None:
raise Exception("Bundle not Found")
apkmirror.download_apk(download_link)
if not os.path.exists("big_file.apkm"):
panic("Failed to download apk")
download_apkeditor()
if not os.path.exists("big_file_merged.apk"):
merge_apk("big_file.apkm")
else:
print("apkm is already merged")
download_revanced_bins()
print("Downloading patches")
pikoRelease = download_release_asset(
"crimera/piko", "^piko.*jar$", "bins", "patches.jar"
)
print("Downloading integrations")
integrationsRelease = download_release_asset(
"crimera/revanced-integrations",
"^rev.*apk$",
"bins",
"integrations.apk",
)
print(integrationsRelease["body"])
message: str = f"""
Changelogs:
[piko-{pikoRelease["tag_name"]}]({pikoRelease["html_url"]})
[integrations-{integrationsRelease["tag_name"]}]({integrationsRelease["html_url"]})
"""
build_apks(latest_version)
publish_release(
latest_version.version,
[
f"x-piko-v{latest_version.version}.apk",
f"x-piko-material-you-v{latest_version.version}.apk",
f"twitter-piko-v{latest_version.version}.apk",
f"twitter-piko-material-you-v{latest_version.version}.apk",
],
message,
latest_version.version
)
report_to_telegram()
def main():
# get latest version
url: str = "https://www.apkmirror.com/apk/x-corp/twitter/"
repo_url: str = "crimera/twitter-apk"
versions = apkmirror.get_versions(url)
latest_version = get_latest_release(versions)
if latest_version is None:
raise Exception("Could not find the latest version")
# only continue if it's a release
if latest_version.version.find("release") < 0:
panic("Latest version is not a release version")
last_build_version: github.GithubRelease | None = github.get_last_build_version(
repo_url
)
if last_build_version is None:
panic("Failed to fetch the latest build version")
return
# Begin stuff
if last_build_version.tag_name != latest_version.version:
print(f"New version found: {latest_version.version}")
else:
print("No new version found")
return
process(latest_version)
def manual(version:str):
link = f'https://www.apkmirror.com/apk/x-corp/twitter/twitter-{version.replace(".","-")}-release'
latest_version = Version(link=link,version=version)
process(latest_version)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Piko APK')
# 0 = auto; 1 = manual;
parser.add_argument('--m', action="store", dest='mode', default=0)
parser.add_argument('--v', action="store", dest='version', default=0)
args = parser.parse_args()
mode = args.mode
if not mode: # auto
main()
else: # manual
version = args.version
if not version:
raise Exception("Version is required.")
manual(version)