forked from DjShinter/VideoRemote
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathVideoRemote.cs
More file actions
1576 lines (1448 loc) · 84.6 KB
/
VideoRemote.cs
File metadata and controls
1576 lines (1448 loc) · 84.6 KB
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
using ABI_RC.VideoPlayer.Scripts;
using BTKUILib;
using MelonLoader;
using UnityEngine;
using UnityEngine.SceneManagement;
using System.Reflection;
using BTKUILib.UIObjects;
using BTKUILib.UIObjects.Components;
using System.Collections.Generic;
using System.Collections.Concurrent;
using System.IO;
using System;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using Semver;
using ABI.CCK.Components;
using ABI_RC.Core.InteractionSystem;
using HarmonyLib;
using System.Net;
using System.Threading.Tasks;
using Newtonsoft.Json;
using ABI_RC.Core.UI;
using ABI_RC.VideoPlayer;
using ABI_RC.Core.Networking;
using ABI_RC.Core.Savior;
using System.Diagnostics;
namespace VideoRemote
{
public static class ModBuildInfo
{
public const string Name = "Video Remote";
public const string Author = "Shin, Nirvash";
public const string Version = "1.7.15";
public const string Description = "This allows you to use the video player with the menu.";
public const string DownloadLink = "https://github.com/Nirv-git/VideoRemote/releases";
}
public class VideoRemoteMod : MelonMod
{
public static VideoRemoteMod Instance;
public static MelonPreferences_Category cat;
private const string catagory = "VideoRemoteMod";
public static MelonPreferences_Entry<bool> sponsorSkip_sponsor;
public static MelonPreferences_Entry<bool> sponsorSkip_selfpromo;
public static MelonPreferences_Entry<bool> sponsorSkip_interaction;
public static MelonPreferences_Entry<bool> sponsorSkip_intro;
public static MelonPreferences_Entry<bool> videoHistory_En;
private static Category VideoPlayerListMain, VideoPlayerList, AdvancedOptions, videoName;
private static Page AdvOptionsPage, TimeStampPage, LogPage, DebugPage, SponsorSkipEvents, savedURLsPage, URLHistoryPage;
private static SliderFloat volumeSilder;
private static string VideoFolderString, MainPageString, SponsorSkipEventsString, AdvOptionsString, TimeStampPageString, LogPageString, DebugPageString, savedURLsPageString, URLHistoryPageString;
private static string lastQMPage = "";
public static bool _initalized = new();
private static ViewManagerVideoPlayer VideoPlayerSelected = new();
private const string FolderRoot = "UserData/VideoRemote/";
private const string savedURLsFileName = "savedURLsList.txt";
private const string histroyURLFileName = "historyURLsList.txt";
public static Dictionary<string, (string, DateTime)> savedURLs = new Dictionary<string, (string, DateTime)>(); //URL,(Name,Date)
public static List<(string, string, DateTime)> historyURLs = new List<(string, string, DateTime)>(); //URL,(Name,Date)
private static GameObject localScreen;
private static bool pickupable = false;
private static float sizeScale = 1;
private static bool sponsorSkip = false;
private static object sponsorSkipCheckCoroutine, sponsorSkipLiveCoroutine;
private static string lastvideo = "zzzzzzzzzzzzzzzzzzzzz09";
private static string sponsorskipVideo = "xxxxxxxxxxxxxxxxxxxx08";
private static SponsorSkipSegment[] sponsorskipResult;
private static List<(string, float[])> sponsorskips = new List<(string, float[])>();
private static float[] lastskip = new float[2];
private static bool TryingToReplay = false;
private static int timeStampHour = 0;
private static int timeStampMin = 0;
private static int timeStampSec = 0;
private static float historyLastCheck = 0;
//public static float worldLastJoin = 0;
//public static bool vidPlayerJoinCoroutine_Run;
//public static List<string> vidJoinBuffer_toRemove = new List<string>();
//public static ConcurrentDictionary<string, (string, bool, string, string, float)> vidPlayerJoinBuffer = new ConcurrentDictionary<string, (string, bool, string, string, float)>(); //ID,(1-URL,2-Paused,3-PlayerName,4-ObjPath,8-Date)
public override void OnInitializeMelon()
{
Instance = this;
cat = MelonPreferences.CreateCategory(catagory, "Video Remote", true);
sponsorSkip_sponsor = MelonPreferences.CreateEntry(catagory, nameof(sponsorSkip_sponsor), true, "Skips Segment Sponsor");
sponsorSkip_selfpromo = MelonPreferences.CreateEntry(catagory, nameof(sponsorSkip_selfpromo), false, "Skips Segment selfpromo");
sponsorSkip_interaction = MelonPreferences.CreateEntry(catagory, nameof(sponsorSkip_interaction), false, "Skips Segment interaction");
sponsorSkip_intro = MelonPreferences.CreateEntry(catagory, nameof(sponsorSkip_intro), false, "Skips Segment intro");
videoHistory_En = MelonPreferences.CreateEntry(catagory, nameof(videoHistory_En), false, "Record history of played URLs for all Video Players. Checks every time a video is Played");
if (!RegisteredMelons.Any(x => x.Info.Name.Equals("BTKUILib") && x.Info.SemanticVersion != null && x.Info.SemanticVersion.CompareTo(new SemVersion(1)) >= 0))
{
MelonLogger.Error("BTKUILib was not detected or it is outdated! VideoRemote cannot function without it!");
MelonLogger.Error("Please download an updated copy for BTKUILib!");
return;
}
_initalized = false;
VideoPlayerSelected = null;
if (!Directory.Exists(FolderRoot))
{
Directory.CreateDirectory(FolderRoot);
}
LoadURLs();
}
public override void OnSceneWasInitialized(int buildIndex, string sceneName)
{
if (SceneManager.GetActiveScene().name == "Init")
{
if (!_initalized)
{
_initalized = true;
SetupIcons();
//HarmonyInstance.Patch(typeof(CVR_MenuManager).GetMethod(nameof(CVR_MenuManager.ToggleQuickMenu)), null, new HarmonyMethod(typeof(VideoRemoteMod).GetMethod(nameof(QMtoggle), BindingFlags.NonPublic | BindingFlags.Static)));
}
}
VideoPlayerSelected = null;
//vidPlayerJoinBuffer.Clear();
//worldLastJoin = Time.time;
//MelonLogger.Msg("OnSceneWasInitialized");
}
private void SetupIcons()
{
QuickMenuAPI.PrepareIcon("VideoRemoteMod", "VideoPlayerModLogo", Assembly.GetExecutingAssembly().GetManifestResourceStream("VideoRemote.UI.Images.VideoPlayerModLogo.png"));
QuickMenuAPI.PrepareIcon("VideoRemoteMod", "VideoPlayerModPlay2", Assembly.GetExecutingAssembly().GetManifestResourceStream("VideoRemote.UI.Images.Play.png"));
QuickMenuAPI.PrepareIcon("VideoRemoteMod", "VideoPlayerModPause2", Assembly.GetExecutingAssembly().GetManifestResourceStream("VideoRemote.UI.Images.Pause.png"));
QuickMenuAPI.PrepareIcon("VideoRemoteMod", "VideoPlayerModNewScreen", Assembly.GetExecutingAssembly().GetManifestResourceStream("VideoRemote.UI.Images.NewScreen.png"));
QuickMenuAPI.PrepareIcon("VideoRemoteMod", "VideoPlayerModWhite-Minus", Assembly.GetExecutingAssembly().GetManifestResourceStream("VideoRemote.UI.Images.White-Minus.png"));
QuickMenuAPI.PrepareIcon("VideoRemoteMod", "VideoPlayerModWhite-Plus", Assembly.GetExecutingAssembly().GetManifestResourceStream("VideoRemote.UI.Images.White-Plus.png"));
QuickMenuAPI.PrepareIcon("VideoRemoteMod", "VideoPlayerModSound", Assembly.GetExecutingAssembly().GetManifestResourceStream("VideoRemote.UI.Images.Sound.png"));
QuickMenuAPI.PrepareIcon("VideoRemoteMod", "VideoPlayerModKeys", Assembly.GetExecutingAssembly().GetManifestResourceStream("VideoRemote.UI.Images.Keys.png"));
QuickMenuAPI.PrepareIcon("VideoRemoteMod", "VideoPlayerModVideoPlayer", Assembly.GetExecutingAssembly().GetManifestResourceStream("VideoRemote.UI.Images.VideoPlayer.png"));
QuickMenuAPI.PrepareIcon("VideoRemoteMod", "VideoPlayerModVideoPlayer-World", Assembly.GetExecutingAssembly().GetManifestResourceStream("VideoRemote.UI.Images.VideoPlayer-World.png"));
QuickMenuAPI.PrepareIcon("VideoRemoteMod", "VideoPlayerModVideoPlayer-Prop", Assembly.GetExecutingAssembly().GetManifestResourceStream("VideoRemote.UI.Images.VideoPlayer-Prop.png"));
QuickMenuAPI.PrepareIcon("VideoRemoteMod", "VideoPlayerModPastePlay", Assembly.GetExecutingAssembly().GetManifestResourceStream("VideoRemote.UI.Images.PastePlay.png"));
QuickMenuAPI.PrepareIcon("VideoRemoteMod", "VideoPlayerModSave", Assembly.GetExecutingAssembly().GetManifestResourceStream("VideoRemote.UI.Images.Save.png"));
QuickMenuAPI.PrepareIcon("VideoRemoteMod", "VideoPlayerModSponsorSkip", Assembly.GetExecutingAssembly().GetManifestResourceStream("VideoRemote.UI.Images.SponsorSkip.png"));
QuickMenuAPI.PrepareIcon("VideoRemoteMod", "VideoPlayerModArrow-Left", Assembly.GetExecutingAssembly().GetManifestResourceStream("VideoRemote.UI.Images.Arrow-Left.png"));
QuickMenuAPI.PrepareIcon("VideoRemoteMod", "VideoPlayerModArrow-Right", Assembly.GetExecutingAssembly().GetManifestResourceStream("VideoRemote.UI.Images.Arrow-Right.png"));
QuickMenuAPI.PrepareIcon("VideoRemoteMod", "VideoPlayerModAdvSettings2", Assembly.GetExecutingAssembly().GetManifestResourceStream("VideoRemote.UI.Images.AdvSettings.png"));
QuickMenuAPI.PrepareIcon("VideoRemoteMod", "VideoPlayerModReloadVideo", Assembly.GetExecutingAssembly().GetManifestResourceStream("VideoRemote.UI.Images.ReloadVideo.png"));
QuickMenuAPI.PrepareIcon("VideoRemoteMod", "VideoPlayerModLoadURLs", Assembly.GetExecutingAssembly().GetManifestResourceStream("VideoRemote.UI.Images.LoadURLs.png"));
QuickMenuAPI.PrepareIcon("VideoRemoteMod", "VideoPlayerModUp", Assembly.GetExecutingAssembly().GetManifestResourceStream("VideoRemote.UI.Images.Up.png"));
QuickMenuAPI.PrepareIcon("VideoRemoteMod", "VideoPlayerModTimestamp", Assembly.GetExecutingAssembly().GetManifestResourceStream("VideoRemote.UI.Images.Timestamp.png"));
QuickMenuAPI.PrepareIcon("VideoRemoteMod", "VideoPlayerModClock-Hours", Assembly.GetExecutingAssembly().GetManifestResourceStream("VideoRemote.UI.Images.Clock-Hours.png"));
QuickMenuAPI.PrepareIcon("VideoRemoteMod", "VideoPlayerModClock-Minutes", Assembly.GetExecutingAssembly().GetManifestResourceStream("VideoRemote.UI.Images.Clock-Minutes.png"));
QuickMenuAPI.PrepareIcon("VideoRemoteMod", "VideoPlayerModClock-Seconds", Assembly.GetExecutingAssembly().GetManifestResourceStream("VideoRemote.UI.Images.Clock-Seconds.png"));
QuickMenuAPI.PrepareIcon("VideoRemoteMod", "VideoPlayerModPlayBlack", Assembly.GetExecutingAssembly().GetManifestResourceStream("VideoRemote.UI.Images.PlayBlack.png"));
QuickMenuAPI.PrepareIcon("VideoRemoteMod", "VideoPlayerModReset", Assembly.GetExecutingAssembly().GetManifestResourceStream("VideoRemote.UI.Images.Reset.png"));
QuickMenuAPI.PrepareIcon("VideoRemoteMod", "VideoPlayerModDebug", Assembly.GetExecutingAssembly().GetManifestResourceStream("VideoRemote.UI.Images.Debug.png"));
QuickMenuAPI.PrepareIcon("VideoRemoteMod", "VideoPlayerModRes", Assembly.GetExecutingAssembly().GetManifestResourceStream("VideoRemote.UI.Images.Res.png"));
QuickMenuAPI.PrepareIcon("VideoRemoteMod", "VideoPlayerModEventLog", Assembly.GetExecutingAssembly().GetManifestResourceStream("VideoRemote.UI.Images.EventLog.png"));
QuickMenuAPI.PrepareIcon("VideoRemoteMod", "VideoPlayerModRemoveLink", Assembly.GetExecutingAssembly().GetManifestResourceStream("VideoRemote.UI.Images.RemoveLink.png"));
QuickMenuAPI.PrepareIcon("VideoRemoteMod", "VideoPlayerModURLHistory", Assembly.GetExecutingAssembly().GetManifestResourceStream("VideoRemote.UI.Images.URLHistory.png"));
QuickMenuAPI.PrepareIcon("VideoRemoteMod", "VideoPlayerMod-jog-5", Assembly.GetExecutingAssembly().GetManifestResourceStream("VideoRemote.UI.Images.Minus5.png"));
QuickMenuAPI.PrepareIcon("VideoRemoteMod", "VideoPlayerMod-jog-1", Assembly.GetExecutingAssembly().GetManifestResourceStream("VideoRemote.UI.Images.Minus1.png"));
QuickMenuAPI.PrepareIcon("VideoRemoteMod", "VideoPlayerMod-jog1", Assembly.GetExecutingAssembly().GetManifestResourceStream("VideoRemote.UI.Images.Plus1.png"));
QuickMenuAPI.PrepareIcon("VideoRemoteMod", "VideoPlayerMod-jog5", Assembly.GetExecutingAssembly().GetManifestResourceStream("VideoRemote.UI.Images.Plus5.png"));
SetupUI();
QuickMenuAPI.OnOpenedPage += OnPageOpen;
QuickMenuAPI.OnBackAction += OnPageBack;
static void SetupUI()
{
var CustomPage = new Page("VideoRemoteMod", "VideoRemotePage", true, "VideoPlayerModLogo")
{
//This sets the title that appears at the very top in the header bar
MenuTitle = ModBuildInfo.Name,
MenuSubtitle = ModBuildInfo.Description
};
MainPageString = CustomPage.ElementID;
videoName = CustomPage.AddCategory("No Video Player Selected", true, false);
var category = videoName;
var Folder = category.AddPage("Select Video Player", "VideoPlayerModLogo", "List Video Players in the World", "VideoRemoteMod");
VideoFolderString = Folder.ElementID;
VideoPlayerListMain = Folder.AddCategory("", false, false);
VideoPlayerList = Folder.AddCategory("Video Players In World", true, false);
var button = category.AddButton("Play Video", "VideoPlayerModPlay2", "Play the Video");
button.OnPress += () =>
{
if (VideoPlayerSelected != null)
{
VideoPlayerSelected.Play();
MelonCoroutines.Start(Instance.SetCurrentVideoNameDelay());
}
else
{
QuickMenuAPI.ShowAlertToast("Video Player Not Selected or does not exist.", 2);
MelonLogger.Msg("Video Player Not Selected or does not exist.");
}
};
var button2 = category.AddButton("Pause Video", "VideoPlayerModPause2", "Pause the Video");
button2.OnPress += () =>
{
if (VideoPlayerSelected != null)
{
VideoPlayerSelected.Pause();
MelonCoroutines.Start(Instance.SetCurrentVideoNameDelay());
}
else
{
QuickMenuAPI.ShowAlertToast("Video Player Not Selected or does not exist.", 2);
MelonLogger.Msg("Video Player Not Selected or does not exist.");
}
};
var button3 = category.AddButton("Paste and Play Video", "VideoPlayerModPastePlay", "Paste and Play the Video");
button3.OnPress += () =>
{
if (VideoPlayerSelected != null)
{
QuickMenuAPI.ShowConfirm("Confirm", "Paste and Play Video?", () =>
{
VideoPlayerSelected.PasteAndPlay();
MelonCoroutines.Start(Instance.SetCurrentVideoNameDelay());
}, () => { }, "Yes", "No");
}
else
{
QuickMenuAPI.ShowAlertToast("Video Player Not Selected or does not exist.", 2);
MelonLogger.Msg("Video Player Not Selected or does not exist.");
}
};
volumeSilder = CustomPage.AddSlider("Volume", "Video Player Volume", .5f, 0f, 1f);
volumeSilder.OnValueUpdated += action =>
{
if (VideoPlayerSelected != null)
{
VideoPlayerSelected.SetLocalAudioVolume(volumeSilder.SliderValue);
}
};
AdvancedOptions = CustomPage.AddCategory("", false, false);
PopulateAdvancedButtons(true);
var catLocalVid = CustomPage.AddCategory("Local Video Player Screen", true, false);
var buttSpawnScreen = catLocalVid.AddButton("Spawn/Toggle Local Screen", "VideoPlayerModNewScreen", "Creates a local copy of the video player screen in front of you.<p>You must select a video player first.").OnPress += () =>
{
if (VideoPlayerSelected != null || (!localScreen?.Equals(null) ?? false))
{
ToggleLocalScreen();
}
else
{
QuickMenuAPI.ShowAlertToast("Can not create local screen. Video Player Not Selected or does not exist.", 3);
MelonLogger.Msg("Can not create local screen. Video Player Not Selected or does not exist.");
}
};
catLocalVid.AddButton("Smaller", "VideoPlayerModWhite-Minus", "Decreases the screen size").OnPress += () =>
{
if (sizeScale > .15) sizeScale -= .15f;
UpdateLocalScreen();
};
catLocalVid.AddButton("Larger", "VideoPlayerModWhite-Plus", "Increases the screen size").OnPress += () =>
{
sizeScale += .15f;
UpdateLocalScreen();
};
catLocalVid.AddToggle("Pickupable", "Toggles pickup of the local screen", pickupable).OnValueUpdated += action =>
{
pickupable = action;
UpdateLocalScreen();
};
}
}
private static void SaveUrl(ViewManagerVideoPlayer vp)
{
var dateFormatOut = "yyyy'-'MM'-'dd";
if (!String.IsNullOrWhiteSpace(vp.videoUrl.text))
{
string vidname = Utils.VideoNameFormat(vp);
if (!File.Exists(FolderRoot + savedURLsFileName))
{
using StreamWriter sw = File.CreateText(FolderRoot + savedURLsFileName);
sw.WriteLine(DateTime.Now.ToString(dateFormatOut) + " ␟ " + vidname + " ␟ " + vp.videoUrl.text);
}
else
{
if (File.Exists(FolderRoot + savedURLsFileName))
{
using StreamWriter sw = File.AppendText(FolderRoot + savedURLsFileName);
sw.WriteLine(DateTime.Now.ToString(dateFormatOut) + " ␟ " + vidname + " ␟ " + vp.videoUrl.text);
}
}
if(!savedURLs.ContainsKey(vp.videoUrl.text)) savedURLs.Add(vp.videoUrl.text, (vidname, DateTime.Now));
else
{
savedURLs.Remove(vp.videoUrl.text);
savedURLs.Add(vp.videoUrl.text, (vidname, DateTime.Now));
}
}
else
{
MelonLogger.Msg("There was nothing to save.");
}
}
private static void RemoveURL(string videoUrl)
{
var dateFormatOut = "yyyy'-'MM'-'dd";
if (savedURLs.ContainsKey(videoUrl))
{
savedURLs.Remove(videoUrl);
try
{
File.WriteAllLines(FolderRoot + savedURLsFileName, savedURLs.Select(p => string.Format("{0} ␟ {1} ␟ {2}", p.Value.Item2.ToString(dateFormatOut), p.Value.Item1, p.Key)), Encoding.UTF8);
}
catch (Exception ex) { MelonLogger.Error("Error writing video list after removing URL\n" + ex.ToString()); }
}
}
public static void LoadURLs()
{
var dateFormatIn = "yyyy-MM-dd";
if (File.Exists(FolderRoot + savedURLsFileName))
{
try
{
savedURLs = new Dictionary<string, (string, DateTime)>(File.ReadAllLines(FolderRoot + savedURLsFileName).Select(s => s.Split(new char[] { '␟' }, StringSplitOptions.RemoveEmptyEntries))
.Where(x => x.Length == 3).ToLookup(p => p[2].Trim(), p => (p[1].Trim(), Utils.ParseDate(p[0].Trim(), dateFormatIn)))
.ToDictionary(p => p.Key, p => p.First()));
}
catch (Exception ex) { MelonLogger.Warning("Error reading previously saved URLs \n" + ex.ToString()); }
}
}
private static void PopulateVideoList()
{
//MelonLogger.Msg("PopVideoList");
if (VideoPlayerListMain.IsGenerated) VideoPlayerListMain.ClearChildren();
if (VideoPlayerList.IsGenerated) VideoPlayerList.ClearChildren();
VideoPlayerListMain.AddButton("Load Video Players", "VideoPlayerModLogo", "Reload the list of Video Players in the world").OnPress += () =>
{
PopulateVideoList();
};
if (GameObject.FindObjectOfType<CVRVideoPlayer>())
{
foreach (CVRVideoPlayer CVRvp in GameObject.FindObjectsOfType<CVRVideoPlayer>())
{
List<IVideoPlayerUi> savedvpui = Traverse.Create(CVRvp).Field("VideoPlayerUis").GetValue<List<IVideoPlayerUi>>();
foreach (ViewManagerVideoPlayer vp in savedvpui.Cast<ViewManagerVideoPlayer>())
{
var dist = Math.Abs(Vector3.Distance(CVRvp.gameObject.transform.position, Camera.main.transform.position)).ToString("F2").TrimEnd('0');
var playerType = Utils.GetPlayerType(CVRvp.gameObject.transform);
var button = VideoPlayerList.AddButton($"Video Player\n{playerType}", $"{(playerType == "Prop" ? "VideoPlayerModVideoPlayer-Prop" : "VideoPlayerModVideoPlayer-World")}", $"Video:{Utils.VideoNameFormat(vp)}, Distance:{dist}<p>{Utils.GetPath(CVRvp.gameObject.transform)}");// | {CVRvp.playerId}");
button.OnPress += () =>
{
VideoPlayerSelected = vp;
MelonLogger.Msg(CVRvp.playerId + " has been selected");
};
}
}
}
}
private static void PopulateAdvancedButtons(bool init)
{ //Doing this way so the button states always show the current value from the video player. And a lot of hacky stuff to avoid using Bono's 'hack' for non-root pages.
//MelonLogger.Msg("PopAdvButtons");
if (AdvancedOptions.IsGenerated) AdvancedOptions.ClearChildren();
{
AdvOptionsPage = AdvancedOptions.AddPage("VideoPlayer Options", "VideoPlayerModAdvSettings2", "Set Permissions, Network Sync, Audio Mode, Reload current video, Timestamp Controls, Info and Debug", "VideoRemoteMod");
AdvOptionsString = AdvOptionsPage.ElementID;
CreatePageAdvOptionsPage(init);
}
//
{
SponsorSkipEvents = AdvancedOptions.AddPage("SponsorBlock", "VideoPlayerModSponsorSkip", "SponsorBlock can automatically skip sponsor segments in Youtube videos.", "VideoRemoteMod");
SponsorSkipEventsString = SponsorSkipEvents.ElementID;
CreatePageSponsorSkip();
}
//
AdvancedOptions.AddButton("Save URL", "VideoPlayerModSave", $"Stores the current video URL into the ChilloutVR/{FolderRoot} Folder.").OnPress += () =>
{
if (Utils.IsVideoPlayerValid(VideoPlayerSelected))
{
SaveUrl(VideoPlayerSelected);
QuickMenuAPI.ShowAlertToast($"Saved URL! Located in ChilloutVR/{FolderRoot}{savedURLsFileName}", 3);
MelonLogger.Msg($"Saved URL! Located in ChilloutVR/{FolderRoot}{savedURLsFileName}");
}
else
{
QuickMenuAPI.ShowAlertToast("Video Player Not Selected or does not exist.", 2);
MelonLogger.Msg("Video Player Not Selected or does not exist.");
}
};
//
{
savedURLsPage = AdvancedOptions.AddPage("Load Saved URLs", "VideoPlayerModLoadURLs", "Load previously saved URLS", "VideoRemoteMod");
savedURLsPageString = savedURLsPage.ElementID;
CreatePagesavedURLsPage();
}
}
public static void CreatePageAdvOptionsPage(bool init)
{
//MelonLogger.Msg($"AdvOpt {init}");
if (AdvOptionsPage != null && AdvOptionsPage.IsGenerated) AdvOptionsPage.ClearChildren();
var advSubPageCat = AdvOptionsPage.AddCategory("", false, false);
{
var current = Utils.IsVideoPlayerValid(VideoPlayerSelected) ? VideoPlayerSelected.videoPlayer.ControlPermission.ToString() : "None Selected";
var butt = advSubPageCat.AddButton($"Permission: {current}", "VideoPlayerModKeys", $"Toggles the video player permission between<p>Everyone and InstanceModerators");
butt.OnPress += () =>
{
if (Utils.IsVideoPlayerValid(VideoPlayerSelected))
{
VideoPlayerUtils.ControlPermission setTo = VideoPlayerUtils.ControlPermission.Everyone;
if (VideoPlayerSelected.videoPlayer.ControlPermission == VideoPlayerUtils.ControlPermission.Everyone)
{
QuickMenuAPI.ShowConfirm("Confirm", "Switch permission to InstanceModerators?", () =>
{
setTo = VideoPlayerUtils.ControlPermission.InstanceModerators;
VideoPlayerSelected.videoPlayer.SetControlPermission(setTo);
butt.ButtonText = $"Permission: {setTo}";
}, () => { }, "Yes", "No");
}
else
{
setTo = VideoPlayerUtils.ControlPermission.Everyone;
VideoPlayerSelected.videoPlayer.SetControlPermission(setTo);
butt.ButtonText = $"Permission: {setTo}";
}
}
else
{
QuickMenuAPI.ShowAlertToast("Video Player Not Selected or does not exist.", 2);
MelonLogger.Msg("Video Player Not Selected or does not exist.");
}
};
}
{
var butt = advSubPageCat.AddToggle("Network Sync", "Toggles Network Sync to state", true);
butt.OnValueUpdated += action =>
{
if (Utils.IsVideoPlayerValid(VideoPlayerSelected))
{
VideoPlayerSelected.videoPlayer.SetNetworkSync(action);
}
else
{
QuickMenuAPI.ShowAlertToast("Video Player Not Selected or does not exist.", 3);
MelonLogger.Msg("Video Player Not Selected or does not exist.");
}
};
}
{
var current = (VideoPlayerSelected != null) ? VideoPlayerSelected.videoPlayer.audioPlaybackMode.ToString() : "None Selected";
var butt = advSubPageCat.AddButton($"Audio Mode: {current}", "VideoPlayerModSound", $"Toggles audio mode between Direct, AudioSource, RoomScale<p>Currently: {current}");
butt.OnPress += () =>
{
if (Utils.IsVideoPlayerValid(VideoPlayerSelected))
{
try
{
switch (VideoPlayerSelected.videoPlayer.audioPlaybackMode)
{
case VideoPlayerUtils.AudioMode.Direct: VideoPlayerSelected.videoPlayer.SetAudioMode(VideoPlayerUtils.AudioMode.AudioSource); break;
case VideoPlayerUtils.AudioMode.AudioSource: VideoPlayerSelected.videoPlayer.SetAudioMode(VideoPlayerUtils.AudioMode.RoomScale); break;
case VideoPlayerUtils.AudioMode.RoomScale: VideoPlayerSelected.videoPlayer.SetAudioMode(VideoPlayerUtils.AudioMode.Direct); break;
default: VideoPlayerSelected.videoPlayer.SetAudioMode(VideoPlayerUtils.AudioMode.AudioSource); break;
}
butt.ButtonText = $"Audio Mode: {VideoPlayerSelected.videoPlayer.audioPlaybackMode}";
butt.ButtonTooltip = $"Toggles audio mode between Direct, AudioSource, RoomScale<p>Currently: {VideoPlayerSelected.videoPlayer.audioPlaybackMode}";
}
catch (System.Exception ex)
{
MelonLogger.Error($"Error when changing video audio source\n" + ex.ToString());
butt.ButtonText = $"Audio Mode: Error";
QuickMenuAPI.ShowAlertToast("Error when changing video audio source.", 3);
}
}
else
{
QuickMenuAPI.ShowAlertToast("Video Player Not Selected or does not exist.", 2);
MelonLogger.Msg("Video Player Not Selected or does not exist.");
}
};
}
//
{
var current = (VideoPlayerSelected != null) ? ((int)VideoPlayerSelected.videoPlayer.maxResolution).ToString() : "None Selected";
var butt = advSubPageCat.AddButton("Set Video Resolution", "VideoPlayerModRes", $"Set Video Max Resolution<p>Currently: {current}").OnPress += () =>
{
if (Utils.IsVideoPlayerValid(VideoPlayerSelected))
{
string[] resolutionStrings = Enum.GetValues(typeof(VideoPlayerUtils.Resolution))
.Cast<int>()
.Select(value => value.ToString())
.ToArray();
var selection = new BTKUILib.UIObjects.Objects.MultiSelection($"Video Resolution", resolutionStrings,
(Array.IndexOf(resolutionStrings, ((int)VideoPlayerSelected.videoPlayer.maxResolution).ToString())));
BTKUILib.QuickMenuAPI.OpenMultiSelect(selection);
selection.OnOptionUpdated += resInt => {
VideoPlayerSelected.videoPlayer.SetMaxResolution(Int32.Parse(resolutionStrings[resInt]));
//CreatePageAdvOptionsPage(false);
};
}
else
{
QuickMenuAPI.ShowAlertToast("Video Player Not Selected or does not exist.", 2);
MelonLogger.Msg("Video Player Not Selected or does not exist.");
}
};
}
//
{
var curState = (VideoPlayerSelected?.videoPlayer?.VideoPlayer != null) ? VideoPlayerSelected.videoPlayer.ytAudioOnly : false;
advSubPageCat.AddToggle("Audio Only", "Toggle Audio Only mode for Youtube<p>(Requires video reload)", curState).OnValueUpdated += action =>
{
if (Utils.IsVideoPlayerValid(VideoPlayerSelected))
{
VideoPlayerSelected.videoPlayer.ytAudioOnly = action;
}
else
{
QuickMenuAPI.ShowAlertToast("Video Player Not Selected or does not exist.", 2);
MelonLogger.Msg("Video Player Not Selected or does not exist.");
}
};
}
//
{
var butt = advSubPageCat.AddButton($"Reload video at timestamp", "VideoPlayerModReloadVideo", $"Reloads the current video and sets it back to the current timestamp");
butt.OnPress += () =>
{
if (Utils.IsVideoPlayerValid(VideoPlayerSelected))
{
if (TryingToReplay)
QuickMenuAPI.ShowAlertToast("Video reload already running", 2);
else
MelonCoroutines.Start(Instance.ReloadVideo());
}
else
{
QuickMenuAPI.ShowAlertToast("Video Player Not Selected or does not exist.", 2);
MelonLogger.Msg("Video Player Not Selected or does not exist.");
}
};
}
//
{
TimeStampPage = advSubPageCat.AddPage("Set to TimeStamp", "VideoPlayerModTimestamp", "Set videoplayer to timestamp", "VideoRemoteMod");
TimeStampPageString = TimeStampPage.ElementID;
if (init) CreatePageTimeStampPage();
}
//
var advSubPageCat_2 = AdvOptionsPage.AddCategory("", false, false);
//
{
LogPage = advSubPageCat_2.AddPage("Event Logs", "VideoPlayerModEventLog", "Video Player Event Logs", "VideoRemoteMod");
LogPageString = LogPage.ElementID;
if (init) CreatePageLogPage();
}
//
{
DebugPage = advSubPageCat_2.AddPage("DebugPage", "VideoPlayerModDebug", "DebugPage", "VideoRemoteMod");
DebugPageString = DebugPage.ElementID;
if (init) CreatePageDebug();
}
//
{
var butt = advSubPageCat_2.AddButton($"Load Blank Video", "VideoPlayerModPlayBlack", $"Load a blank video, just 480p black with no audio").OnPress += () =>
{
if (Utils.IsVideoPlayerValid(VideoPlayerSelected))
{
QuickMenuAPI.ShowConfirm("Confirm", $"Play Video?<p><p><p>Blank Video<p><p><p>1min long, Black, 480p", () =>
{
VideoPlayerSelected.videoPlayer.SetVideoUrl("https://www.youtube.com/watch?v=-Pg819il8lY");
MelonCoroutines.Start(Instance.SetCurrentVideoNameDelay());
}, () => { }, "Yes", "No");
}
else
{
QuickMenuAPI.ShowAlertToast("Video Player Not Selected or does not exist.", 2);
MelonLogger.Msg("Video Player Not Selected or does not exist.");
}
};
}
//
var advSubPageCat_3 = AdvOptionsPage.AddCategory("", false, false);
//
{
URLHistoryPage = advSubPageCat_3.AddPage("URL History Page", "VideoPlayerModURLHistory", "Videos played on VideoPlayers since game start", "VideoRemoteMod");
URLHistoryPageString = URLHistoryPage.ElementID;
if (init) CreatePageURLsHistroyPage();
}
{
var butt = advSubPageCat_3.AddToggle("URL History", "Record URL History for ALL VideoPlayers in the world - Checks every time a video is Played<p>With this off history is only saved when you have a VideoPlayer selected and interact with this menu.", videoHistory_En.Value);
butt.OnValueUpdated += action =>
{
videoHistory_En.Value = action;
};
}
}
public static void CreatePageTimeStampPage()
{
//MelonLogger.Msg("Timestamp");
if (TimeStampPage != null && TimeStampPage.IsGenerated) TimeStampPage.ClearChildren();
var timestampSum = timeStampHour * 60 * 60 + timeStampMin * 60 + timeStampSec;
if (!Utils.IsVideoPlayerValid(VideoPlayerSelected))
{
TimeStampPage.AddCategory($"No Player Selected", true, false);
}
else
{
if (VideoPlayerSelected.videoPlayer.VideoPlayer.Info.VideoMetaData.IsLivestream)
{
TimeStampPage.AddCategory($"Video is a livestream: No time controls allowed", true, false);
}
else if (!(VideoPlayerSelected.videoPlayer.VideoPlayer.Info.VideoMetaData.GetDuration() > 0))
{
TimeStampPage.AddCategory($"No video playing", true, false);
}
else
{
var currentString = "";
currentString += "Playing: " + Utils.VideoNameFormat(VideoPlayerSelected) + "<p>";
currentString += "Currently at: " + Utils.FormatTime((float)VideoPlayerSelected.videoPlayer.VideoPlayer.Time) + "<p>";
currentString += "End time: " + Utils.FormatTime((float)VideoPlayerSelected.videoPlayer.VideoPlayer.Info.VideoMetaData.GetDuration()) + "<p>";
var textCat = TimeStampPage.AddCategory("temp", true, false);
textCat.CategoryName = currentString;
var timeHeader = TimeStampPage.AddCategory($"Timestamp: {Utils.FormatTime(timestampSum)}", true, false);
timeHeader.AddButton($"Set to timestamp", "VideoPlayerModTimestamp", $"Set video to {Utils.FormatTime(timestampSum)}").OnPress += () =>
{
if (VideoPlayerSelected?.videoPlayer?.VideoPlayer != null && timestampSum < VideoPlayerSelected.videoPlayer.VideoPlayer.Info.VideoMetaData.GetDuration() - 5)
{//Confirm this video is still on
MelonLogger.Msg($"Manual set timestamp to: {Utils.FormatTime(timestampSum)}, Was at: {Utils.FormatTime((float)VideoPlayerSelected.videoPlayer.VideoPlayer.Time)}");
QuickMenuAPI.ShowAlertToast($"Manual set timestamp to: {Utils.FormatTime(timestampSum)}", 2);
VideoPlayerSelected.videoPlayer.SetVideoTimestamp(timestampSum);
CreatePageTimeStampPage();
}
else
{
QuickMenuAPI.ShowAlertToast("Video Player does not exist or timestamp beyond length of video", 3);
MelonLogger.Msg("Video Player does not exist or timestamp beyond length of video");
}
};
timeHeader.AddButton($"Set Hour", "VideoPlayerModClock-Hours", "Set the hour value").OnPress += () =>
{
QuickMenuAPI.OpenNumberInput("Hours", timeStampHour, (action) =>
{
timeStampHour = (int)action;
CreatePageTimeStampPage();
});
};
timeHeader.AddButton($"Set Minutes", "VideoPlayerModClock-Minutes", "Set the minute value").OnPress += () =>
{
QuickMenuAPI.OpenNumberInput("Minutes", timeStampMin, (action) =>
{
timeStampMin = (int)action;
CreatePageTimeStampPage();
});
};
timeHeader.AddButton($"Set Seconds", "VideoPlayerModClock-Seconds", "Set the second value").OnPress += () =>
{
QuickMenuAPI.OpenNumberInput("Seconds", timeStampSec, (action) =>
{
timeStampSec = (int)action;
CreatePageTimeStampPage();
});
};
var jogHeader = TimeStampPage.AddCategory($"Jog Controllers", true, false);
{
var jogList = new Dictionary<string, int> {
{"VideoPlayerMod-jog-5", -5 },
{"VideoPlayerMod-jog-1", -1 },
{"VideoPlayerMod-jog1", 1 },
{"VideoPlayerMod-jog5", 5 }
};
foreach (var jog in jogList)
{
float seconds = 60f * jog.Value;
jogHeader.AddButton($"{jog.Value} Min", jog.Key, $"Set video {jog.Value} minute(s)").OnPress += () =>
{
var timestampTo = (float)VideoPlayerSelected.videoPlayer.VideoPlayer.Time + seconds;
if (VideoPlayerSelected?.videoPlayer?.VideoPlayer != null && timestampTo < VideoPlayerSelected.videoPlayer.VideoPlayer.Info.VideoMetaData.GetDuration() - 5 &&
timestampTo > 0f)
{//Confirm this video is still on
MelonLogger.Msg($"Jogged timestamp to: {Utils.FormatTime(timestampTo)}, Was at: {Utils.FormatTime((float)VideoPlayerSelected.videoPlayer.VideoPlayer.Time)}");
QuickMenuAPI.ShowAlertToast($"Jogged timestamp to: {Utils.FormatTime(timestampTo)}", 2);
VideoPlayerSelected.videoPlayer.SetVideoTimestamp(timestampTo);
CreatePageTimeStampPage();
}
else
{
QuickMenuAPI.ShowAlertToast("Video Player does not exist or timestamp beyond length of video", 3);
MelonLogger.Msg("Video Player does not exist or timestamp beyond length of video");
}
};
}
}
var timeSegHeader = TimeStampPage.AddCategory($"Generated Timestamps", true, false);
if (VideoPlayerSelected.videoPlayer.VideoPlayer.Info.VideoMetaData.GetDuration() > 0)
{
var timeInterval = (float)VideoPlayerSelected.videoPlayer.VideoPlayer.Info.VideoMetaData.GetDuration() / 10;
for (int i = 0; i < 10; i += 2)
{
var timeSeg = timeInterval * i;
var timeSeg2 = timeInterval * (i + 1);
var timeStampText = $" {Utils.FormatTime(timeSeg)} " +
$" {Utils.FormatTime(timeSeg2)} ";
var timeSegLoop = TimeStampPage.AddCategory("temp", true, false); //__________________
timeSegLoop.CategoryName = timeStampText;
for (int x = 0; x < 2; x++)
{
var timeSegCopy = x == 0 ? timeSeg : timeSeg2;
timeSegLoop.AddButton($"Set videoplayer to time", "VideoPlayerModTimeStamp", $"Set video to {Utils.FormatTime(timeSegCopy)}").OnPress += () =>
{
if (VideoPlayerSelected?.videoPlayer?.VideoPlayer != null && timeSegCopy < VideoPlayerSelected.videoPlayer.VideoPlayer.Info.VideoMetaData.GetDuration() - 5)
{//Confirm this video is still on
MelonLogger.Msg($"Manual set segment timestamp to: {Utils.FormatTime(timeSeg)}, Was at: {Utils.FormatTime((float)VideoPlayerSelected.videoPlayer.VideoPlayer.Time)}");
QuickMenuAPI.ShowAlertToast($"Manual set segment timestamp to: {Utils.FormatTime(timeSeg)}", 2);
VideoPlayerSelected.videoPlayer.SetVideoTimestamp(timeSegCopy);
CreatePageTimeStampPage();
}
else
{
QuickMenuAPI.ShowAlertToast("Video Player does not exist or segment timestamp beyond length of video", 3);
MelonLogger.Msg("Video Player does not exist or segment timestamp beyond length of video");
CreatePageTimeStampPage();
}
};
timeSegLoop.AddButton($"Send time to custom input", "VideoPlayerModUp", $"Send this time value to custom input above").OnPress += () =>
{
timeStampHour = Utils.GetTimeSeg(timeSegCopy, "hour");
timeStampMin = Utils.GetTimeSeg(timeSegCopy, "min");
timeStampSec = Utils.GetTimeSeg(timeSegCopy, "sec");
CreatePageTimeStampPage();
};
}
}
}
}
}
}
public static void CreatePageLogPage()
{
//MelonLogger.Msg("Log");
if (LogPage != null && LogPage.IsGenerated) LogPage.ClearChildren();
if (!Utils.IsVideoPlayerValid(VideoPlayerSelected))
{
LogPage.AddCategory($"No Player Selected", true, false);
}
else
{
var cat = LogPage.AddCategory($"", false, false);
cat.AddButton($"Refresh", "VideoPlayerModReset", $"Refresh page").OnPress += () =>
{
CreatePageLogPage();
};
LogPage.AddCategory($"Video player log entries:", true, false);
if (VideoPlayerSelected.logEntries.Count == 0)
LogPage.AddCategory("None", true, false);
else
{
foreach (var entry in VideoPlayerSelected.logEntries)
{
var entryText = entry.Replace($"Unknown ({MetaPort.Instance.ownerId})", AuthManager.Username);
Regex regex = new Regex(@"(\d+\.\d+)");
Match match = regex.Match(entryText);
if (match.Success)
{
string floatString = match.Groups[1].Value;
if (float.TryParse(floatString, out float floatValue))
{
entryText = entryText.Replace(floatString +" seconds", $"{floatString} seconds ({Utils.FormatTime(floatValue)})");
}
}
LogPage.AddCategory(entryText, true, false);
}
}
}
}
public static void CreatePageDebug()
{
//MelonLogger.Msg("Debug");
if (DebugPage != null && DebugPage.IsGenerated) DebugPage.ClearChildren();
if (!Utils.IsVideoPlayerValid(VideoPlayerSelected))
{
DebugPage.AddCategory($"No Player Selected", true, false);
}
else
{
var cat = DebugPage.AddCategory($"Debug Info:", true, false);
cat.AddButton($"Refresh", "VideoPlayerModReset", $"Refresh page").OnPress += () =>
{
CreatePageDebug();
};
string str1 = "";
string str2 = "";
if (VideoPlayerSelected.videoPlayer.currentlySelectedVideo != null)
str1 = VideoPlayerSelected.videoPlayer.currentlySelectedVideo.videoTitle;
if (VideoPlayerSelected.videoPlayer.currentlySelectedPlaylist != null)
str2 = VideoPlayerSelected.videoPlayer.currentlySelectedPlaylist.playlistTitle;
var videoPlayer = VideoPlayerSelected.videoPlayer.VideoPlayer;
var debugString = "";
debugString += $"Video title: {str1.Truncate(25)}<p>";
debugString += $"Playlist title: {str2.Truncate(25)}<p>";
debugString += $"URL: {videoPlayer.Info.VideoMetaData.GetUrl()}<p>";
debugString += $"Video FPS: {videoPlayer.Info.VideoMetaData.GetVideoFps()} Player FPS: {videoPlayer.Info.GetPlayerFps()}<p>";
debugString += $"Connection: {(videoPlayer.Info.IsConnectionLost() ? "Lost" : "Connected")}<p>";
debugString += $"Video Player Time: {videoPlayer.Info.Time}<p>";
debugString += $"Audio Player Time: {videoPlayer.Info.AudioTime}<p>";
debugString += $"Video Texture Res: {videoPlayer.Info.VideoMetaData.GetVideoWidth()} x {videoPlayer.Info.VideoMetaData.GetVideoHeight()}<p>";
debugString += $"Render Texture Res: {VideoPlayerSelected.videoPlayer.ProjectionTexture.width} x {VideoPlayerSelected.videoPlayer.ProjectionTexture.height}<p>";
debugString += $"Video Codec: {GetVideoCodec()}<p>";
debugString += $"Audio Mode: {VideoPlayerSelected.videoPlayer.audioPlaybackMode}<p>";
debugString += $"Audio Channels: {videoPlayer.Info.VideoMetaData.GetAudioChannels()}";
var textcat = DebugPage.AddCategory("temp", true, false);
textcat.CategoryName = debugString;
string GetVideoCodec()
{
YoutubeDl.ProcessResult? processResult = VideoPlayerSelected.videoPlayer.VideoPlayer.Info.VideoMetaData.ProcessResult;
if (!processResult.HasValue)
return "Unknown";
YoutubeDlVideoMetaData output = processResult.Value.Output;
if (output == null)
return "Unknown";
if (!string.IsNullOrEmpty(output.VideoCodec))
return output.VideoCodec;
// This can get stuck returning nothing, which due to the way this mod is made, breaks the menu generation
// foreach (YoutubeDlVideoFormat requestedFormat in output.requestedFormats)
// {
// MelonLogger.Msg("60");
// if (requestedFormat.Format != null && !requestedFormat.Format.Contains("audio only") && requestedFormat.VideoCodec != null)
// return requestedFormat.VideoCodec;
// MelonLogger.Msg("70");
// }
return "Unknown";
}
}
}
public static void CreatePageSponsorSkip()
{
//MelonLogger.Msg("SponsorSkip");
if (SponsorSkipEvents != null && SponsorSkipEvents.IsGenerated) SponsorSkipEvents.ClearChildren();
var skipHeaderCat = SponsorSkipEvents.AddCategory($"", false, false);
skipHeaderCat.AddToggle("Enable", "Enable SponsorBlock for this VideoPlayer", sponsorSkip).OnValueUpdated += action =>
{
sponsorSkip = action;
StartSponsorSkip();
};
var skipSettings = SponsorSkipEvents.AddCategory($"Segments types to skip", true, false);
skipSettings.AddToggle("Sponsor", "Skip sponsor segments.<p>Doesn't skip if <5 seconds.", sponsorSkip_sponsor.Value).OnValueUpdated += action =>
{
sponsorSkip_sponsor.Value = action;
if (Utils.IsVideoPlayerValid(VideoPlayerSelected) && VideoPlayerSelected.videoPlayer.lastNetworkVideoUrl == sponsorskipVideo)
PrepSkipList();
};
skipSettings.AddToggle("Self Promo", "Skip self promo segments.<p>Doesn't skip if <5 seconds.", sponsorSkip_selfpromo.Value).OnValueUpdated += action =>
{
sponsorSkip_selfpromo.Value = action;
if (Utils.IsVideoPlayerValid(VideoPlayerSelected) && VideoPlayerSelected.videoPlayer.lastNetworkVideoUrl == sponsorskipVideo)
PrepSkipList();
};
skipSettings.AddToggle("Interaction", "Skip interaction segments.<p>Doesn't skip if <5 seconds.", sponsorSkip_interaction.Value).OnValueUpdated += action =>
{
sponsorSkip_interaction.Value = action;
if (Utils.IsVideoPlayerValid(VideoPlayerSelected) && VideoPlayerSelected.videoPlayer.lastNetworkVideoUrl == sponsorskipVideo)
PrepSkipList();
};
skipSettings.AddToggle("Intro", "Skip intro segments.<p>Doesn't skip if <5 seconds.", sponsorSkip_intro.Value).OnValueUpdated += action =>
{
sponsorSkip_intro.Value = action;
if (Utils.IsVideoPlayerValid(VideoPlayerSelected) && VideoPlayerSelected.videoPlayer.lastNetworkVideoUrl == sponsorskipVideo)
PrepSkipList();
};
if (!sponsorSkip)
{
SponsorSkipEvents.AddCategory($"SponsorBlock not enabled", true, false);
}
else if (!Utils.IsVideoPlayerValid(VideoPlayerSelected))
{
SponsorSkipEvents.AddCategory($"No video player selected", true, false);
}
else if (sponsorskipVideo == "API_Repsonse_Not_Found")
{
SponsorSkipEvents.AddCategory($"Video not found in SponsorBlock API", true, false);
}
else if (VideoPlayerSelected.videoPlayer.lastNetworkVideoUrl != sponsorskipVideo)
{
SponsorSkipEvents.AddCategory($"SponsorBlock hasn't grabbed current video yet, or no video is playing", true, false);
SponsorSkipEvents.AddCategory($"Go back a page to refresh this menu", true, false);
}
else if (sponsorskipResult == null || sponsorskipResult.Length == 0)
{
SponsorSkipEvents.AddCategory($"SponsorBlock didn't find any results");
}
else
{
var skipHeader = SponsorSkipEvents.AddCategory($"------------ All events for video ------------", true, false);
foreach (var x in sponsorskipResult.OrderBy(x => x.segment[0]))
{
var stringText = $"Type: {Utils.SkipCatSwitch(x.category)}{((x.category == "poi_highlight") ? " <<<<<<<<<<<<<<" : "")}<p>";
if (x.description != "") stringText += $"Desc: {x.description}<p>";
stringText += $"{Utils.FormatTime(x.segment[0])} - {Utils.FormatTime(x.segment[1])}<p>";
var skipEvent = SponsorSkipEvents.AddCategory($"temp", true, false);
skipEvent.CategoryName = stringText;
skipEvent.AddButton($"Jump to Start", "VideoPlayerModArrow-Left", $"Set video to start time of event {Utils.FormatTime(x.segment[0])}").OnPress += () =>
{
if (Utils.IsVideoPlayerValid(VideoPlayerSelected) && VideoPlayerSelected.videoPlayer.lastNetworkVideoUrl == sponsorskipVideo)
{//Confirm this video is still on
MelonLogger.Msg($"|SponsorBlock| Manual skip to: {Utils.FormatTime(x.segment[0])}, Was at: {Utils.FormatTime((float)VideoPlayerSelected.videoPlayer.VideoPlayer.Time)}");
QuickMenuAPI.ShowAlertToast($"Manual skip to: { Utils.FormatTime(x.segment[0])}", 2);
lastskip = x.segment;
VideoPlayerSelected.videoPlayer.SetVideoTimestamp(x.segment[0]);
}
else
{
QuickMenuAPI.ShowAlertToast("Video Player does not exist or wrong video playing.", 3);
MelonLogger.Msg("Video Player Not Selected or does not exist or wrong video playing - skipEvent");
}
};
skipEvent.AddButton($"Jump to End", "VideoPlayerModArrow-Right", $"Set video to end time of event {Utils.FormatTime(x.segment[1])}").OnPress += () =>
{
if (Utils.IsVideoPlayerValid(VideoPlayerSelected) && VideoPlayerSelected.videoPlayer.lastNetworkVideoUrl == sponsorskipVideo)
{//Confirm this video is still on
if (x.segment[1] > VideoPlayerSelected.videoPlayer.VideoPlayer.Info.VideoMetaData.GetDuration() - 5)
{ //Skip if <5 seconds from end of video
MelonLogger.Msg($"|SponsorBlock| Not skipping to {Utils.FormatTime(x.segment[1])}, less than 5 seconds till end of video");
QuickMenuAPI.ShowAlertToast($"Not skipping, less than 5 seconds till end of video!", 3);
}
else
{
MelonLogger.Msg($"|SponsorBlock| Manual skip to: {Utils.FormatTime(x.segment[1])}, Was at: {Utils.FormatTime((float)VideoPlayerSelected.videoPlayer.VideoPlayer.Time)}");
QuickMenuAPI.ShowAlertToast($"Manual skip to: { Utils.FormatTime(x.segment[1])}", 2);
lastskip = x.segment;
VideoPlayerSelected.videoPlayer.SetVideoTimestamp(x.segment[1]);
}