-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStreamHelper.au3
2555 lines (2061 loc) · 84.1 KB
/
StreamHelper.au3
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
#cs
[FakeIniSectionName]
#ce
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=Svartnos.ico
#AutoIt3Wrapper_UseX64=n
#AutoIt3Wrapper_Res_Description=StreamHelper
#AutoIt3Wrapper_Res_Fileversion=1.5.3.0
#AutoIt3Wrapper_Res_ProductVersion=1.5.3.0
#AutoIt3Wrapper_Res_LegalCopyright=©2015-2020 Alexander Samuelsson
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#AutoIt3Wrapper_Run_Au3Stripper=y
#AutoIt3Wrapper_Au3Stripper_OnError=ForceUse
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs ----------------------------------------------------------------------------
AutoIt Version: 3.3.14.2 (Stable)
Author: Alexander Samuelsson AKA AdmiralAlkex
Script Function:
Stuff
Todo:
*Add back the quality stuff in the array now that Twitch changed how they allocate transcoding to non-partners?
*Always save quality stuff to array for partners?
*Beep confirmed as annoying.
*BroccoliCat on twitch doesn't load properly on source quality in livestreamer.
Increase the timer wait thing in the config file?
I have increased multiple seconds, difference is questionable?
(needs to be verified if it still happens with streamlink!)
*Favs changing games make the sound but not the notification?
*Add a check for when twitch says it returns x items and there is not x items in the response array (and log it!)
2017-10-25 19:13:25 : myURL users/follows?from_id=37714348&first=100&after=eyJiIjpudWxsLCJhIjoiMTQ1NDcwNjQ0OTY2OTg5MDAwMCJ9
2017-10-25 19:13:26 : HTTP/1.1 502 Bad Gateway \ Connection: keep-alive \ Date: Wed, 25 Oct 2017 17:13:26 GMT \ Content-Length: 138 \ Content-Type: text/html \ Server: awselb/2.0
2017-10-25 19:13:26 : <html>
<head><title>502 Bad Gateway</title></head>
<body bgcolor="white">
<center><h1>502 Bad Gateway</h1></center>
</body>
</html>
wtf fix!
*Notifications are not optimal (only 4 rows are seen, so if there's more than 4 streams you just don't see the extras)
*Check if AutoIt can use the appx protocol
ms-appx:///Relative/Path/To/Content.jpg
NO IT CAN NOT!!
*Remake icon?
*Or redo in better quality (Square310x310Logo.scale-400.png is just a resized Square310x310Logo.scale-200.png)
*I'm pretty sure it just notified me of an ignored streamer changing game, verify and fix?
*Switch URL encoding UDF?
"Secondly, the best version I've seen has be ProgAndy's which features in the WinHTTP UDF."
https://www.autoitscript.com/forum/topic/95850-url-encoding/?do=findComment&comment=1019203
*Look at possibility to get streams from friends.
#cs
/// <summary>
/// Redirect user to Windows Store and open the review window for current App
/// </summary>
/// <returns>Task</returns>
public static async Task OpenStoreReviewAsync()
{
var pfn = Package.Current.Id.FamilyName;
await Launcher.LaunchUriAsync(new Uri("ms-windows-store://review/?PFN=" + pfn));
}
#ce
#cs
wintoast.exe --appname "Git for Windows" \
--appid GitForWindows.Updater \
--image /mingw$bit/share/git/git-for-windows.ico \
--text "Download and install $name$warn?" \
--action Yes --action No --expirems 15000
#ce
*https://docs.microsoft.com/en-us/windows/uwp/design/shell/tiles-and-notifications/adaptive-interactive-toasts
*https://blogs.msdn.microsoft.com/lucian/2015/10/23/how-to-call-uwp-apis-from-a-desktop-vbc-app/
*https://docs.microsoft.com/en-us/uwp/api/windows.applicationmodel.startuptaskstate
*use mailgun for gathering feedback and logs?
https://www.mailgun.com/
https://documentation.mailgun.com/en/latest/index.html
*move Reset-button to the right of the username editbox?
*Change button to say "Forget ID & Username"?
*Make myself a install button to put on websites like http://vidcoder.net/ have
ms-windows-store://pdp/?productid=*12LETTERSANDNUMBERS*
*Detect if Tc is installed and enable a "Open chat in Tc" button on the "Play from clipboard"-window.
.\Tc.exe --channel="swebliss"
So stupid, --channel only works if Tc is not already running. And there isn't even a very nice way to close it to make a hack around it.
*remove $eTime, use $eCreated and generate time live on tooltip show instead
*add >:( to random places
*Use for refresh button? https://stackoverflow.com/a/54006960
#ce ----------------------------------------------------------------------------
#include <AutoItConstants.au3>
#include "Json.au3"
#include <Array.au3>
#include <Date.au3>
#include <GDIPlus.au3>
#include <WinAPIShellEx.au3>
#include <WindowsConstants.au3>
#include <WinAPIDiag.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WinAPISys.au3>
#include <GuiComboBox.au3>
#include <Misc.au3>
#include <File.au3>
#include <GuiEdit.au3>
#include <UpDownConstants.au3>
#include "WinHttp.au3"
#include <GuiMenu.au3>
#include <String.au3>
#include "APIStuff.au3"
#include "CentennialHelper.au3"
#include <GuiListBox.au3>
#include <TrayConstants.au3>
#include <IE.au3>
#include "IE_EmbeddedVersioning.au3"
#include <Math.au3>
#include <StaticConstants.au3>
$iWM = _WinAPI_RegisterWindowMessage("AutoIt window with hopefully a unique title|Singleton")
_WinAPI_PostMessage($HWND_BROADCAST, $iWM, 0x1234, 0xABCD)
GUICreate("AutoIt window with hopefully a unique title|Senap the third")
GUIRegisterMsg($WM_POWERBROADCAST, "_PowerEvents")
GUIRegisterMsg($WM_ENDSESSION, "_EndSessionEvents")
GUIRegisterMsg($iWM, "_RemoteEvents")
TraySetToolTip("StreamHelper")
If (Not @Compiled) Then
TraySetIcon(@ScriptDir & "\Svartnos.ico", -1)
EndIf
$iClosePreviousBeforePlaying = True
Global Enum $eAppX, $eClassic
Global $asInstallType[2]
$asInstallType[$eAppX] = "AppX"
$asInstallType[$eClassic] = "Classic"
Global $sLog = RegRead("HKCU\SOFTWARE\StreamHelper\", "Log")
_CW("Install type: " & _InstallType())
Global $iStreamlinkInstalled = StringInStr(EnvGet("path"), "Streamlink") > 0
_CW("Streamlink found: " & $iStreamlinkInstalled)
Global $sUpdateCheck
If _InstallType() = $asInstallType[$eAppX] Then
$sUpdateCheck = "Never"
Else
$sUpdateCheck = RegRead("HKCU\SOFTWARE\StreamHelper\", "UpdateCheck")
If @error Then $sUpdateCheck = "Daily"
EndIf
$sCheckTime = RegRead("HKCU\SOFTWARE\StreamHelper\", "CheckTime")
If @error Then $sCheckTime = "0"
$sRefreshMinutes = RegRead("HKCU\SOFTWARE\StreamHelper\", "RefreshMinutes")
If @error Then $sRefreshMinutes = 3
$sIgnoreMinutes = RegRead("HKCU\SOFTWARE\StreamHelper\", "IgnoreMinutes")
If @error Then $sIgnoreMinutes = 0
$sIgnoreMinutes = 0
Global $sNewUI = RegRead("HKCU\SOFTWARE\StreamHelper\", "NewUI")
Global $sNewUIMultipleThumbnails = _MultipleThumbnails()
$sStreamlinkEnabled = RegRead("HKCU\SOFTWARE\StreamHelper\", "StreamlinkEnabled")
If @error Then $sStreamlinkEnabled = String(Number($iStreamlinkInstalled))
_CW("Streamlink enabled: " & $sStreamlinkEnabled)
$sStreamlinkPath = RegRead("HKCU\SOFTWARE\StreamHelper\", "StreamlinkPath")
$sStreamlinkQuality = RegRead("HKCU\SOFTWARE\StreamHelper\", "StreamlinkQuality")
If @error Then $sStreamlinkQuality = "best"
$sStreamlinkCommandLine = RegRead("HKCU\SOFTWARE\StreamHelper\", "StreamlinkCommandLine")
Global $iSmashcastEnable = False, $iYoutubeEnable = False
$sTwitchId = RegRead("HKCU\SOFTWARE\StreamHelper\", "TwitchId")
$sTwitchName = RegRead("HKCU\SOFTWARE\StreamHelper\", "TwitchName")
$sTwitchToken = RegRead("HKCU\SOFTWARE\StreamHelper\", "TwitchToken")
$sTwitchGamesMax = RegRead("HKCU\SOFTWARE\StreamHelper\", "TwitchGamesMax")
If @error Then $sTwitchGamesMax = 20
If $iSmashcastEnable Then
$sSmashcastId = RegRead("HKCU\SOFTWARE\StreamHelper\", "SmashcastId")
$sSmashcastName = RegRead("HKCU\SOFTWARE\StreamHelper\", "SmashcastName")
EndIf
If $iYoutubeEnable Then
$sYoutubeId = RegRead("HKCU\SOFTWARE\StreamHelper\", "YoutubeId")
$sYoutubeName = RegRead("HKCU\SOFTWARE\StreamHelper\", "YoutubeName")
EndIf
Global $sInternalVersion
If @Compiled Then
$sInternalVersion = FileGetVersion(@AutoItExe)
Else
$sInternalVersion = IniRead(@ScriptFullPath, "FakeIniSectionName", "#AutoIt3Wrapper_Res_Fileversion", "0.0.0.0")
EndIf
_Upgrade()
Global $asFavorites = _EnumValues("Favorite")
Global $asTwitchGames = _EnumValues("TwitchGames")
Opt("TrayMenuMode", 3)
Opt("TrayOnEventMode", 1)
Opt("GUIOnEventMode", 1)
TrayCreateItem("")
TrayCreateItem("Refresh")
TrayItemSetOnEvent(-1, _MAIN)
TrayCreateItem("Play from clipboard")
TrayItemSetOnEvent(-1, _GuiShow)
TrayCreateItem("")
TrayCreateItem("Settings")
TrayItemSetOnEvent(-1, _SettingsShow)
TrayCreateItem("Send feedback")
TrayItemSetOnEvent(-1, _FeedbackShow)
TrayCreateItem("About")
TrayItemSetOnEvent(-1, _About)
TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, _Exit)
Global Enum $eDisplayName, $eUrl, $ePreview, $eGame, $eCreated, $eTrayId, $eStatus, $eTime, $eOnline, $eService, $eQualities, $eFlags, $eUserID, $eGameID, $eChannelID, $eTimer, $eStreamID, $eOldStreamID, $eViewers, $eName, $eMax
Global Enum $eTwitch, $eSmashcast, $eYoutube
Global Enum Step *2 $eIsLink, $eIsText, $eIsStream
Global $sNew
Global $aStreams[0][$eMax]
Global $bBlobFirstRun = True
Global $sChanged
Global Const $AUT_WM_NOTIFYICON = $WM_USER + 1 ; Application.h
Global Const $AUT_NOTIFY_ICON_ID = 1 ; Application.h
Global Const $PBT_APMRESUMEAUTOMATIC = 0x12
AutoItWinSetTitle("AutoIt window with hopefully a unique title|Ketchup the second")
Global $TRAY_ICON_GUI = WinGetHandle(AutoItWinGetTitle()) ; Internal AutoIt GUI
Global $avDownloads[1][2]
Global $hGuiClipboard, $hGuiFeedback, $hGuiIEUI
Global $idLabel, $idQuality, $idUrl
_GuiCreate()
_FeedbackCreate()
Global $hGuiSettings
Global $idRefreshMinutes, $idIgnoreMinutes, $idUpdates, $idStartup, $idStartupTooltip, $idStartupLegacy, $idLog, $idLogDelete, $idTwitchId, $idTwitchName, $idTwitchGamesName, $idTwitchGamesID, $idTwitchGamesAdd, $idTwitchGamesList, $idTwitchGamesMax, $idSmashcastInput, $idSmashcastId, $idSmashcastName, $idYoutubeInput, $idYoutubeId, $idYoutubeName, $idNewUI, $idNewUIMultipleThumbnails, $idStreamlinkEnabled, $idStreamlinkPath, $idStreamlinkPathCheck, $idStreamlinkQuality, $idStreamlinkCommandLine
_SettingsCreate()
_GDIPlus_Startup()
Global $hBitmap, $hImage, $hGraphic
$hBitmap = _WinAPI_CreateSolidBitmap(0, 0xFFFFFF, 16, 16)
$hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)
$hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage)
; https://www.autoitscript.com/forum/topic/199786-making-your-compiled-application-dpi-aware/
Global Const $DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED = -5
If @OSVersion = 'WIN_10' Then DllCall("User32.dll", "bool", "SetProcessDpiAwarenessContext" , "HWND", $DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED)
If @Compiled = 1 Then
_WinAPI_RegisterApplicationRestart($RESTART_NO_REBOOT)
EndIf
Global $aoEvents[0]
If $sNewUI = 1 Then
TraySetClick($TRAY_CLICK_SECONDARYDOWN)
TraySetOnEvent($TRAY_EVENT_PRIMARYUP, _IEUI)
EndIf
If FileExists(@LocalAppDataDir & "\StreamHelper\arraydebug") Then
HotKeySet("{PAUSE}", _ArrayDebug)
EndIf
_MAIN()
While 1
Sleep(3600000)
WEnd
#Region TWITCH
Func _TwitchNew()
_CW("Twitching")
_ProgressSpecific("T")
_TwitchGet()
_TwitchGetGames()
_TwitchProcessUserID()
_TwitchProcessGameID()
$iTrayRefresh = True
EndFunc
Func _TwitchGet()
$sCursor = ""
While True
$sUrl = "users/follows?from_id=" & $sTwitchId & "&first=100&after=" & $sCursor
$oJSON = _TwitchFetch($sUrl)
If IsObj($oJSON) = False Then Return
$aData = Json_ObjGet($oJSON, "data")
If UBound($aData) = 0 Then ExitLoop
$oPagination = Json_ObjGet($oJSON, "pagination")
$sCursor = Json_ObjGet($oPagination, "cursor")
Local $sUsers = ""
For $iX = 0 To UBound($aData) -1
$sUser = Json_ObjGet($aData[$iX], "to_id")
$sUsers &= "&user_id=" & $sUser
Next
$sUsers = StringTrimLeft($sUsers, 1)
$sUrl = "streams?" & $sUsers & "&first=100"
$oJSON = _TwitchFetch($sUrl)
If IsObj($oJSON) = False Then Return
$aData2 = Json_ObjGet($oJSON, "data")
If UBound($aData2) = 0 Then
If UBound($aData) <> 100 Then Return "Potato on a Stick"
ContinueLoop
EndIf
$sNow = _NowCalc()
For $iX = 0 To UBound($aData2) -1
$sStreamID = Json_ObjGet($aData2[$iX], "id")
$sUserID = "T" & Json_ObjGet($aData2[$iX], "user_id")
$sGameID = Json_ObjGet($aData2[$iX], "game_id")
$sTime = Json_ObjGet($aData2[$iX], "started_at")
$sTitle = Json_ObjGet($aData2[$iX], "title")
$sThumbnail = Json_ObjGet($aData2[$iX], "thumbnail_url")
$sViewerCount = Json_ObjGet($aData2[$iX], "viewer_count")
Local $aDate, $aTime
_DateTimeSplit($sTime, $aDate, $aTime)
Local $tSystem = _Date_Time_EncodeSystemTime($aDate[2], $aDate[3], $aDate[1], $aTime[1], $aTime[2], $aTime[3])
$tLocal = _Date_Time_SystemTimeToTzSpecificLocalTime($tSystem)
$sTimeConverted = _Date_Time_SystemTimeToDateTimeStr($tLocal, 1)
$sTimeDiffHour = _DateDiff("h", $sTimeConverted, $sNow)
$sTimeAdded = _DateAdd("h", $sTimeDiffHour, $sTimeConverted)
$sTimeDiffMin = _DateDiff("n", $sTimeAdded, $sNow)
$sTime2 = StringFormat("%02s:%02s", $sTimeDiffHour, $sTimeDiffMin)
_StreamSet("", "", $sThumbnail, "", "", $sTime2, $sTitle, $eTwitch, $sUserID, $sStreamID, Default, $sGameID, $sViewerCount)
Next
If UBound($aData) <> 100 Then Return "Potato on a Stick"
WEnd
Return "Potato on a Stick"
EndFunc
Func _TwitchGetGames()
If $asTwitchGames = "" Then Return
$asGameIDs = StringSplit(StringStripWS($asTwitchGames, $STR_STRIPTRAILING), @LF)
Local $sGames = ""
For $iX = 1 To $asGameIDs[0]
$sGames &= "&game_id=" & $asGameIDs[$iX]
Next
$sGames = StringTrimLeft($sGames, 1)
$sUrl = "streams?" & $sGames & "&first=" & $sTwitchGamesMax
$oJSON = _TwitchFetch($sUrl)
If IsObj($oJSON) = False Then Return
$aData = Json_ObjGet($oJSON, "data")
If UBound($aData) = 0 Then Return
$sNow = _NowCalc()
For $iX = 0 To UBound($aData) -1
$sGameID = Json_ObjGet($aData[$iX], "game_id")
$sStreamID = Json_ObjGet($aData[$iX], "id")
$sTime = Json_ObjGet($aData[$iX], "started_at")
$sTitle = Json_ObjGet($aData[$iX], "title")
$sUserID = "T" & Json_ObjGet($aData[$iX], "user_id")
$sThumbnail = Json_ObjGet($aData[$iX], "thumbnail_url")
$sViewerCount = Json_ObjGet($aData[$iX], "viewer_count")
Local $aDate, $aTime
_DateTimeSplit($sTime, $aDate, $aTime)
Local $tSystem = _Date_Time_EncodeSystemTime($aDate[2], $aDate[3], $aDate[1], $aTime[1], $aTime[2], $aTime[3])
$tLocal = _Date_Time_SystemTimeToTzSpecificLocalTime($tSystem)
$sTimeConverted = _Date_Time_SystemTimeToDateTimeStr($tLocal, 1)
$sTimeDiffHour = _DateDiff("h", $sTimeConverted, $sNow)
$sTimeAdded = _DateAdd("h", $sTimeDiffHour, $sTimeConverted)
$sTimeDiffMin = _DateDiff("n", $sTimeAdded, $sNow)
$sTime2 = StringFormat("%02s:%02s", $sTimeDiffHour, $sTimeDiffMin)
_StreamSet("", "", $sThumbnail, "", "", $sTime2, $sTitle, $eTwitch, $sUserID, $sStreamID, Default, $sGameID, $sViewerCount)
Next
EndFunc
Func _TwitchProcessUserID()
Local $sUsers = "", $iCount = 0
For $iX = 0 To UBound($aStreams) -1
If $aStreams[$iX][$eService] <> $eTwitch Then ContinueLoop
If $aStreams[$iX][$eDisplayName] <> "" And $aStreams[$iX][$eUrl] <> "" Then ContinueLoop
If $aStreams[$iX][$eOnline] <> True Then ContinueLoop
$sUsers &= "&id=" & StringTrimLeft($aStreams[$iX][$eUserID], 1)
$iCount += 1
If $iCount = 100 Then ExitLoop
Next
$sUsers = StringTrimLeft($sUsers, 1)
If $iCount = 0 Then Return
$sUrl = "users?" & $sUsers
$oJSON = _TwitchFetch($sUrl)
If IsObj($oJSON) = False Then Return
$aData = Json_ObjGet($oJSON, "data")
If UBound($aData) = 0 Then Return
For $iX = 0 To UBound($aData) -1
Local $sName = ""
$sDisplayName = Json_ObjGet($aData[$iX], "display_name")
$sLogin = Json_ObjGet($aData[$iX], "login")
$sID = Json_ObjGet($aData[$iX], "id")
If StringIsASCII($sDisplayName) = 0 Then
$sName = $sDisplayName
$sDisplayName = $sLogin
EndIf
$sUrl = "https://www.twitch.tv/" & $sLogin
For $iIndex = 0 To UBound($aStreams) -1
If $aStreams[$iIndex][$eUserID] = "T" & $sID Then
$aStreams[$iIndex][$eDisplayName] = $sDisplayName
$aStreams[$iIndex][$eUrl] = $sUrl
If $sName <> "" Then
$aStreams[$iIndex][$eName] = $sName
EndIf
ExitLoop
EndIf
Next
Next
EndFunc
Func _TwitchProcessGameID()
Local $sGames = "", $iCount = 0
For $iX = 0 To UBound($aStreams) -1
If $aStreams[$iX][$eService] <> $eTwitch Then ContinueLoop
If $aStreams[$iX][$eGame] <> "" Then ContinueLoop
If $aStreams[$iX][$eOnline] <> True Then ContinueLoop
If $aStreams[$iX][$eGameID] == "0" Or $aStreams[$iX][$eGameID] == "" Then
$oJSON = _WinHttpFetch("api.twitch.tv", "kraken/channels/" & StringTrimLeft($aStreams[$iX][$eUserID], 1), "Accept: application/vnd.twitchtv.v5+json" & @CRLF & "Client-ID: " & $sTwitchClientID & @CRLF & "Authorization: OAuth " & $sTwitchToken)
If IsObj($oJSON) = False Then Return
$sGame = Json_ObjGet($oJSON, "game")
$aStreams[$iX][$eGame] = $sGame
ContinueLoop
EndIf
If $aStreams[$iX][$eGameID] == "" Then
$aStreams[$iX][$eGame] = "No game selected"
ContinueLoop
EndIf
For $iIndex = 0 To UBound($aStreams) -1
If $aStreams[$iIndex][$eGameID] == $aStreams[$iX][$eGameID] And $aStreams[$iIndex][$eGame] <> "" Then
$aStreams[$iX][$eGame] = $aStreams[$iIndex][$eGame]
ContinueLoop 2
EndIf
Next
$sGames &= "&id=" & $aStreams[$iX][$eGameID]
$iCount += 1
If $iCount = 100 Then ExitLoop
Next
$sGames = StringTrimLeft($sGames, 1)
If $iCount = 0 Then Return
$sUrl = "games?" & $sGames
$oJSON = _TwitchFetch($sUrl)
If IsObj($oJSON) = False Then Return
$aData = Json_ObjGet($oJSON, "data")
If UBound($aData) = 0 Then Return
For $iX = 0 To UBound($aData) -1
$sGame = Json_ObjGet($aData[$iX], "name")
$sID = Json_ObjGet($aData[$iX], "id")
For $iIndex = 0 To UBound($aStreams) -1
If $aStreams[$iIndex][$eGameID] = $sID Then
$aStreams[$iIndex][$eGame] = $sGame
EndIf
Next
Next
EndFunc
;~ add &api_version=5 ??
Func _TwitchFetch($sUrl)
Return _WinHttpFetch("api.twitch.tv", "helix/" & $sUrl, "Client-ID: " & $sTwitchClientID & @CRLF & "Authorization: Bearer " & $sTwitchToken)
EndFunc
#EndRegion TWITCH
#Region SMASHCAST
Func _Smashcast()
_CW("Smashcasting")
_ProgressSpecific("S")
_SmashcastGet()
$iTrayRefresh = True
EndFunc
Func _SmashcastGet()
$iOffset = 0
While 1
Local $sUrl = "media/live/list?follower_id=" & $sSmashcastId & "&start=" & $iOffset
$oJSON = _SmashcastFetch($sUrl)
If IsObj($oJSON) = False Then Return
$oLivestream = Json_ObjGet($oJSON, "livestream")
If UBound($oLivestream) = 0 Then Return
For $iX = 0 To UBound($oLivestream) -1
$oChannel = Json_ObjGet($oLivestream[$iX], "channel")
$sUrl = Json_ObjGet($oChannel, "channel_link")
$sUserID = "S" & Json_ObjGet($oChannel, "user_id")
$sDisplayName = Json_ObjGet($oLivestream[$iX], "media_display_name")
$sStatus = Json_ObjGet($oLivestream[$iX], "media_status")
;The documentation still says to use the hitbox domain for images
$sThumbnail = "http://edge.sf.hitbox.tv" & Json_ObjGet($oLivestream[$iX], "media_thumbnail")
$sGame = Json_ObjGet($oLivestream[$iX], "category_name")
$sStreamID = Json_ObjGet($oLivestream[$iX], "media_id")
$sCreated = Json_ObjGet($oLivestream[$iX], "media_live_since")
$asSplit = StringSplit($sCreated, " ")
$asDate = StringSplit($asSplit[1], "-")
$asTime = StringSplit($asSplit[2], ":")
$tSystemTime = DllStructCreate($tagSYSTEMTIME)
$tSystemTime.Year = $asDate[1]
$tSystemTime.Month = $asDate[2]
$tSystemTime.Day = $asDate[3]
$tSystemTime.Hour = $asTime[1]
$tSystemTime.Minute = $asTime[2]
$tSystemTime.Second = $asTime[3]
$tFileTime = _Date_Time_SystemTimeToFileTime($tSystemTime)
$tLocalTime = _Date_Time_FileTimeToLocalFileTime($tFileTime)
$sTime = _Date_Time_FileTimeToStr($tLocalTime, 1)
$iHours = _DateDiff("h", $sTime, _NowCalc())
$iMinutes = _DateDiff("n", $sTime, _NowCalc())
$iMinutes -= $iHours * 60
$sTime = StringFormat("%02i:%02i", $iHours, $iMinutes)
_StreamSet($sDisplayName, $sUrl, $sThumbnail, $sGame, $sCreated, $sTime, $sStatus, $eSmashcast, $sUserID, $sStreamID)
Next
If UBound($oLivestream) <> 100 Then Return "Potato on a Stick"
$iOffset += 100
WEnd
Return "Potato on a Stick"
EndFunc
Func _SmashcastFetch($sUrl)
Return _WinHttpFetch("api.smashcast.tv", $sUrl)
EndFunc
#EndRegion
#Region YOUTUBE
Func _Youtube()
_CW("Youtubeing")
_ProgressSpecific("Y")
_YoutubeGet()
$iTrayRefresh = True
EndFunc
Func _YoutubeGet()
Local $sPageToken = ""
While 1
Local $sUrl = "subscriptions?part=snippet&channelId=" & $sYoutubeId & "&maxResults=50&pageToken=" & $sPageToken & "&fields=items%2Fsnippet%2FresourceId%2FchannelId%2CnextPageToken"
$oChannels = _YoutubeFetch($sUrl)
If IsObj($oChannels) = False Then Return
$aItems = Json_ObjGet($oChannels, "items")
If UBound($aItems) = 0 Then Return
$sPageToken = Json_ObjGet($oChannels, "nextPageToken")
For $iX = 0 To UBound($aItems) -1
$oSnippet = Json_ObjGet($aItems[$iX], "snippet")
$oResourceId = Json_ObjGet($oSnippet, "resourceId")
$sChannelId = Json_ObjGet($oResourceId, "channelId")
$sUserID = "Y" & $sChannelId
$sUrl = "search?part=snippet&channelId=" & $sChannelId & "&eventType=live&type=video&fields=items(id%2FvideoId%2Csnippet(channelTitle%2Ctitle))"
$oChannels = _YoutubeFetch($sUrl)
If IsObj($oChannels) = False Then ContinueLoop
$aItem = Json_ObjGet($oChannels, "items")
If UBound($aItem) = 0 Then ContinueLoop
$oID = Json_ObjGet($aItem[0], "id")
$sUrl = "https://www.youtube.com/watch?v=" & Json_ObjGet($oID, "videoId")
$oSnippet = Json_ObjGet($aItem[0], "snippet")
$sGame = Json_ObjGet($oSnippet, "title")
$sDisplayName = Json_ObjGet($oSnippet, "channelTitle")
_StreamSet($sDisplayName, $sUrl, "", $sGame, "", "", "", $eYoutube, $sUserID)
Next
If $sPageToken = "" Then ExitLoop
WEnd
Return "Potato on a Stick"
EndFunc
Func _YoutubeFetch($sUrl)
Static Local $vCache[0][2]
Local $vRet = _WinHttpFetch("www.googleapis.com", "youtube/v3/" & $sUrl & "&key={YOUR_API_KEY}", Default, 2)
Local $oJSON = $vRet[0]
Local $sHeader = $vRet[1]
Local $sETag = _StringBetween($sHeader, 'ETag: "', '"')
Local $vToCache[1][2] = [[$sETag[0], $oJSON]]
_ArrayAdd($vCache, $vToCache)
Return $oJSON
EndFunc
#EndRegion
#Region COMMON
Func _WinHttpFetch($sDomain, $sUrl, $sHeader = Default, $sReturnFormat = Default)
_CW("_WinHttpFetch: " & $sDomain & "/" & $sUrl & " \ " & StringReplace($sHeader, @CRLF, " \ "))
Local $iTries = 0, $asResponse
Do
Sleep($iTries * 6000)
Local $hOpen = _WinHttpOpen()
Local $hConnect = _WinHttpConnect($hOpen, $sDomain)
$asResponse = _WinHttpSimpleSSLRequest($hConnect, Default, $sUrl, Default, Default, $sHeader, True)
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)
$iTries += 1
Until (IsArray($asResponse) And (StringSplit($asResponse[0], " ")[2] = 200 Or StringSplit($asResponse[0], " ")[2] = 404)) Or $iTries = 6
If $asResponse = 0 Then
_CW("_WinHttpFetch failed")
Return
EndIf
_CW("Succeeded/failed after " & $iTries & " tries")
_CW(StringReplace(StringStripWS($asResponse[0], $STR_STRIPTRAILING), @CRLF, " \ "))
_CW($asResponse[1])
$oJSON = Json_Decode($asResponse[1])
If $sReturnFormat = Default Then
Return $oJSON
Else
Local $vRet[2] = [$oJSON, $asResponse[0]]
Return $vRet
EndIf
EndFunc
;From https://www.autoitscript.com/forum/topic/95850-url-encoding/?do=findComment&comment=689045
Func URLEncode($urlText)
$url = ""
For $i = 1 To StringLen($urlText)
$acode = Asc(StringMid($urlText, $i, 1))
Select
Case ($acode >= 48 And $acode <= 57) Or _
($acode >= 65 And $acode <= 90) Or _
($acode >= 97 And $acode <= 122)
$url = $url & StringMid($urlText, $i, 1)
Case $acode = 32
$url = $url & "+"
Case Else
$url = $url & "%" & Hex($acode, 2)
EndSelect
Next
Return $url
EndFunc ;==>URLEncode
#EndRegion
#Region GUI
Func _TrayRefresh()
Static Local $iRandomStreams = FileExists(@LocalAppDataDir & "\StreamHelper\randomstreams")
_ArraySort($aStreams, 1)
For $iX = 0 To UBound($aStreams) -1
If $iRandomStreams Then
If Random(0, 1, 1) Then
$aStreams[$iX][$eOnline] = False
EndIf
EndIf
If $aStreams[$iX][$eOnline] = True Then
Local $sDisplayName = $aStreams[$iX][$eDisplayName]
If BitAND($aStreams[$iX][$eFlags], $eIsStream) Then
If StringInStr($asFavorites, $aStreams[$iX][$eUserID] & @LF, $STR_CASESENSE) Then $sDisplayName = $sDisplayName & " | F"
EndIf
Local $sTrayText = $sDisplayName
If $aStreams[$iX][$eGame] <> "" Then $sTrayText &= " | " & $aStreams[$iX][$eGame]
$sTrayText = StringReplace($sTrayText, "&", "&&")
$aStreams[$iX][$eOnline] = False
If $aStreams[$iX][$eTrayId] = 0 Then
$aStreams[$iX][$eTrayId] = TrayCreateItem($sTrayText, -1, 0)
If $aStreams[$iX][$eFlags] = $eIsStream Then
Local $NewText = $aStreams[$iX][$eDisplayName]
If $bBlobFirstRun <> True Then $NewText &= " - " & $aStreams[$iX][$eGame] & "@CRLF" & $aStreams[$iX][$eStatus]
If $aStreams[$iX][$eStreamID] = 404 Or $aStreams[$iX][$eStreamID] <> $aStreams[$iX][$eOldStreamID] Then
$aStreams[$iX][$eOldStreamID] = $aStreams[$iX][$eStreamID]
If StringInStr($sDisplayName, " | F", $STR_CASESENSE) And ($sIgnoreMinutes = 0 Or TimerDiff($aStreams[$iX][$eTimer]) * 1000 * 60 > $sIgnoreMinutes) Then
$aStreams[$iX][$eTimer] = TimerInit()
$sNew &= $NewText & @CRLF
EndIf
EndIf
EndIf
TrayItemSetOnEvent( -1, _TrayStuff)
Else
If $sTrayText = TrayItemGetText($aStreams[$iX][$eTrayId]) Then ContinueLoop
TrayItemSetText($aStreams[$iX][$eTrayId], $sTrayText)
If StringInStr($sDisplayName, " | F", $STR_CASESENSE) Then
Local $NewText = $aStreams[$iX][$eDisplayName] & " - " & $aStreams[$iX][$eGame] & " - " & $aStreams[$iX][$eTime] & "@CRLF" & $aStreams[$iX][$eStatus]
$sChanged &= $NewText & @CRLF
EndIf
EndIf
Else
If $aStreams[$iX][$eTrayId] <> 0 And BitAND($aStreams[$iX][$eFlags], $eIsStream) = $eIsStream Then
TrayItemDelete($aStreams[$iX][$eTrayId])
$aStreams[$iX][$eTrayId] = 0
$aStreams[$iX][$eTime] = ""
EndIf
EndIf
Next
EndFunc
Func _TrayStuff()
For $iX = 0 To UBound($aStreams) -1
If $aStreams[$iX][$eTrayId] = @TRAY_ID Then
ExitLoop
EndIf
Next
If BitAND($aStreams[$iX][$eFlags], $eIsLink) = $eIsLink Then
ShellExecute($aStreams[$iX][$eUrl])
ElseIf BitAND($aStreams[$iX][$eFlags], $eIsText) = $eIsText Then
Return
ElseIf BitAND($aStreams[$iX][$eFlags], $eIsStream) = $eIsStream Then
If _IsPressed("10") Then
Local $asStream[] = [$aStreams[$iX][$eUrl], $aStreams[$iX][$eDisplayName]]
_ClipboardGo($asStream)
ElseIf _IsPressed("11") Then
$sUserID = $aStreams[$iX][$eUserID]
If StringInStr($asFavorites, $sUserID, $STR_CASESENSE) Then ; if fav then remove it from fav
$asFavorites = StringReplace($asFavorites, $sUserID & @LF, "")
RegDelete("HKCU\SOFTWARE\StreamHelper\Favorite\", $sUserID)
Else ; if nothing then fav
$asFavorites &= $sUserID & @LF
RegWrite("HKCU\SOFTWARE\StreamHelper\Favorite\", $sUserID, "REG_SZ", "")
EndIf
Local $sDisplayName = $aStreams[$iX][$eDisplayName]
If StringInStr($asFavorites, $aStreams[$iX][$eUserID] & @LF, $STR_CASESENSE) Then $sDisplayName = $sDisplayName & " | F"
;Shouldn't this also have an if not game then skip game display?
;Future me: Yes. Yes it should.
Local $NewText = $sDisplayName
If $aStreams[$iX][$eGame] <> "" Then $NewText &= " | " & $aStreams[$iX][$eGame]
TrayItemSetText($aStreams[$iX][$eTrayId], $NewText)
ElseIf $sStreamlinkEnabled = "1" Then
_StreamlinkPlay($aStreams[$iX][$eUrl])
Else
ShellExecute($aStreams[$iX][$eUrl])
EndIf
EndIf
EndFunc
Func _StreamlinkPlay($sUrl, $sQuality = "")
Static Local $iPID = 0
;_GuiPlay can send empty $sQuality so conversion has to be done
If $sQuality = "" Then $sQuality = $sStreamlinkQuality
If $iClosePreviousBeforePlaying Then
If _WinAPI_GetProcessName($iPID) = "streamlink.exe" Then
RunWait("taskkill.exe /PID " & $iPID & " /T", "", @SW_HIDE)
ProcessWaitClose($iPID, 1000)
EndIf
EndIf
Local $sProgram = "streamlink.exe"
If $sStreamlinkPath Then
$sProgram = '"' & $sStreamlinkPath & '"'
EndIf
$sProgram &= " " & $sStreamlinkCommandLine
$sProgram &= " --twitch-disable-hosting"
$sProgram &= " " & $sUrl
$sProgram &= " " & $sQuality
$iPID = Run($sProgram, "", @SW_HIDE)
EndFunc
;Based on https://www.autoitscript.com/forum/topic/115222-set-the-tray-icon-as-a-hicon/
Func _TraySet($sText)
_GDIPlus_GraphicsClear($hGraphic, 0xFFFFFFFF)
$hFamily = _GDIPlus_FontFamilyCreate('Arial')
$hFont = _GDIPlus_FontCreate($hFamily, 9, 1, 2)
$tLayout = _GDIPlus_RectFCreate(0, 0, 0, 0)
$hFormat = _GDIPlus_StringFormatCreate()
$hBrush = _GDIPlus_BrushCreateSolid(0xFF000000)
$aData = _GDIPlus_GraphicsMeasureString($hGraphic, $sText, $hFont, $tLayout, $hFormat)
$tLayout = $aData[0]
DllStructSetData($tLayout, 1, (_GDIPlus_ImageGetWidth($hImage) - DllStructGetData($tLayout, 3)) / 2)
DllStructSetData($tLayout, 2, (_GDIPlus_ImageGetHeight($hImage) - DllStructGetData($tLayout, 4)) / 2)
_GDIPlus_GraphicsDrawStringEx($hGraphic, $sText, $hFont, $aData[0], $hFormat, $hBrush)
_GDIPlus_StringFormatDispose($hFormat)
_GDIPlus_FontFamilyDispose($hFamily)
_GDIPlus_FontDispose($hFont)
_GDIPlus_BrushDispose($hBrush)
$hIcon = _GDIPlus_HICONCreateFromBitmap($hImage)
Local $tNOTIFY = DllStructCreate($tagNOTIFYICONDATA)
$tNOTIFY.Size = DllStructGetSize($tNOTIFY)
$tNOTIFY.hWnd = $TRAY_ICON_GUI
$tNOTIFY.ID = $AUT_NOTIFY_ICON_ID
$tNOTIFY.hIcon = $hIcon
$tNOTIFY.Flags = BitOR($NIF_ICON, $NIF_MESSAGE)
$tNOTIFY.CallbackMessage = $AUT_WM_NOTIFYICON
_WinAPI_ShellNotifyIcon($NIM_MODIFY, $tNOTIFY)
_WinAPI_DestroyIcon($hIcon)
EndFunc
Func _ProgressSpecific($sText)
_TraySet($sText)
EndFunc
Func _MAIN()
AdlibUnRegister(_MAIN)
Global $sNew = "", $sChanged = ""
_CheckUpdates()
If $sTwitchId <> "" Then _TwitchNew()
If $iSmashcastEnable And $sSmashcastId <> "" Then _Smashcast()
If $iYoutubeEnable And $sYoutubeId <> "" Then _Youtube()
_CW("Getters done")
_TrayRefresh()
_IEUIRefresh()
;https://www.autoitscript.com/forum/topic/146955-solved-remove-crlf-at-the-end-of-text-file/?do=findComment&comment=1041088
If StringRight($sNew, 2) = @CRLF Then $sNew = StringTrimRight($sNew, 2)
If StringRight($sChanged, 2) = @CRLF Then $sChanged = StringTrimRight($sChanged, 2)
If (Not @Compiled) Then
TraySetIcon(@ScriptDir & "\Svartnos.ico", -1)
Else
TraySetIcon()
EndIf
_CW("New streamer: " & StringReplace(StringReplace($sNew, "@CRLF", " - "), @CRLF, ", "))
_CW("Streamer changed game: " & StringReplace(StringReplace($sChanged, "@CRLF", " - "), @CRLF, ", "))
If $sChanged <> "" Then
If @OSBuild >= 10240 Then
_TrayTipThis8($sChanged, "Changed game")
Else
$iSkipped = 0
While StringLen($sChanged) > 240
$iPos = StringInStr($sChanged, @CRLF, $STR_CASESENSE, -1)
$sChanged = StringLeft($sChanged, $iPos -1)
$iSkipped += 1
WEnd
If $iSkipped > 0 Then
$sChanged &= @CRLF & "+" & $iSkipped & " more"
EndIf
TrayTip("Changed game", $sChanged, 10)
EndIf
EndIf
If $sNew <> "" Then
If $bBlobFirstRun = True Then
$bBlobFirstRun = False
Local $sReplaced = StringReplace($sNew, @CRLF, ", ")
Local $iReplacedLength = StringLen($sReplaced)
;Win 10 November Update seems to have a 140 character limit when just a block of text, but here spaces and things screw that up.
;I'm guessing 120 is low enough to cover most situations.
$sReplaced = StringLeft($sReplaced, 120)
If StringLen($sReplaced) <> $iReplacedLength Then $sReplaced &= "..."
TrayTip("Currently streaming", $sReplaced, 10)
ElseIf @OSBuild >= 10240 Then
_TrayTipThis8($sNew, "Now streaming")
Else
$iSkipped = 0
While StringLen($sNew) > 240
$iPos = StringInStr($sNew, @CRLF, $STR_CASESENSE, -1)
$sNew = StringLeft($sNew, $iPos -1)
$iSkipped += 1
WEnd
If $iSkipped > 0 Then
$sNew &= @CRLF & "+" & $iSkipped & " more"
EndIf
TrayTip("Now streaming", $sNew, 10)
EndIf
EndIf
AdlibRegister(_MAIN, $sRefreshMinutes * 60000)
EndFunc
;Sort every array by length to move overrun to the end? What if there is multiple long lines?
;https://www.autoitscript.com/forum/topic/177643-how-to-sort-a-array-by-string-length/
Func _TrayTipThis($sPeople, $sDesc, $iLines)
$asSplit = StringSplit($sPeople, @CRLF, $STR_ENTIRESPLIT + $STR_NOCOUNT)
While True
Local $asText[0]
For $iX = 1 To $iLines
$sPopped = _ArrayPop($asSplit)
If @error Then
TrayTip($sDesc, _ArrayToString($asText, @CRLF), 10)
Return
Else
_ArrayAdd($asText, $sPopped, Default, Default, Default, $ARRAYFILL_FORCE_SINGLEITEM)
EndIf
Next
TrayTip($sDesc, _ArrayToString($asText, @CRLF), 10)
WEnd
EndFunc
Func _TrayTipThis2($sPeople, $sDesc, $iLines)
While True
$iLocation = StringInStr($sPeople, @CRLF, $STR_NOCASESENSEBASIC, $iLines)
If $iLocation = 0 Then
TrayTip($sDesc, $sPeople, 10)
ExitLoop
Else