-
Notifications
You must be signed in to change notification settings - Fork 46
/
Build.ps1
212 lines (178 loc) · 7.06 KB
/
Build.ps1
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<#
.SYNOPSIS
Build ReVanced app using latest components:
YouTube (latest supported);
ReVanced CLI;
ReVanced Patches;
ReVanced Integrations;
ReVanced microG GmsCore;
Azul Zulu.
.NOTES
After compiling, microg.apk and compiled revanced.apk will be located in "Downloads folder\ReVanced"
.LINKS
https://github.com/revanced
#>
#Requires -Version 5.1
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
if ($Host.Version.Major -eq 5)
{
# Progress bar can significantly impact cmdlet performance
# https://github.com/PowerShell/PowerShell/issues/2138
$Script:ProgressPreference = "SilentlyContinue"
}
# Download all files to "Downloads folder\ReVanced"
$DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}"
if (-not (Test-Path -Path "$DownloadsFolder\ReVanced"))
{
New-Item -Path "$DownloadsFolder\ReVanced" -ItemType Directory -Force
}
# Get the latest supported YouTube version to patch
# https://api.revanced.app
$Parameters = @{
Uri = "https://api.revanced.app/v4/patches/list"
UseBasicParsing = $true
Verbose = $true
}
$JSON = (Invoke-Webrequest @Parameters).Content | ConvertFrom-Json
$versions = ($JSON | Where-Object -FilterScript {$_.name -eq "Video ads"})
$LatestSupported = $versions.compatiblePackages.'com.google.android.youtube' | Sort-Object -Descending -Unique | Select-Object -First 1
$LatestSupported = $LatestSupported.Replace(".", "-")
Write-Verbose -Message "Downloading the latest supported YouTube apk" -Verbose
# We need a NON-bundle version
# https://www.apkmirror.com/apk/google-inc/youtube/
$Parameters = @{
Uri = "https://www.apkmirror.com/apk/google-inc/youtube/youtube-$($LatestSupported)-release/youtube-$($LatestSupported)-android-apk-download/"
UseBasicParsing = $false # Disabled
Verbose = $true
}
$Request = Invoke-Webrequest @Parameters
$Parameters = @{
Uri = "https://www.apkmirror.com/apk/google-inc/youtube/youtube-$($LatestSupported)-release/youtube-$($LatestSupported)-2-android-apk-download/"
UseBasicParsing = $false # Disabled
Verbose = $true
}
$Request2 = Invoke-Webrequest @Parameters
@($Request, $Request2) | ForEach-Object -Process {
$RequestVariable = $_
$RequestVariable.ParsedHtml.getElementsByTagName("a") | Where-Object -FilterScript {$_.className -match "downloadButton"} | ForEach-Object -Process {
if ($_.innerText -notmatch "Download APK Bundle")
{
$DownloadKey = $_.href.Replace("about:/", "")
}
}
}
$Parameters = @{
Uri = "https://www.apkmirror.com/$DownloadKey"
UseBasicParsing = $true
Verbose = $true
}
$Request = Invoke-Webrequest @Parameters
$DownloadURL = $Request.Links.href | Where-Object -FilterScript {$_ -match "download.php"}
$Parameters = @{
Uri = "https://www.apkmirror.com/$DownloadURL"
OutFile = "$DownloadsFolder\ReVanced\youtube.apk"
UseBasicParsing = $true
Verbose = $true
}
Invoke-Webrequest @Parameters
Write-Verbose -Message "Downloading ReVanced cli" -Verbose
# https://github.com/revanced/revanced-cli
$Parameters = @{
Uri = "https://api.github.com/repos/revanced/revanced-cli/releases/latest"
UseBasicParsing = $true
Verbose = $true
}
$Tag = (Invoke-RestMethod @Parameters).tag_name
$Tag2 = $Tag.replace("v", "")
$Parameters = @{
Uri = "https://github.com/revanced/revanced-cli/releases/download/$Tag/revanced-cli-$Tag2-all.jar"
Outfile = "$DownloadsFolder\ReVanced\revanced-cli.jar"
UseBasicParsing = $true
Verbose = $true
}
Invoke-RestMethod @Parameters
Write-Verbose -Message "Downloading ReVanced patches" -Verbose
# https://github.com/revanced/revanced-patches
$Parameters = @{
Uri = "https://api.github.com/repos/revanced/revanced-patches/releases/latest"
UseBasicParsing = $true
Verbose = $true
}
$Patchesvtag = (Invoke-RestMethod @Parameters).tag_name
$Patchestag = $Patchesvtag.replace("v", "")
$Parameters = @{
Uri = "https://github.com/revanced/revanced-patches/releases/download/$Patchesvtag/patches-$Patchestag.rvp"
Outfile = "$DownloadsFolder\ReVanced\revanced-patches.rvp"
UseBasicParsing = $true
Verbose = $true
}
Invoke-RestMethod @Parameters
Write-Verbose -Message "Downloading ReVanced GmsCore" -Verbose
# https://github.com/ReVanced/GmsCore
$Parameters = @{
Uri = "https://api.github.com/repos/ReVanced/GmsCore/releases/latest"
UseBasicParsing = $true
Verbose = $true
}
# Default microg.apk
$URL_Default = (Invoke-RestMethod @Parameters).assets.browser_download_url | Where-Object -FilterScript {$_ -notmatch "hw"}
# microg.apk for Huawei, Xiaomi
$URL_Vendors = (Invoke-RestMethod @Parameters).assets.browser_download_url | Where-Object -FilterScript {$_ -match "hw"}
# Default microg.apk
$Parameters = @{
Uri = $URL_Default
Outfile = "$DownloadsFolder\ReVanced\microg.apk"
UseBasicParsing = $true
Verbose = $true
}
Invoke-RestMethod @Parameters
# microg.apk for Huawei, Xiaomi
$Parameters = @{
Uri = $URL_Vendors
Outfile = "$DownloadsFolder\ReVanced\microg_for_huawei_xiaomi.apk"
UseBasicParsing = $true
Verbose = $true
}
Invoke-RestMethod @Parameters
Remove-Item -Path "$DownloadsFolder\ReVanced\zulu-jdk-win_x64" -Recurse -Force -ErrorAction Ignore
Write-Verbose -Message "Downloading Azul Zulu" -Verbose
# https://app.swaggerhub.com/apis-docs/azul/zulu-download-community/1.0
$Parameters = @{
Uri = "https://api.azul.com/zulu/download/community/v1.0/bundles/latest/?jdk_version=21&bundle_type=jdk&javafx=false&ext=msi&os=windows&arch=x86&hw_bitness=64"
UseBasicParsing = $true
Verbose = $true
}
$URL = (Invoke-RestMethod @Parameters).url
$Parameters = @{
Uri = $URL
Outfile = "$DownloadsFolder\ReVanced\zulu-jdk-win_x64.msi"
UseBasicParsing = $true
Verbose = $true
}
Invoke-RestMethod @Parameters
# Extract zulu-jdk-win_x64.msi to zulu-jdk-win_x64 folder
$Arguments = @(
"/a `"$DownloadsFolder\ReVanced\zulu-jdk-win_x64.msi`"",
"TARGETDIR=`"$DownloadsFolder\ReVanced\zulu-jdk-win_x64`""
"/qb"
)
Start-Process "msiexec" -ArgumentList $Arguments -Wait
Remove-Item -Path "$DownloadsFolder\ReVanced\zulu-jdk-win_x64.msi" -Force
# https://revanced.app/patches?pkg=com.google.android.youtube
# https://github.com/ReVanced/revanced-cli/tree/main/docs
& "$DownloadsFolder\ReVanced\zulu-jdk-win_x64\Program Files\Zulu\zulu*\bin\java.exe" `
-jar "$DownloadsFolder\ReVanced\revanced-cli.jar" `
patch "$DownloadsFolder\ReVanced\youtube.apk" `
--patches "$DownloadsFolder\ReVanced\revanced-patches.rvp" `
--purge `
--out "$DownloadsFolder\ReVanced\revanced.apk"
Invoke-Item -Path "$DownloadsFolder\ReVanced"
$Files = @(
"$DownloadsFolder\ReVanced\revanced-temporary-files",
"$DownloadsFolder\ReVanced\zulu-jdk-win_x64",
"$DownloadsFolder\ReVanced\revanced.keystore",
"$DownloadsFolder\ReVanced\revanced-cli.jar",
"$DownloadsFolder\ReVanced\revanced-patches.rvp",
"$DownloadsFolder\ReVanced\youtube.apk"
)
Remove-Item -Path $Files -Recurse -Force