forked from oword/gamesense-workshop-luas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpotify Player.lua
2403 lines (2138 loc) · 97 KB
/
Spotify Player.lua
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
local surface = require "gamesense/surface" or error('gamesense/surface library is required')
local http = require "gamesense/http" or error('gamesense/http library is required')
local images = require "gamesense/images" or error('gamesense/images library is required')
local inspect = require "gamesense/inspect"
local ffi = require "ffi"
local database_read = database.read
local database_write = database.write
local package_searchpath = package.searchpath
local ui_set_callback = ui.set_callback
local ui_set_visible = ui.set_visible
local ui_get = ui.get
local ui_set = ui.set
local ui_new_label = ui.new_label
local ui_new_button = ui.new_button
local ui_new_checkbox = ui.new_checkbox
local ui_new_combobox = ui.new_combobox
local ui_new_slider = ui.new_slider
local ui_new_color_picker = ui.new_color_picker
local ui_new_hotkey = ui.new_hotkey
local ui_new_multiselect = ui.new_multiselect
local ui_menu_position = ui.menu_position
local entity_get_local_player = entity.get_local_player
local entity_get_prop = entity.get_prop
local last_update = client.unix_time()
local last_update_controls = client.unix_time()
local last_update_error = client.unix_time()
local last_update_volume = globals.tickcount()
local last_update_volume_press = globals.tickcount()
local last_update_volume_set = globals.tickcount()
local last_update_server = client.unix_time()
local last_tick = globals.tickcount()
local sx, sy = client.screen_size()
MenuScaleX = 4.8
MenuScaleY = 10.8
ScaleTitle = 41.54
ScaleArtist = 63.53
ScaleDuration = 57
local TitleFont = surface.create_font("GothamBookItalic", sy/ScaleTitle, 900, 0x010)
local ArtistFont = surface.create_font("GothamBookItalic", sy/ScaleArtist, 600, 0x010)
local TitleFontHUD = surface.create_font("GothamBookItalic", 25, 900, 0x010)
local ArtistFontHUD = surface.create_font("GothamBookItalic", 20, 600, 0x010)
local DurationFont = surface.create_font("GothamBookItalic", sy/ScaleDuration, 600, 0x010)
local DurationFontHUD = surface.create_font("GothamBookItalic", 12, 900, 0x010)
local MainElementFontHUD = surface.create_font("GothamBookItalic", 18, 600, 0x010)
local PlayListFontHUD = surface.create_font("GothamBookItalic", 18, 500, 0x010)
local SubtabTitleHUD = surface.create_font("GothamBookItalic", 30, 500, 0x010)
local SubtabRowFontHUD = surface.create_font("GothamBookItalic", 23, 500, 0x010)
local SubtabRowFontHUD2 = surface.create_font("GothamBookItalic", 17, 500, 0x010)
local SubtabTrackFontHUD2 = surface.create_font("GothamBookItalic", 19, 800, 0x010)
local SubtabArtistFontHUD2 = surface.create_font("GothamBookItalic", 12, 500, 0x010)
local SubtabRowFontHUD3 = surface.create_font("GothamBookItalic", 24, 500, 0x010)
local VolumeFont = surface.create_font("GothamBookItalic", sy/ScaleTitle, 900, 0x010)
local MainCheckbox = ui.new_checkbox("MISC", "Miscellaneous", "Spotify")
local MenukeyReference = ui.reference("MISC", "Settings", "Menu key")
local SpotifyIndicX = database_read("previous_posX") or 0
local SpotifyIndicY = database_read("previous_posY") or 1020
local SizePerc = database_read("previous_size") or 30
local apikey = database_read("StoredKey") or nil
local refreshkey = database_read("StoredKey2") or nil
ffi.cdef[[
typedef bool (__thiscall *IsButtonDown_t)(void*, int);
typedef int (__thiscall *GetAnalogValue_t)(void*, int);
typedef int (__thiscall *GetAnalogDelta_t)(void*, int);
typedef void***(__thiscall* FindHudElement_t)(void*, const char*);
typedef void(__cdecl* ChatPrintf_t)(void*, int, int, const char*, ...);
]]
local native_GetClipboardTextCount = vtable_bind("vgui2.dll", "VGUI_System010", 7, "int(__thiscall*)(void*)")
local native_GetClipboardText = vtable_bind("vgui2.dll", "VGUI_System010", 11, "int(__thiscall*)(void*, int, const char*, int)")
local new_char_arr = ffi.typeof("char[?]")
local interface_ptr = ffi.typeof('void***')
local raw_inputsystem = client.create_interface('inputsystem.dll', 'InputSystemVersion001')
local inputsystem = ffi.cast(interface_ptr, raw_inputsystem)
local input_vmt = inputsystem[0]
local raw_IsButtonDown = input_vmt[15]
local raw_GetAnalogValue = input_vmt[18]
local raw_GetAnalogDelta = input_vmt[19]
local IsButtonDown = ffi.cast('IsButtonDown_t', raw_IsButtonDown)
local GetAnalogValue = ffi.cast('GetAnalogValue_t', raw_GetAnalogValue)
local GetAnalogDelta = ffi.cast('GetAnalogDelta_t', raw_GetAnalogDelta)
local signature_gHud = "\xB9\xCC\xCC\xCC\xCC\x88\x46\x09"
local signature_FindElement = "\x55\x8B\xEC\x53\x8B\x5D\x08\x56\x57\x8B\xF9\x33\xF6\x39\x77\x28"
local match = client.find_signature("client_panorama.dll", signature_gHud) or error("sig1 not found")
local hud = ffi.cast("void**", ffi.cast("char*", match) + 1)[0] or error("hud is nil")
match = client.find_signature("client_panorama.dll", signature_FindElement) or error("FindHudElement not found")
local find_hud_element = ffi.cast("FindHudElement_t", match)
local hudchat = find_hud_element(hud, "CHudChat") or error("CHudChat not found")
local chudchat_vtbl = hudchat[0] or error("CHudChat instance vtable is nil")
local print_to_chat = ffi.cast("ChatPrintf_t", chudchat_vtbl[27])
local function print_chat(text)
print_to_chat(hudchat, 0, 0, text)
end
local mouse_state = {}
retardedJpg = false
dragging = false
Authed = false
CornerReady = false
ControlCheck = false
AuthClicked = false
SongChanged = false
VolumeMax = false
VolumeMin = false
VolumeCheck = false
FirstPress = false
RunOnceCheck = false
StopSpamming = false
SetCheck = true
forkinCock = true
bool = true
gropeTits = true
animCheck = false
ShuffleState = false
UpdateWaitCheck = false
kanker = false
MenuBarExtended = false
SearchSelected = false
PlaylistSelected = false
PlaylistLimitReached = false
scrollmin = true
scrollmax = false
SongTooLong = false
SpotifyScaleX = sx/4.8
SpotifyScaleY = sy/10.8
SpotifyIndicX2 = 1
adaptivesize = 400
ArtScaleX, ArtScaleY = SpotifyScaleY, SpotifyScaleY
UpdateCount = 0
ClickSpree = 0
ClickSpreeTime = 1
TotalErrors = 0
ErrorSpree = 0
NewApiKeyRequest = 0
AlteredVolume = 0
NewVolume = 0
AnimSizePerc = 100
ProgressBarCache = 0
PlayListCount = 0
TrackCount = 0
scrollvalue = 0
last_analogvalue = 0
CurrentSong = "-"
AuthStatus = "> Not connected"
deviceid = ""
UserName = "-"
SongName = "-"
ArtistName = "-"
SongNameHUD = "-"
ArtistNameHUD = "-"
SongProgression = "-"
SongLength = "-"
ProgressDuration = "-"
TotalDuration = "-"
LeftDuration = "-"
SongNameBack = "-"
HoveringOver = "none"
RepeatState = "off"
loadanim = "."
AuthURL = "https://spotify.stbrouwers.cc/"
local LoopUrl = "https://i.imgur.com/wREhluX.png"
local LoopActiveUrl = "https://i.imgur.com/rEEvjzM.png"
local ShuffleUrl = "https://i.imgur.com/8hjJTCO.png"
local ShuffleActiveUrl = "https://i.imgur.com/HNVpf4j.png"
local VolumeSpeakerUrl = "https://i.imgur.com/rj2IJfJ.png"
local function CP()
local len = native_GetClipboardTextCount()
if len > 0 then
local char_arr = new_char_arr(len)
native_GetClipboardText(0, char_arr, len)
return ffi.string(char_arr, len-1)
end
end
local function splitByChunk(text, chunkSize)
local s = {}
for i=1, #text, chunkSize do
s[#s+1] = text:sub(i,i+chunkSize - 1)
end
return s
end
function mouse_state.new()
return setmetatable({tape = 0, laststate = 0, initd = false, events = {}}, {__index = mouse_state})
end
local scrollstate = mouse_state.new()
function mouse_state:init()
if not self.init then
self.tape = 0
self.laststate = GetAnalogDelta(inputsystem, 0x03)
self.initd = true
end
if GetAnalogDelta(inputsystem, 0x03) == 0 and self.tape ~= 0 then
self.tape = 0
return
end
local currentTape = GetAnalogValue(inputsystem, 0x03)
if currentTape > self.tape then
for index, value in ipairs(self.events) do
value({state = "Up", pos = currentTape})
end
self.tape = currentTape
elseif currentTape < self.tape then
for index, value in ipairs(self.events) do
value({state = "Down", pos = currentTape})
end
self.tape = currentTape
end
if GetAnalogValue(inputsystem, 0x03) >= last_analogvalue + 1 and not scrollmin then
scrollvalue = scrollvalue + 1
elseif GetAnalogValue(inputsystem, 0x03) <= last_analogvalue - 1 and not scrollmax then
scrollvalue = scrollvalue - 1
end
last_analogvalue = GetAnalogValue(inputsystem, 0x03)
end
http.get(LoopUrl, function(success, response)
if not success or response.status ~= 200 then
return
end
Loop = images.load_png(response.body)
end)
http.get(LoopActiveUrl, function(success, response)
if not success or response.status ~= 200 then
return
end
LoopA = images.load_png(response.body)
end)
http.get(ShuffleUrl, function(success, response)
if not success or response.status ~= 200 then
return
end
Shuffle = images.load_png(response.body)
end)
http.get(ShuffleActiveUrl, function(success, response)
if not success or response.status ~= 200 then
return
end
ShuffleA = images.load_png(response.body)
end)
http.get(VolumeSpeakerUrl, function(success, response)
if not success or response.status ~= 200 then
return
end
VolumeSpeaker = images.load_png(response.body)
end)
currplaylist = {}
if database_read("previous_posX") == nil then
database_write("previous_posX", SpotifyIndicX)
database_write("previous_posY", SpotifyIndicY)
else
if database_read("previous_posX") >= sx + 3 then
SpotifyIndicX = 0
SpotifyIndicY = 1020
end
end
Playlistcache = database_read("playlistcache")
if database_read("savedplaylists") == nil then
Playlists = {}
Playlistcache = ""
else
Playlists = database_read("savedplaylists")
for i, id in ipairs(Playlists) do
PlayListCount = PlayListCount + 1
end
end
switch = function(check)
return function(cases)
if type(cases[check]) == "function" then
return cases[check]()
elseif type(cases["default"] == "function") then
return cases["default"]()
end
end
end
local msConversion = function(b)
local c=math.floor(b/1000)
local d=math.floor(c/3600)
local c=c-d*3600;
local e=math.floor(c/60)
local c='00'..c-e*60;
local c=c:sub(#c-1)
if d>0 then
local e=''..e;
local e=('00'..e):sub(#e+1)
return d..':'..e..':'..c
else
return e..':'..c
end
end
function round(n)
return n % 1 >= 0.5 and math.ceil(n) or math.floor(n)
end
local function GetRefreshToken()
if AuthClicked == false then return end
local js = panorama.loadstring([[
return {
open_url: function(url){
SteamOverlayAPI.OpenURL(url)
}
}
]])()
js.open_url(AuthURL)
end
function GetApiToken()
if NewApiKeyRequest <= 5 then
if PendingRequest then return end
PendingRequest = true
if AuthClicked == true then
AuthStatus = "TRYING"
end
http.get("https://spotify.stbrouwers.cc/refresh_token?refresh_token="..refreshkey, function(s, r)
if r.status ~= 200 then
AuthStatus = "WRONGKEY"
PendingRequest = false
GetRefreshToken()
NewApiKeyRequest = NewApiKeyRequest + 1
return
else
PendingRequest = false
NewApiKeyRequest = 0
parsed = json.parse(r.body)
apikey = parsed.access_token
Auth()
end
end)
else
return
end
end
function Auth()
if AuthClicked == true then refreshkey = CP() end
if refreshkey == nil then GetRefreshToken() return end
if refreshkey ~= nil and apikey == nil then
GetApiToken()
return end
if refreshkey ~= nil and apikey ~= nil then
http.get("https://api.spotify.com/v1/me?&access_token=" .. apikey, function(success, response)
ConnectionStatus = response.status
if not success or response.status ~= 200 then
ConnectionStatus = response.status
Authed = false
AuthStatus = "FAILED"
GetApiToken()
ShowMenuElements()
UpdateElements()
return end
UpdateCount = UpdateCount + 1
spotidata = json.parse(response.body)
UserName = spotidata.display_name
Authed = true
AuthStatus = "SUCCESS"
ShowMenuElements()
UpdateElements()
end)
end
end
Auth()
function DAuth()
if not ConnectionStatus then return end
if ConnectionStatus == 202 then
AuthStatus = "SUCCESS"
end
if ConnectionStatus == 403 then
AuthStatus = "FORBIDDEN"
ErrorSpree = ErrorSpree + 1
TotalErrors = TotalErrors + 1
end
if ConnectionStatus == 429 then
AuthStatus = "RATE"
ErrorSpree = ErrorSpree + 1
TotalErrors = TotalErrors + 1
end
if ConnectionStatus == 503 then
AuthStatus = "APIFAIL"
ErrorSpree = ErrorSpree + 1
TotalErrors = TotalErrors + 1
end
ShowMenuElements()
UpdateElements()
end
function UpdateInf()
SongNameBack = SongName
if UpdateWaitCheck == false then
DAuth()
http.get("https://api.spotify.com/v1/me/player?access_token=" .. apikey, function(success, response)
if not success or response.status ~= 200 then
AuthStatus = "TOKEN"
ErrorSpree = ErrorSpree + 1
TotalErrors = TotalErrors + 1
UpdateWaitCheck = true
return
end
CurrentDataSpotify = json.parse(response.body)
if CurrentDataSpotify == nil then return end
deviceid = CurrentDataSpotify.device.id
if RunOnceCheck == false then
NewVolume = CurrentDataSpotify.device.volume_percent
RunOnceCheck = true
end
if CurrentDataSpotify.is_playing and CurrentDataSpotify.currently_playing_type == "episode" then
SongName = "Podcast"
ArtistName = ""
PlayState = "Playing"
elseif CurrentDataSpotify.is_playing then
SongName = CurrentDataSpotify.item.name
SongNameHUD = CurrentDataSpotify.item.name
ArtistName = CurrentDataSpotify.item.artists[1].name
ArtistNameHUD = CurrentDataSpotify.item.artists[1].name
Currenturi = CurrentDataSpotify.item.uri
PlayState = "Playing"
else
SongName = "Music paused"
PlayState = "Paused"
ArtistName = ""
end
SongLength = CurrentDataSpotify.item.duration_ms / 1000
SongProgression = CurrentDataSpotify.progress_ms / 1000
ShuffleState = CurrentDataSpotify.shuffle_state
RepeatState = CurrentDataSpotify.repeat_state
ProgressBarCache = CurrentDataSpotify.progress_ms
VolumeBarCache = CurrentDataSpotify.device.volume_percent
TotalDuration = msConversion(CurrentDataSpotify.item.duration_ms)
ProgressDuration = msConversion(CurrentDataSpotify.progress_ms)
LeftDuration = msConversion(CurrentDataSpotify.item.duration_ms - CurrentDataSpotify.progress_ms)
if not CurrentDataSpotify.item.is_local then
ThumbnailUrl = CurrentDataSpotify.item.album.images[1].url
http.get(ThumbnailUrl, function(success, response)
if not success or response.status ~= 200 then
return
end
Thumbnail = images.load_jpg(response.body)
end)
end
if SongNameBack ~= SongName and SongNameBack ~= nil then
SpotifyIndicX2 = SpotifyIndicX+adaptivesize
SongChanged = true
end
end)
end
UpdateWaitCheck = false
end
function PlayPause()
local options = {
headers = {
["Accept"] = "application/json",
["Content-Type"] = "application/json",
["Authorization"] = "Bearer " .. apikey,
["Content-length"] = 0
}
}
if CurrentDataSpotify.is_playing then
PlayState = "Paused"
http.put("https://api.spotify.com/v1/me/player/pause?device_id=" .. deviceid, options, function(s, r)
UpdateCount = UpdateCount + 1
end)
else
PlayState = "Playing"
http.put("https://api.spotify.com/v1/me/player/play?device_id=" .. deviceid, options, function(s, r)
UpdateCount = UpdateCount + 1
UpdateWaitCheck = true
end)
end
end
function NextTrack()
local options = {
headers = {
["Accept"] = "application/json",
["Content-Type"] = "application/json",
["Authorization"] = "Bearer " .. apikey,
["Content-length"] = 0
}
}
http.post("https://api.spotify.com/v1/me/player/next?device_id=" .. deviceid, options, function(s, r)
UpdateCount = UpdateCount + 1
end)
end
function PreviousTrack()
local options = {
headers = {
["Accept"] = "application/json",
["Content-Type"] = "application/json",
["Authorization"] = "Bearer " .. apikey,
["Content-length"] = 0
}
}
http.post("https://api.spotify.com/v1/me/player/previous?device_id=" .. deviceid, options, function(s, r)
UpdateCount = UpdateCount + 1
end)
end
function ShuffleToggle()
if ShuffleState == true then
ShuffleState = false
else
ShuffleState = true
end
local options = {
headers = {
["Accept"] = "application/json",
["Content-Type"] = "application/json",
["Authorization"] = "Bearer " .. apikey,
["Content-length"] = 0
}
}
http.put("https://api.spotify.com/v1/me/player/shuffle?device_id=" .. deviceid .. "&state=" .. tostring(ShuffleState), options, function(s, r)
UpdateCount = UpdateCount + 1
UpdateWaitCheck = true
end)
end
function LoopToggle()
if RepeatState == "off" then
RepeatState = "context"
elseif RepeatState == "context" then
RepeatState = "track"
elseif RepeatState == "track" then
RepeatState = "off"
end
local options = {
headers = {
["Accept"] = "application/json",
["Content-Type"] = "application/json",
["Authorization"] = "Bearer " .. apikey,
["Content-length"] = 0
}
}
http.put("https://api.spotify.com/v1/me/player/repeat?device_id=" .. deviceid .. "&state=" .. RepeatState, options, function(s, r)
UpdateCount = UpdateCount + 1
UpdateWaitCheck = true
end)
end
local elements = {
Connected = ui_new_label("MISC", "Miscellaneous", AuthStatus),
AuthButton = ui_new_button("MISC", "Miscellaneous", "Authorize", function() AuthClicked = true Auth() end),
IndicType = ui_new_combobox("MISC", "Miscellaneous", "Type", "Spotify", "Minimal"),
Additions = ui_new_multiselect("MISC", "Miscellaneous", "Additions", "Cover art", "Duration", "Vitals", "Fixed width"),
CustomLayoutType = ui_new_combobox("MISC", "Miscellaneous", "Art location", "Left", "Right"),
MenuSize = ui_new_slider("MISC", "Miscellaneous", "Scale", 50, 150, 100, true, "%"),
WidthLock = ui_new_label("MISC", "Miscellaneous", "⭥ [LINKED] ⭥"),
MinimumWidth = ui_new_slider("MISC", "Miscellaneous", "Minimum box width", 199, 600, 400, true, "px", 1, { [199] = "Auto"}),
FixedWidth = ui_new_slider("MISC", "Miscellaneous", "Box width", 200, 600, 400, true, "px", 1),
DebugInfo = ui_new_checkbox("MISC", "Miscellaneous", "Debug info"),
NowPlaying = ui_new_label("MISC", "Miscellaneous", "Now playing:" .. SongName),
Artist = ui_new_label("MISC", "Miscellaneous", "By:" .. ArtistName),
SongDuration = ui_new_label("MISC", "Miscellaneous", SongProgression .. SongLength),
VolumeLabel = ui_new_label("MISC", "Miscellaneous", "NewVolume: " .. NewVolume),
UpdateRate = ui_new_slider("MISC", "Miscellaneous", "Update rate", 0.5, 5, 1, true, "s"),
RateLimitWarning = ui_new_label("MISC", "Miscellaneous", "WARNING: using <1s updaterate might get you ratelimited"),
SessionUpdates = ui_new_label("MISC", "Miscellaneous", "Total updates this session: " .. UpdateCount),
TotalErrors = ui_new_label("MISC", "Miscellaneous", "Errors this session: " .. TotalErrors),
SpreeErrors = ui_new_label("MISC", "Miscellaneous", "Errors this spree: " .. ErrorSpree),
RecentError = ui_new_label("MISC", "Miscellaneous", "Most recent error: " .. "-"),
MaxErrors = ui_new_slider("MISC", "Miscellaneous", "Max errors", 1, 20, 5, true, "x"),
ErrorRate = ui_new_slider("MISC", "Miscellaneous", "within", 5, 300, 30, true, "s"),
FirstPressAmount = ui_new_slider("MISC", "Miscellaneous", "First press amount", 1, 20, 5, true, "%"),
VolumeTickSpeed = ui_new_slider("MISC", "Miscellaneous", "Volume tick speed", 1, 64, 2, true, "tc"),
VolumeTickAmount = ui_new_slider("MISC", "Miscellaneous", "Volume tick amount", 1, 10, 1, true, "%"),
SpotifyPosition = ui_new_label("MISC", "Miscellaneous", "Position(x - x2(width), y): " .. SpotifyIndicX .. " - " .. SpotifyIndicX2 .. "(" .. adaptivesize .. "), " .. SpotifyIndicY .. "y"),
AddError = ui_new_button("MISC", "Miscellaneous", "Add an error", function() AuthStatus = "TOKEN" ErrorSpree = ErrorSpree + 1 TotalErrors = TotalErrors + 1 end),
ForceReflowButton = ui_new_button("MISC", "Miscellaneous", "Force element reflow", function() ForceReflow() end),
MenuBarEnable = ui_new_checkbox("MISC", "Miscellaneous", "Menu bar"),
HideOriginIndic = ui_new_checkbox("MISC", "Miscellaneous", "Hide indicator while in menu"),
CustomColors = ui_new_checkbox("MISC", "Miscellaneous", "Custom colors"),
ProgressGradientSwitch = ui_new_checkbox("MISC", "Miscellaneous", "Gradient progress bar"),
BackgroundGradientSwitch = ui_new_checkbox("MISC", "Miscellaneous", "Gradient background"),
LabelProgressGradient1 = ui_new_label("MISC", "Miscellaneous", " - Progress gradient L"),
ProgressGradient1 = ui_new_color_picker("MISC", "Miscellaneous", "progressbar gradient 1", 0, 255, 0, 255),
LabelProgressGradient2 = ui_new_label("MISC", "Miscellaneous", " - Progress gradient R"),
ProgressGradient2 = ui_new_color_picker("MISC", "Miscellaneous", "progressbar gradient 2", 0, 255, 0, 255),
LabelGradientColour = ui_new_label("MISC", "Miscellaneous", " - Progress bar color"),
GradientColour = ui.new_color_picker("MISC", "Miscellaneous", "progress bar Colourpicker", 0, 255, 0, 255),
LabelBackgroundColor = ui_new_label("MISC", "Miscellaneous", " - Background color"),
BackgroundColour = ui_new_color_picker("MISC", "Miscellaneous", "Background colourrpicker", 25, 25, 25, 255),
LabelBackgroundColorGradient1 = ui_new_label("MISC", "Miscellaneous", " - Background gradient L"),
BackgroundColorGradient1 = ui_new_color_picker("MISC", "Miscellaneous", "Background Gradient colourpicker1", 25, 25, 25, 50),
LabelBackgroundColorGradient2 = ui_new_label("MISC", "Miscellaneous", " - Background gradient R"),
BackgroundColorGradient2 = ui_new_color_picker("MISC", "Miscellaneous", "Background Gradient colourpicker2", 25, 25, 25, 255),
LabelTextColorPrimary = ui_new_label("MISC", "Miscellaneous", " - Primary text color"),
TextColorPrimary = ui_new_color_picker("MISC", "Miscellaneous", "Primary text clr", 255, 255, 255, 255),
LabelTextColorSecondary = ui_new_label("MISC", "Miscellaneous", " - Secondary text color"),
TextColorSecondary = ui_new_color_picker("MISC", "Miscellaneous", "Secondary text clr", 159, 159, 159, 255),
ControlSwitch = ui_new_checkbox("MISC", "Miscellaneous", "Controls"),
SmartControlSwitch = ui_new_checkbox("MISC", "Miscellaneous", "Smart controls"),
SmartVolumeSwitch = ui_new_checkbox("MISC", "Miscellaneous", "Smart volume"),
SmartControls = ui_new_hotkey("MISC", "Miscellaneous", " - Smart Controls", true),
PlayPause = ui_new_hotkey("MISC", "Miscellaneous", " - Play/Pause", false),
SkipSong = ui_new_hotkey("MISC", "Miscellaneous", " - Skip song", false),
PreviousSong = ui_new_hotkey("MISC", "Miscellaneous", " - Previous song", false),
IncreaseVolume = ui_new_hotkey("MISC", "Miscellaneous", " - Volume up", false),
DecreaseVolume = ui_new_hotkey("MISC", "Miscellaneous", " - Volume down", false),
AdaptiveVolume = ui_new_slider("MISC", "Miscellaneous", "Decrease volume by % on voicechat", 0, 100, "off", true, "%", 1, { [0] = "off", [100] = "mute"}),
ExtrasBox = ui_new_multiselect("MISC", "Miscellaneous", "Extras", "Print song changes in chat", "Now playing clantag", "Higher update rate (experimental)"),
ResetAuth = ui_new_button("MISC", "Miscellaneous", "Reset authorization", function() ResetAPI() end),
KankerOp = ui_new_button("MISC", "Miscellaneous", "Reset playlists", function() database_write("savedplaylists", nil) Playlists = {} PlayListCount = 0 PlaylistLimitReached = false currplaylist = {} currplaylisturi = "" currplaylistname = "" TrackCount = 0 Playlistcache = "" database_write("playlistcache", Playlistcache) PlaylistSelected = false end),
}
function ChangeVolume(Svol)
if kanker then
kanker = false
local options = {
headers = {
["Accept"] = "application/json",
["Content-Type"] = "application/json",
["Authorization"] = "Bearer " .. apikey,
["Content-length"] = 0
}
}
http.put("https://api.spotify.com/v1/me/player/volume?volume_percent=" .. round(Svol) .. "&device_id=" .. deviceid, options, function(s, r)
UpdateCount = UpdateCount + 1
end)
VolumeBarCache = ScrolledVolume
else
if stopRequest then return end
local options = {
headers = {
["Accept"] = "application/json",
["Content-Type"] = "application/json",
["Authorization"] = "Bearer " .. apikey,
["Content-length"] = 0
}
}
http.put("https://api.spotify.com/v1/me/player/volume?volume_percent=" .. NewVolume .. "&device_id=" .. deviceid, options, function(s, r)
UpdateCount = UpdateCount + 1
end)
stopRequest = true
StopSpamming = false
SetCheck = true
UpdateInf()
end
end
function Seek(seekms)
local options = {
headers = {
["Accept"] = "application/json",
["Content-Type"] = "application/json",
["Authorization"] = "Bearer " .. apikey,
["Content-length"] = 0
}
}
http.put("https://api.spotify.com/v1/me/player/seek?position_ms=" .. round(seekms) .. "&device_id=" .. deviceid, options, function(s, r)
UpdateCount = UpdateCount + 1
end)
ProgressBarCache = CurrentDataSpotify.item.duration_ms/404*MouseHudPosXprgs
ProgressDuration = msConversion(SeekedTime)
LeftDuration = msConversion(CurrentDataSpotify.item.duration_ms-SeekedTime)
end
function PlaySong(n, k, y, s)
local niggers = json.stringify({context_uri = "spotify:playlist:" .. currplaylisturi, offset = {position = n-1}, position_ms = 0})
local options = {
headers = {
["Accept"] = "application/json",
["Content-Type"] = "application/json",
["Authorization"] = "Bearer " .. apikey,
},
body = niggers
}
http.put("https://api.spotify.com/v1/me/player/play", options, function(s, r)
UpdateCount = UpdateCount + 1
if not success or response.status ~= 200 then return end
SongNameHUD = k
ArtistNameHUD = y
ThumbnailUrl = s
http.get(ThumbnailUrl, function(success, response)
if not success or response.status ~= 200 then
return
end
Thumbnail = images.load_jpg(response.body)
end)
end)
end
function QueueSong(uri)
local options = {
headers = {
["Accept"] = "application/json",
["Content-Type"] = "application/json",
["Authorization"] = "Bearer " .. apikey,
["Content-length"] = 0
}
}
http.post("https://api.spotify.com/v1/me/player/queue?uri=" .. uri .. "&device_id=" .. deviceid, options, function(s, r)
UpdateCount = UpdateCount + 1
end)
end
function InitPlaylist(id)
if id == nil then client.color_log(255, 0, 0, "Failed to add playlist. Make sure that you have your Playlist link in your clipboard, and that the formatting is correct. (https://open.spotify.com/playlist/6piHLVTmzq8nTix2wIlM8x?si=10c8288bd6fc4f94)") return end
if string.find(Playlistcache, id) ~= nil then client.color_log(255, 0, 0, "You have already added this playlist!") return end
UpdateWaitCheck = true
http.get("https://api.spotify.com/v1/playlists/" .. id .. "?access_token=" .. apikey .. "&fields=name", function(s, r) -- tracks.items(track(name%2C%20uri%2C%20images%2C%20album.artists%2C%20duration_ms))%2C%20
if not s or r.status ~= 200 then
client.color_log(255, 0, 0, "Failed to add playlist. Make sure that you have your Playlist link in your clipboard, and that the formatting is correct. (https://open.spotify.com/playlist/6piHLVTmzq8nTix2wIlM8x?si=10c8288bd6fc4f94)")
return
end
PlayListCount = PlayListCount + 1
local temp = json.parse(r.body)
table.insert(Playlists, {id = PlayListCount, PlaylistName = temp.name .. "," .. id})
Playlistcache = Playlistcache .. id
UpdateCount = UpdateCount + 1
end)
end
function LoadPlaylist(uri)
local jekanker, moeder = string.match(uri, "(.*),(.*)")
TrackCount = 0
UpdateWaitCheck = true
http.get("https://api.spotify.com/v1/playlists/".. moeder .."/tracks?market=US&limit=100&offset=0" .. "&access_token=" .. apikey, function(s, r)
if not s or r.status ~= 200 then return end
currplaylist = {}
currplaylistname = jekanker
currplaylisturi = moeder
local temp = json.parse(r.body)
for i, track in ipairs(temp.items) do
TrackCount = TrackCount + 1
table.insert(currplaylist, {id = TrackCount, SongDetails = temp.items[i].track.name .. "^" .. temp.items[i].track.artists[1].name .. "^" .. temp.items[i].track.duration_ms .. "^" .. temp.items[i].track.uri .. "^" .. temp.items[i].track.album.images[3].url})
PlaylistSelected = true
UpdateCount = UpdateCount + 1
end
end)
end
function AddPlaylist(uri)
UpdateWaitCheck = true
http.get("https://api.spotify.com/v1/playlists/".. uri .."/tracks?market=US&limit=100&offset=".. TrackCount .. "&access_token=" .. apikey, function(s, r)
if not s or r.status ~= 200 then return end
local temp = json.parse(r.body)
for i, track in ipairs(temp.items) do
TrackCount = TrackCount + 1
table.insert(currplaylist, {id = TrackCount, SongDetails = temp.items[i].track.name .. "^" .. temp.items[i].track.artists[1].name .. "^" .. temp.items[i].track.duration_ms .. "^" .. temp.items[i].track.uri .. "^" .. temp.items[i].track.album.images[3].url})
UpdateCount = UpdateCount + 1
end
end)
end
function setConnected(value)
ui_set(elements.Connected, value)
end
local startpos = {
DRegionx = 0, DRegiony = 0,
}
local endpos = {
DRegionx = SpotifyScaleX, DRegiony = SpotifyScaleY,
}
local function intersect(x, y, w, h, debug)
local mousepos = { ui.mouse_position() }
rawmouseposX = mousepos[1]
rawmouseposY = mousepos[2]
debug = debug or false
if debug then
surface.draw_filled_rect(x, y, w, h, 255, 0, 0, 50)
end
return rawmouseposX >= x and rawmouseposX <= x + w and rawmouseposY >= y and rawmouseposY <= y + h
end
local function contains(table, value)
if table == nil then
return false
end
table = ui_get(table)
for i=0, #table do
if table[i] == value then
return true
end
end
return false
end
function ShowMenuElements()
if ui_get(MainCheckbox) and Authed then
ui_set_visible(elements.Connected, true)
ui_set_visible(elements.AuthButton, false)
ui_set_visible(elements.NowPlaying, true)
ui_set_visible(elements.Artist, true)
ui_set_visible(elements.SongDuration, true)
ui_set_visible(elements.IndicType, true)
ui_set_visible(elements.GradientColour, true)
ui_set_visible(elements.LabelGradientColour, true)
ui_set_visible(elements.CustomColors, true)
ui_set_visible(elements.ControlSwitch, true)
ui_set_visible(elements.MenuSize, true)
ui_set_visible(elements.ResetAuth, true)
ui_set_visible(elements.MenuBarEnable, true)
ui_set_visible(elements.ExtrasBox, true)
if ui_get(elements.IndicType) == "Spotify" then
ui_set_visible(elements.WidthLock, ShiftClick)
ui_set_visible(elements.MinimumWidth, not contains(elements.Additions, "Fixed width"))
ui_set_visible(elements.CustomLayoutType, contains(elements.Additions, "Cover art"))
ui_set_visible(elements.FixedWidth, contains(elements.Additions, "Fixed width"))
ui_set_visible(elements.Additions, true)
if ui_get(elements.CustomColors) then
ui_set_visible(elements.ProgressGradientSwitch, true)
ui_set_visible(elements.BackgroundGradientSwitch, true)
ui_set_visible(elements.LabelTextColorPrimary, true)
ui_set_visible(elements.TextColorPrimary, true)
ui_set_visible(elements.LabelTextColorSecondary, true)
ui_set_visible(elements.TextColorSecondary, true)
ui_set_visible(elements.BackgroundColour, true)
ui_set_visible(elements.LabelBackgroundColor, true)
if ui_get(elements.ProgressGradientSwitch) then
ui_set_visible(elements.LabelProgressGradient1, true)
ui_set_visible(elements.ProgressGradient1, true)
ui_set_visible(elements.LabelProgressGradient2, true)
ui_set_visible(elements.ProgressGradient2, true)
ui_set_visible(elements.GradientColour, false)
ui_set_visible(elements.LabelGradientColour, false)
else
ui_set_visible(elements.GradientColour, true)
ui_set_visible(elements.LabelGradientColour, true)
ui_set_visible(elements.LabelProgressGradient1, false)
ui_set_visible(elements.ProgressGradient1, false)
ui_set_visible(elements.LabelProgressGradient2, false)
ui_set_visible(elements.ProgressGradient2, false)
end
if ui_get(elements.BackgroundGradientSwitch) then
ui_set_visible(elements.BackgroundColorGradient1, true)
ui_set_visible(elements.LabelBackgroundColorGradient1, true)
ui_set_visible(elements.BackgroundColorGradient2, true)
ui_set_visible(elements.LabelBackgroundColorGradient2, true)
else
ui_set_visible(elements.BackgroundColorGradient1, false)
ui_set_visible(elements.LabelBackgroundColorGradient1, false)
ui_set_visible(elements.BackgroundColorGradient2, false)
ui_set_visible(elements.LabelBackgroundColorGradient2, false)
end
else
ui_set_visible(elements.ProgressGradientSwitch, false)
ui_set_visible(elements.BackgroundGradientSwitch, false)
ui_set_visible(elements.BackgroundColour, false)
ui_set_visible(elements.LabelBackgroundColor, false)
ui_set_visible(elements.LabelTextColorPrimary, false)
ui_set_visible(elements.TextColorPrimary, false)
ui_set_visible(elements.LabelTextColorSecondary, false)
ui_set_visible(elements.TextColorSecondary, false)
ui_set_visible(elements.BackgroundColorGradient1, false)
ui_set_visible(elements.LabelBackgroundColorGradient1, false)
ui_set_visible(elements.BackgroundColorGradient2, false)
ui_set_visible(elements.LabelBackgroundColorGradient2, false)
ui_set_visible(elements.LabelProgressGradient1, false)
ui_set_visible(elements.ProgressGradient1, false)
ui_set_visible(elements.LabelProgressGradient2, false)
ui_set_visible(elements.ProgressGradient2, false)
ui_set_visible(elements.GradientColour, false)
ui_set_visible(elements.LabelGradientColour, false)
end
elseif ui_get(elements.IndicType) == "Minimal" then
ui_set_visible(elements.MinimumWidth, false)
ui_set_visible(elements.ProgressGradientSwitch, false)
ui_set_visible(elements.BackgroundGradientSwitch, false)
ui_set_visible(elements.BackgroundColour, false)
ui_set_visible(elements.LabelBackgroundColor, false)
ui_set_visible(elements.LabelTextColorPrimary, false)
ui_set_visible(elements.TextColorPrimary, false)
ui_set_visible(elements.LabelTextColorSecondary, false)
ui_set_visible(elements.TextColorSecondary, false)
ui_set_visible(elements.BackgroundColorGradient1, false)
ui_set_visible(elements.LabelBackgroundColorGradient1, false)
ui_set_visible(elements.BackgroundColorGradient2, false)
ui_set_visible(elements.LabelBackgroundColorGradient2, false)
ui_set_visible(elements.LabelProgressGradient1, false)
ui_set_visible(elements.ProgressGradient1, false)
ui_set_visible(elements.LabelProgressGradient2, false)
ui_set_visible(elements.ProgressGradient2, false)
ui_set_visible(elements.GradientColour, false)
ui_set_visible(elements.LabelGradientColour, false)
ui_set_visible(elements.MenuSize, false)
ui_set_visible(elements.CustomLayoutType, false)
ui_set_visible(elements.Additions, false)
ui_set_visible(elements.FixedWidth, false)
if ui_get(elements.CustomColors) then
ui_set_visible(elements.GradientColour, true)
ui_set_visible(elements.LabelGradientColour, true)
else
ui_set_visible(elements.GradientColour, false)
ui_set_visible(elements.LabelGradientColour, false)
end
else
ui_set_visible(elements.MinimumWidth, false)
ui_set_visible(elements.CustomLayoutType, false)
ui_set_visible(elements.ProgressGradientSwitch, false)
ui_set_visible(elements.BackgroundColour, false)
ui_set_visible(elements.LabelBackgroundColor, false)
ui_set_visible(elements.LabelTextColorPrimary, false)
ui_set_visible(elements.TextColorPrimary, false)
ui_set_visible(elements.LabelTextColorSecondary, false)
ui_set_visible(elements.TextColorSecondary, false)
ui_set_visible(elements.BackgroundColorGradient1, false)
ui_set_visible(elements.LabelBackgroundColorGradient1, false)
ui_set_visible(elements.BackgroundColorGradient2, false)
ui_set_visible(elements.LabelBackgroundColorGradient2, false)
ui_set_visible(elements.LabelProgressGradient1, false)
ui_set_visible(elements.ProgressGradient1, false)
ui_set_visible(elements.LabelProgressGradient2, false)
ui_set_visible(elements.ProgressGradient2, false)
ui_set_visible(elements.GradientColour, false)
ui_set_visible(elements.LabelGradientColour, false)
end
if ui_get(elements.MenuBarEnable) then
ui_set_visible(elements.HideOriginIndic, true)
ui_set_visible(elements.KankerOp, true)
else
ui_set_visible(elements.HideOriginIndic, false)
ui_set_visible(elements.KankerOp, false)
end
if ui_get(elements.ControlSwitch) then
ui_set_visible(elements.SmartControlSwitch, true)
ui_set_visible(elements.SmartVolumeSwitch, false)