forked from SpotX-Official/SpotX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.ps1
1841 lines (1537 loc) · 62.5 KB
/
run.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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
param
(
[Parameter(HelpMessage = "Change recommended version of Spotify.")]
[Alias("v")]
[string]$version,
[Parameter(HelpMessage = "Use github.io mirror instead of raw.githubusercontent.")]
[Alias("m")]
[switch]$mirror,
[Parameter(HelpMessage = "Developer mode activation.")]
[Alias("dev")]
[switch]$devtools,
[Parameter(HelpMessage = 'Hiding podcasts/episodes/audiobooks from homepage.')]
[switch]$podcasts_off,
[Parameter(HelpMessage = 'Hiding Ad-like sections from the homepage')]
[switch]$adsections_off,
[Parameter(HelpMessage = 'Do not hiding podcasts/episodes/audiobooks from homepage.')]
[switch]$podcasts_on,
[Parameter(HelpMessage = 'Block Spotify automatic updates.')]
[switch]$block_update_on,
[Parameter(HelpMessage = 'Do not block Spotify automatic updates.')]
[switch]$block_update_off,
[Parameter(HelpMessage = 'Change limit for clearing audio cache.')]
[Alias('cl')]
[int]$cache_limit,
[Parameter(HelpMessage = 'Automatic uninstallation of Spotify MS if it was found.')]
[switch]$confirm_uninstall_ms_spoti,
[Parameter(HelpMessage = 'Overwrite outdated or unsupported version of Spotify with the recommended version.')]
[Alias('sp-over')]
[switch]$confirm_spoti_recomended_over,
[Parameter(HelpMessage = 'Uninstall outdated or unsupported version of Spotify and install the recommended version.')]
[Alias('sp-uninstall')]
[switch]$confirm_spoti_recomended_uninstall,
[Parameter(HelpMessage = 'Installation without ad blocking for premium accounts.')]
[switch]$premium,
[Parameter(HelpMessage = 'Automatic launch of Spotify after installation is complete.')]
[switch]$start_spoti,
[Parameter(HelpMessage = 'Experimental features operated by Spotify.')]
[switch]$exp_spotify,
[Parameter(HelpMessage = 'Enable top search bar.')]
[switch]$topsearchbar,
[Parameter(HelpMessage = 'disable subfeed filter chips on home.')]
[switch]$homesub_off,
[Parameter(HelpMessage = 'Do not hide the icon of collaborations in playlists.')]
[switch]$hide_col_icon_off,
[Parameter(HelpMessage = 'Disable new right sidebar.')]
[switch]$rightsidebar_off,
[Parameter(HelpMessage = 'it`s killing the heart icon, you`re able to save and choose the destination for any song, playlist, or podcast')]
[switch]$plus,
[Parameter(HelpMessage = 'Enabled the big cards for home page')]
[switch]$canvasHome,
[Parameter(HelpMessage = 'Enable funny progress bar.')]
[switch]$funnyprogressBar,
[Parameter(HelpMessage = 'New theme activated (new right and left sidebar, some cover change)')]
[switch]$new_theme,
[Parameter(HelpMessage = 'Enable right sidebar coloring to match cover color)')]
[switch]$rightsidebarcolor,
[Parameter(HelpMessage = 'Returns old lyrics')]
[switch]$old_lyrics,
[Parameter(HelpMessage = 'Disable native lyrics')]
[switch]$lyrics_block,
[Parameter(HelpMessage = 'Do not create desktop shortcut.')]
[switch]$no_shortcut,
[Parameter(HelpMessage = 'Static color for lyrics.')]
[ArgumentCompleter({ param($cmd, $param, $wordToComplete)
[array] $validValues = @('default', 'red', 'orange', 'yellow', 'spotify', 'blue', 'purple', 'strawberry', 'pumpkin', 'sandbar', 'radium', 'oceano', 'royal', 'github', 'discord', 'drot', 'forest', 'fresh', 'zing', 'pinkle', 'krux', 'blueberry', 'postlight', 'relish', 'turquoise')
$validValues -like "*$wordToComplete*"
})]
[string]$lyrics_stat,
[Parameter(HelpMessage = 'Accumulation of track listening history with Goofy.')]
[string]$urlform_goofy = $null,
[Parameter(HelpMessage = 'Accumulation of track listening history with Goofy.')]
[string]$idbox_goofy = $null,
[Parameter(HelpMessage = 'Error log ru string.')]
[switch]$err_ru,
[Parameter(HelpMessage = 'Select the desired language to use for installation. Default is the detected system language.')]
[Alias('l')]
[string]$language
)
# Ignore errors from `Stop-Process`
$PSDefaultParameterValues['Stop-Process:ErrorAction'] = [System.Management.Automation.ActionPreference]::SilentlyContinue
function Format-LanguageCode {
# Normalizes and confirms support of the selected language.
[CmdletBinding()]
[OutputType([string])]
param
(
[string]$LanguageCode
)
$supportLanguages = @(
'en', 'ru', 'it', 'tr', 'ka', 'pl', 'es', 'fr', 'hi', 'pt', 'id', 'vi', 'ro', 'de', 'hu', 'zh', 'zh-TW', 'ko', 'ua', 'fa', 'sr', 'lv', 'bn', 'el', 'fi', 'ja', 'fil', 'sv', 'sk', 'ta', 'cs'
)
# Trim the language code down to two letter code.
switch -Regex ($LanguageCode) {
'^en' {
$returnCode = 'en'
break
}
'^(ru|py)' {
$returnCode = 'ru'
break
}
'^it' {
$returnCode = 'it'
break
}
'^tr' {
$returnCode = 'tr'
break
}
'^ka' {
$returnCode = 'ka'
break
}
'^pl' {
$returnCode = 'pl'
break
}
'^es' {
$returnCode = 'es'
break
}
'^fr' {
$returnCode = 'fr'
break
}
'^hi' {
$returnCode = 'hi'
break
}
'^pt' {
$returnCode = 'pt'
break
}
'^id' {
$returnCode = 'id'
break
}
'^vi' {
$returnCode = 'vi'
break
}
'^ro' {
$returnCode = 'ro'
break
}
'^de' {
$returnCode = 'de'
break
}
'^hu' {
$returnCode = 'hu'
break
}
'^(zh|zh-CN)$' {
$returnCode = 'zh'
break
}
'^zh-TW' {
$returnCode = 'zh-TW'
break
}
'^ko' {
$returnCode = 'ko'
break
}
'^ua' {
$returnCode = 'ua'
break
}
'^fa' {
$returnCode = 'fa'
break
}
'^sr' {
$returnCode = 'sr'
break
}
'^lv' {
$returnCode = 'lv'
break
}
'^bn' {
$returnCode = 'bn'
break
}
'^el' {
$returnCode = 'el'
break
}
'^fi$' {
$returnCode = 'fi'
break
}
'^ja' {
$returnCode = 'ja'
break
}
'^fil' {
$returnCode = 'fil'
break
}
'^sv' {
$returnCode = 'sv'
break
}
'^sk' {
$returnCode = 'sk'
break
}
'^ta' {
$returnCode = 'ta'
break
}
'^cs' {
$returnCode = 'cs'
break
}
Default {
$returnCode = $PSUICulture
$long_code = $true
break
}
}
# Checking the long language code
if ($long_code -and $returnCode -NotIn $supportLanguages) {
$returnCode = $returnCode -split "-" | Select-Object -First 1
}
# Checking the short language code
if ($returnCode -NotIn $supportLanguages) {
# If the language code is not supported default to English.
$returnCode = 'en'
}
return $returnCode
}
$spotifyDirectory = Join-Path $env:APPDATA 'Spotify'
$spotifyDirectory2 = Join-Path $env:LOCALAPPDATA 'Spotify'
$spotifyExecutable = Join-Path $spotifyDirectory 'Spotify.exe'
$exe_bak = Join-Path $spotifyDirectory 'Spotify.bak'
$spotifyUninstall = Join-Path ([System.IO.Path]::GetTempPath()) 'SpotifyUninstall.exe'
$start_menu = Join-Path $env:APPDATA 'Microsoft\Windows\Start Menu\Programs\Spotify.lnk'
$upgrade_client = $false
# Check version Powershell
$psv = $PSVersionTable.PSVersion.major
if ($psv -ge 7) {
Import-Module Appx -UseWindowsPowerShell -WarningAction:SilentlyContinue
}
# add Tls12
[Net.ServicePointManager]::SecurityProtocol = 3072
function CallLang($clg) {
$urlLang = switch ($mirror) {
$true { "https://spotx-official.github.io/SpotX/scripts/installer-lang/$clg.ps1" }
default { "https://raw.githubusercontent.com/SpotX-Official/SpotX/main/scripts/installer-lang/$clg.ps1" }
}
$ProgressPreference = 'SilentlyContinue'
try {
$response = (iwr -Uri $urlLang -UseBasicParsing).Content
if ($mirror) { $response = [System.Text.Encoding]::UTF8.GetString($response) }
Invoke-Expression $response
}
catch {
Write-Host "Error loading $clg language"
Pause
Exit
}
}
# Set language code for script.
$langCode = Format-LanguageCode -LanguageCode $Language
$lang = CallLang -clg $langCode
Write-Host ($lang).Welcome
Write-Host
# Check version Windows
$os = Get-CimInstance -ClassName "Win32_OperatingSystem" -ErrorAction SilentlyContinue
if ($os) {
$osCaption = $os.Caption
}
else {
$osCaption = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" -Name ProductName).ProductName
}
$pattern = "\bWindows (7|8(\.1)?|10|11|12)\b"
$reg = [regex]::Matches($osCaption, $pattern)
$win_os = $reg.Value
$win12 = $win_os -match "\windows 12\b"
$win11 = $win_os -match "\windows 11\b"
$win10 = $win_os -match "\windows 10\b"
$win8_1 = $win_os -match "\windows 8.1\b"
$win8 = $win_os -match "\windows 8\b"
$win7 = $win_os -match "\windows 7\b"
$match_v = "^\d+\.\d+\.\d+\.\d+\.g[0-9a-f]{8}-\d+$"
if ($version) {
if ($version -match $match_v) {
$onlineFull = $version
}
else {
Write-Warning "Invalid $($version) format. Example: 1.2.13.661.ga588f749-4064"
Write-Host
}
}
$old_os = $win7 -or $win8 -or $win8_1
# Recommended version for Win 7-8.1
$last_win7_full = "1.2.5.1006.g22820f93-1078"
if (!($version -and $version -match $match_v)) {
if ($old_os) {
$onlineFull = $last_win7_full
}
else {
# Recommended version for Win 10-12
$onlineFull = "1.2.44.405.g81fd6352-5851"
}
}
else {
if ($old_os) {
$last_win7 = "1.2.5.1006"
if ([version]($onlineFull -split ".g")[0] -gt [version]$last_win7) {
Write-Warning ("Version {0} is only supported on Windows 10 and above" -f ($onlineFull -split ".g")[0])
Write-Warning ("The recommended version has been automatically changed to {0}, the latest supported version for Windows 7-8.1" -f $last_win7)
Write-Host
$onlineFull = $last_win7_full
}
}
}
$online = ($onlineFull -split ".g")[0]
function Get {
param (
[string]$Url,
[int]$MaxRetries = 3,
[int]$RetrySeconds = 3
)
$retries = 0
while ($retries -lt $MaxRetries) {
try {
return Invoke-RestMethod -Uri $Url
}
catch {
Write-Warning "Request failed: $_"
$retries++
Start-Sleep -Seconds $RetrySeconds
}
}
Write-Host
Write-Host "ERROR: " -ForegroundColor Red -NoNewline; Write-Host "Failed to retrieve data from $Url" -ForegroundColor White
Write-Host
return $null
}
function incorrectValue {
Write-Host ($lang).Incorrect"" -ForegroundColor Red -NoNewline
Write-Host ($lang).Incorrect2"" -NoNewline
Start-Sleep -Milliseconds 1000
Write-Host "3" -NoNewline
Start-Sleep -Milliseconds 1000
Write-Host " 2" -NoNewline
Start-Sleep -Milliseconds 1000
Write-Host " 1"
Start-Sleep -Milliseconds 1000
Clear-Host
}
function Unlock-Folder {
$blockFileUpdate = Join-Path $env:LOCALAPPDATA 'Spotify\Update'
if (Test-Path $blockFileUpdate -PathType Container) {
$folderUpdateAccess = Get-Acl $blockFileUpdate
$hasDenyAccessRule = $false
foreach ($accessRule in $folderUpdateAccess.Access) {
if ($accessRule.AccessControlType -eq 'Deny') {
$hasDenyAccessRule = $true
$folderUpdateAccess.RemoveAccessRule($accessRule)
}
}
if ($hasDenyAccessRule) {
Set-Acl $blockFileUpdate $folderUpdateAccess
}
}
}
function Mod-F {
param(
[string] $template,
[object[]] $arguments
)
$result = $template
for ($i = 0; $i -lt $arguments.Length; $i++) {
$placeholder = "{${i}}"
$value = $arguments[$i]
$result = $result -replace [regex]::Escape($placeholder), $value
}
return $result
}
function downloadSp() {
$webClient = New-Object -TypeName System.Net.WebClient
Import-Module BitsTransfer
$web_Url = "https://download.scdn.co/upgrade/client/win32-x86/spotify_installer-$onlineFull.exe"
$local_Url = "$PWD\SpotifySetup.exe"
$web_name_file = "SpotifySetup.exe"
try { if (curl.exe -V) { $curl_check = $true } }
catch { $curl_check = $false }
try {
if ($curl_check) {
$stcode = curl.exe -Is -w "%{http_code} \n" -o /dev/null $web_Url --retry 2 --ssl-no-revoke
if ($stcode.trim() -ne "200") {
Write-Host "Curl error code: $stcode"; throw
}
curl.exe -q $web_Url -o $local_Url --progress-bar --retry 3 --ssl-no-revoke
return
}
if (!($curl_check ) -and $null -ne (Get-Module -Name BitsTransfer -ListAvailable)) {
$ProgressPreference = 'Continue'
Start-BitsTransfer -Source $web_Url -Destination $local_Url -DisplayName ($lang).Download5 -Description "$online "
return
}
if (!($curl_check ) -and $null -eq (Get-Module -Name BitsTransfer -ListAvailable)) {
$webClient.DownloadFile($web_Url, $local_Url)
return
}
}
catch {
Write-Host
Write-Host ($lang).Download $web_name_file -ForegroundColor RED
$Error[0].Exception
Write-Host
Write-Host ($lang).Download2`n
Start-Sleep -Milliseconds 5000
try {
if ($curl_check) {
$stcode = curl.exe -Is -w "%{http_code} \n" -o /dev/null $web_Url --retry 2 --ssl-no-revoke
if ($stcode.trim() -ne "200") {
Write-Host "Curl error code: $stcode"; throw
}
curl.exe -q $web_Url -o $local_Url --progress-bar --retry 3 --ssl-no-revoke
return
}
if (!($curl_check ) -and $null -ne (Get-Module -Name BitsTransfer -ListAvailable) -and !($curl_check )) {
Start-BitsTransfer -Source $web_Url -Destination $local_Url -DisplayName ($lang).Download5 -Description "$online "
return
}
if (!($curl_check ) -and $null -eq (Get-Module -Name BitsTransfer -ListAvailable) -and !($curl_check )) {
$webClient.DownloadFile($web_Url, $local_Url)
return
}
}
catch {
Write-Host ($lang).Download3 -ForegroundColor RED
$Error[0].Exception
Write-Host
Write-Host ($lang).Download4`n
($lang).StopScript
$tempDirectory = $PWD
Pop-Location
Start-Sleep -Milliseconds 200
Remove-Item -Recurse -LiteralPath $tempDirectory
Pause
Exit
}
}
}
function DesktopFolder {
# If the default Dekstop folder does not exist, then try to find it through the registry.
$ErrorActionPreference = 'SilentlyContinue'
if (Test-Path "$env:USERPROFILE\Desktop") {
$desktop_folder = "$env:USERPROFILE\Desktop"
}
$regedit_desktop_folder = Get-ItemProperty -Path "Registry::HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\"
$regedit_desktop = $regedit_desktop_folder.'{754AC886-DF64-4CBA-86B5-F7FBF4FBCEF5}'
if (!(Test-Path "$env:USERPROFILE\Desktop")) {
$desktop_folder = $regedit_desktop
}
return $desktop_folder
}
function Kill-Spotify {
param (
[int]$maxAttempts = 5
)
for ($attempt = 1; $attempt -le $maxAttempts; $attempt++) {
$allProcesses = Get-Process -ErrorAction SilentlyContinue
$spotifyProcesses = $allProcesses | Where-Object { $_.ProcessName -like "*spotify*" }
if ($spotifyProcesses) {
foreach ($process in $spotifyProcesses) {
try {
Stop-Process -Id $process.Id -Force
}
catch {
# Ignore NoSuchProcess exception
}
}
Start-Sleep -Seconds 1
}
else {
break
}
}
if ($attempt -gt $maxAttempts) {
Write-Host "The maximum number of attempts to terminate a process has been reached."
}
}
Kill-Spotify
# Remove Spotify Windows Store If Any
if ($win10 -or $win11 -or $win8_1 -or $win8 -or $win12) {
if (Get-AppxPackage -Name SpotifyAB.SpotifyMusic) {
Write-Host ($lang).MsSpoti`n
if (!($confirm_uninstall_ms_spoti)) {
do {
$ch = Read-Host -Prompt ($lang).MsSpoti2
Write-Host
if (!($ch -eq 'n' -or $ch -eq 'y')) {
incorrectValue
}
}
while ($ch -notmatch '^y$|^n$')
}
if ($confirm_uninstall_ms_spoti) { $ch = 'y' }
if ($ch -eq 'y') {
$ProgressPreference = 'SilentlyContinue' # Hiding Progress Bars
if ($confirm_uninstall_ms_spoti) { Write-Host ($lang).MsSpoti3`n }
if (!($confirm_uninstall_ms_spoti)) { Write-Host ($lang).MsSpoti4`n }
Get-AppxPackage -Name SpotifyAB.SpotifyMusic | Remove-AppxPackage
}
if ($ch -eq 'n') {
Read-Host ($lang).StopScript
Pause
Exit
}
}
}
# Attempt to fix the hosts file
$hostsFilePath = Join-Path $Env:windir 'System32\Drivers\Etc\hosts'
$hostsBackupFilePath = Join-Path $Env:windir 'System32\Drivers\Etc\hosts.bak'
if (Test-Path -Path $hostsFilePath) {
$hosts = [System.IO.File]::ReadAllLines($hostsFilePath)
$regex = "^(?!#|\|)((?:.*?(?:download|upgrade)\.scdn\.co|.*?spotify).*)"
if ($hosts -match $regex) {
Write-Host ($lang).HostInfo`n
Write-Host ($lang).HostBak`n
Copy-Item -Path $hostsFilePath -Destination $hostsBackupFilePath -ErrorAction SilentlyContinue
if ($?) {
Write-Host ($lang).HostDel
try {
$hosts = $hosts | Where-Object { $_ -notmatch $regex }
[System.IO.File]::WriteAllLines($hostsFilePath, $hosts)
}
catch {
Write-Host ($lang).HostError`n -ForegroundColor Red
$copyError = $Error[0]
Write-Host "Error: $($copyError.Exception.Message)`n" -ForegroundColor Red
}
}
else {
Write-Host ($lang).HostError`n -ForegroundColor Red
$copyError = $Error[0]
Write-Host "Error: $($copyError.Exception.Message)`n" -ForegroundColor Red
}
}
}
# Unique directory name based on time
Push-Location -LiteralPath ([System.IO.Path]::GetTempPath())
New-Item -Type Directory -Name "SpotX_Temp-$(Get-Date -UFormat '%Y-%m-%d_%H-%M-%S')" | Convert-Path | Set-Location
if ($premium) {
Write-Host ($lang).Prem`n
}
$spotifyInstalled = (Test-Path -LiteralPath $spotifyExecutable)
if ($spotifyInstalled) {
# Check version Spotify offline
$offline = (Get-Item $spotifyExecutable).VersionInfo.FileVersion
# Version comparison
# converting strings to arrays of numbers using the -split operator and a foreach loop
$arr1 = $online -split '\.' | foreach { [int]$_ }
$arr2 = $offline -split '\.' | foreach { [int]$_ }
# compare each element of the array in order from most significant to least significant.
for ($i = 0; $i -lt $arr1.Length; $i++) {
if ($arr1[$i] -gt $arr2[$i]) {
$oldversion = $true
break
}
elseif ($arr1[$i] -lt $arr2[$i]) {
$testversion = $true
break
}
}
# Old version Spotify
if ($oldversion) {
if ($confirm_spoti_recomended_over -or $confirm_spoti_recomended_uninstall) {
Write-Host ($lang).OldV`n
}
if (!($confirm_spoti_recomended_over) -and !($confirm_spoti_recomended_uninstall)) {
do {
Write-Host (($lang).OldV2 -f $offline, $online)
$ch = Read-Host -Prompt ($lang).OldV3
Write-Host
if (!($ch -eq 'n' -or $ch -eq 'y')) {
incorrectValue
}
}
while ($ch -notmatch '^y$|^n$')
}
if ($confirm_spoti_recomended_over -or $confirm_spoti_recomended_uninstall) {
$ch = 'y'
Write-Host ($lang).AutoUpd`n
}
if ($ch -eq 'y') {
$upgrade_client = $true
if (!($confirm_spoti_recomended_over) -and !($confirm_spoti_recomended_uninstall)) {
do {
$ch = Read-Host -Prompt (($lang).DelOrOver -f $offline)
Write-Host
if (!($ch -eq 'n' -or $ch -eq 'y')) {
incorrectValue
}
}
while ($ch -notmatch '^y$|^n$')
}
if ($confirm_spoti_recomended_uninstall) { $ch = 'y' }
if ($confirm_spoti_recomended_over) { $ch = 'n' }
if ($ch -eq 'y') {
Write-Host ($lang).DelOld`n
$null = Unlock-Folder
cmd /c $spotifyExecutable /UNINSTALL /SILENT
wait-process -name SpotifyUninstall
Start-Sleep -Milliseconds 200
if (Test-Path $spotifyDirectory) { Remove-Item -Recurse -Force -LiteralPath $spotifyDirectory }
if (Test-Path $spotifyDirectory2) { Remove-Item -Recurse -Force -LiteralPath $spotifyDirectory2 }
if (Test-Path $spotifyUninstall ) { Remove-Item -Recurse -Force -LiteralPath $spotifyUninstall }
}
if ($ch -eq 'n') { $ch = $null }
}
if ($ch -eq 'n') {
$downgrading = $true
}
}
# Unsupported version Spotify
if ($testversion) {
# Submit unsupported version of Spotify to google form for further processing
try {
# Country check
$country = [System.Globalization.RegionInfo]::CurrentRegion.EnglishName
$txt = [IO.File]::ReadAllText($spotifyExecutable)
$regex = "(\d+)\.(\d+)\.(\d+)\.(\d+)(\.g[0-9a-f]{8})"
$v = $txt | Select-String $regex -AllMatches
$ver = $v.Matches.Value[0]
if ($ver.Count -gt 1) { $ver = $ver[0] }
$Parameters = @{
Uri = 'https://docs.google.com/forms/d/e/1FAIpQLSegGsAgilgQ8Y36uw-N7zFF6Lh40cXNfyl1ecHPpZcpD8kdHg/formResponse'
Method = 'POST'
Body = @{
'entry.620327948' = $ver
'entry.1951747592' = $country
'entry.1402903593' = $win_os
'entry.860691305' = $psv
'entry.2067427976' = $online + " < " + $offline
}
}
$null = Invoke-WebRequest -useb @Parameters
}
catch {
Write-Host 'Unable to submit new version of Spotify'
Write-Host "error description: "$Error[0]
}
if ($confirm_spoti_recomended_over -or $confirm_spoti_recomended_uninstall) {
Write-Host ($lang).NewV`n
}
if (!($confirm_spoti_recomended_over) -and !($confirm_spoti_recomended_uninstall)) {
do {
Write-Host (($lang).NewV2 -f $offline, $online)
$ch = Read-Host -Prompt (($lang).NewV3 -f $offline)
Write-Host
if (!($ch -eq 'n' -or $ch -eq 'y')) {
incorrectValue
}
}
while ($ch -notmatch '^y$|^n$')
}
if ($confirm_spoti_recomended_over -or $confirm_spoti_recomended_uninstall) { $ch = 'n' }
if ($ch -eq 'y') { $upgrade_client = $false }
if ($ch -eq 'n') {
if (!($confirm_spoti_recomended_over) -and !($confirm_spoti_recomended_uninstall)) {
do {
$ch = Read-Host -Prompt (($lang).Recom -f $online)
Write-Host
if (!($ch -eq 'n' -or $ch -eq 'y')) {
incorrectValue
}
}
while ($ch -notmatch '^y$|^n$')
}
if ($confirm_spoti_recomended_over -or $confirm_spoti_recomended_uninstall) {
$ch = 'y'
Write-Host ($lang).AutoUpd`n
}
if ($ch -eq 'y') {
$upgrade_client = $true
$downgrading = $true
if (!($confirm_spoti_recomended_over) -and !($confirm_spoti_recomended_uninstall)) {
do {
$ch = Read-Host -Prompt (($lang).DelOrOver -f $offline)
Write-Host
if (!($ch -eq 'n' -or $ch -eq 'y')) {
incorrectValue
}
}
while ($ch -notmatch '^y$|^n$')
}
if ($confirm_spoti_recomended_uninstall) { $ch = 'y' }
if ($confirm_spoti_recomended_over) { $ch = 'n' }
if ($ch -eq 'y') {
Write-Host ($lang).DelNew`n
$null = Unlock-Folder
cmd /c $spotifyExecutable /UNINSTALL /SILENT
wait-process -name SpotifyUninstall
Start-Sleep -Milliseconds 200
if (Test-Path $spotifyDirectory) { Remove-Item -Recurse -Force -LiteralPath $spotifyDirectory }
if (Test-Path $spotifyDirectory2) { Remove-Item -Recurse -Force -LiteralPath $spotifyDirectory2 }
if (Test-Path $spotifyUninstall ) { Remove-Item -Recurse -Force -LiteralPath $spotifyUninstall }
}
if ($ch -eq 'n') { $ch = $null }
}
if ($ch -eq 'n') {
Write-Host ($lang).StopScript
$tempDirectory = $PWD
Pop-Location
Start-Sleep -Milliseconds 200
Remove-Item -Recurse -LiteralPath $tempDirectory
Pause
Exit
}
}
}
}
# If there is no client or it is outdated, then install
if (-not $spotifyInstalled -or $upgrade_client) {
Write-Host ($lang).DownSpoti"" -NoNewline
Write-Host $online -ForegroundColor Green
Write-Host ($lang).DownSpoti2`n
# Delete old version files of Spotify before installing, leave only profile files
$ErrorActionPreference = 'SilentlyContinue'
Kill-Spotify
Start-Sleep -Milliseconds 600
$null = Unlock-Folder
Start-Sleep -Milliseconds 200
Get-ChildItem $spotifyDirectory -Exclude 'Users', 'prefs' | Remove-Item -Recurse -Force
Start-Sleep -Milliseconds 200
# Client download
downloadSp
Write-Host
Start-Sleep -Milliseconds 200
# Client installation
Start-Process -FilePath explorer.exe -ArgumentList $PWD\SpotifySetup.exe
while (-not (get-process | Where-Object { $_.ProcessName -eq 'SpotifySetup' })) {}
wait-process -name SpotifySetup
Kill-Spotify
# Upgrade check version Spotify offline
$offline = (Get-Item $spotifyExecutable).VersionInfo.FileVersion
# Upgrade check version Spotify.bak
$offline_bak = (Get-Item $exe_bak).VersionInfo.FileVersion
}
# Delete Spotify shortcut if it is on desktop
if ($no_shortcut) {
$ErrorActionPreference = 'SilentlyContinue'
$desktop_folder = DesktopFolder
Start-Sleep -Milliseconds 1000
remove-item "$desktop_folder\Spotify.lnk" -Recurse -Force
}
$ch = $null
# updated Russian translation
if ($langCode -eq 'ru' -and [version]$offline -ge [version]"1.1.92.644") {
$urlru = switch ($mirror) {
$true { "https://spotx-official.github.io/SpotX/patches/Augmented%20translation/ru.json" }
default { "https://raw.githubusercontent.com/SpotX-Official/SpotX/main/patches/Augmented%20translation/ru.json" }
}
$webjsonru = Get -Url $urlru
if ($webjsonru -ne $null) {
$ru = $true
}
}
if ($podcasts_off) {
Write-Host ($lang).PodcatsOff`n
$ch = 'y'
}
if ($podcasts_on) {
Write-Host ($lang).PodcastsOn`n
$ch = 'n'
}
if (!($podcasts_off) -and !($podcasts_on)) {
do {
$ch = Read-Host -Prompt ($lang).PodcatsSelect
Write-Host
if (!($ch -eq 'n' -or $ch -eq 'y')) { incorrectValue }
}
while ($ch -notmatch '^y$|^n$')
}
if ($ch -eq 'y') { $podcast_off = $true }
$ch = $null
if ($downgrading) { $upd = "`n" + [string]($lang).DowngradeNote }
else { $upd = "" }
if ($block_update_on) {
Write-Host ($lang).UpdBlock`n
$ch = 'y'
}
if ($block_update_off) {
Write-Host ($lang).UpdUnblock`n
$ch = 'n'
}
if (!($block_update_on) -and !($block_update_off)) {
do {
$text_upd = [string]($lang).UpdSelect + $upd
$ch = Read-Host -Prompt $text_upd
Write-Host
if (!($ch -eq 'n' -or $ch -eq 'y')) { incorrectValue }
}
while ($ch -notmatch '^y$|^n$')
}
if ($ch -eq 'y') { $not_block_update = $false }
if (!($new_theme) -and [version]$offline -ge [version]"1.2.14.1141") {
Write-Warning "This version does not support the old theme, use version 1.2.13.661 or below"
Write-Host
}
if ($ch -eq 'n') {
$not_block_update = $true
$ErrorActionPreference = 'SilentlyContinue'
if ((Test-Path -LiteralPath $exe_bak) -and $offline -eq $offline_bak) {
Remove-Item $spotifyExecutable -Recurse -Force
Rename-Item $exe_bak $spotifyExecutable
}
}
$ch = $null
$url = switch ($mirror) {
$true { "https://spotx-official.github.io/SpotX/patches/patches.json" }
default { "https://raw.githubusercontent.com/SpotX-Official/SpotX/main/patches/patches.json" }
}
$webjson = Get -Url $url -RetrySeconds 5
if ($webjson -eq $null) {
Write-Host
Write-Host "Failed to get patches.json" -ForegroundColor Red
Write-Host ($lang).StopScript
$tempDirectory = $PWD
Pop-Location
Start-Sleep -Milliseconds 200
Remove-Item -Recurse -LiteralPath $tempDirectory
Pause
Exit
}
function Helper($paramname) {
function Remove-Json {
param (
[Parameter(Mandatory = $true)]
[Alias("j")]
[PSObject]$Json,
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
[Alias("p")]