forked from DjShinter/VideoRemote
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUtils.cs
More file actions
142 lines (126 loc) · 5.13 KB
/
Utils.cs
File metadata and controls
142 lines (126 loc) · 5.13 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using ABI_RC.VideoPlayer.Scripts;
using MelonLoader;
using UnityEngine;
namespace VideoRemote
{
public static class Utils
{
public static string GetPath(this Transform current)
{ //http://answers.unity.com/answers/261847/view.html
if (current.parent == null)
return "World:" + current.name;
if (current.name.Contains("CVRSpawnable_"))
return "Prop:";
return current.parent.GetPath() + "/ " + current.name;
}
public static string GetPlayerType(this Transform current)
{ //http://answers.unity.com/answers/261847/view.html
if (current.parent == null)
return "World";
if (current.name.Contains("CVRSpawnable_"))
return "Prop";
if (current.name.Contains("_CVRSpawnable"))
return "Prop";
return current.parent.GetPlayerType();
}
public static bool IsVideoPlayerValid(ViewManagerVideoPlayer vidPlay)
{
return (vidPlay != null) && !(vidPlay?.videoPlayer?.VideoPlayer.Equals(null) ?? true) ;
}
public static string VideoState(ViewManagerVideoPlayer vidPlay)
{
if (vidPlay?.videoName?.text.Equals(null) ?? true)
return "";
if (vidPlay.videoName.text.Contains("Currently Playing:"))
return "Playing: ";
if (vidPlay.videoName.text.Contains("Currently Paused:"))
return "Paused: ";
return "";
}
public static string VideoNameFormat(ViewManagerVideoPlayer vidPlay)
{
//"Currently Paused:"
//"Currently Playing:"
if (vidPlay?.videoName?.text.Equals(null) ?? true)
return "No video player";
if (vidPlay.videoName.text.Length < 25)
return "No video playing";
if (vidPlay.videoName.text.Contains("Currently Playing:"))
return vidPlay.videoName.text.Remove(0, 26);
if (vidPlay.videoName.text.Contains("Currently Paused:"))
return vidPlay.videoName.text.Remove(0, 25);
var name = vidPlay.videoName.text.Remove(0, 26);
return (name != "eo selected") ? name : "No video playing";
}
public static string SkipCatSwitch(string value)
{
switch (value)
{
case "sponsor": return "Sponsor";
case "selfpromo": return "Selfpromo";
case "interaction": return "Interaction";
case "intro": return "Intro";
case "outro": return "Outro";
case "preview": return "Preview";
case "music_offtopic": return "Music Offtopic";
case "poi_highlight": return "Highlight";
case "chapter": return "Chapter";
default: return $"Unknown: {value}";
}
}
public static string FormatTime(float seconds)
{
TimeSpan time = TimeSpan.FromSeconds(seconds);
return time.ToString(@"hh\:mm\:ss");
}
public static int GetTimeSeg(float seconds, string type)
{
TimeSpan time = TimeSpan.FromSeconds(seconds);
switch (type)
{
case "hour": return int.Parse(time.ToString(@"hh"));
case "min": return int.Parse(time.ToString(@"mm"));
case "sec": return int.Parse(time.ToString(@"ss"));
default: return 0;
}
}
public static DateTime ParseDate(string value, string format)
{
if (DateTime.TryParseExact(value, format, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out var dt))
{
return dt;
}
MelonLogger.Msg(ConsoleColor.Red, $"Date Error: {value}");
return DateTime.MinValue;
}
//https://stackoverflow.com/a/39784693
private const string YoutubeLinkRegex = "(?:.+?)?(?:\\/v\\/|watch\\/|\\?v=|\\&v=|youtu\\.be\\/|\\/v=|^youtu\\.be\\/)([a-zA-Z0-9_-]{11})+";
private static Regex regexExtractId = new Regex(YoutubeLinkRegex, RegexOptions.Compiled);
private static string[] validAuthorities = { "youtube.com", "www.youtube.com", "youtu.be", "www.youtu.be" };
public static string ExtractVideoIdFromUri(Uri uri)
{
try
{
string authority = new UriBuilder(uri).Uri.Authority.ToLower();
//check if the url is a youtube url
if (validAuthorities.Contains(authority))
{
//and extract the id
var regRes = regexExtractId.Match(uri.ToString());
if (regRes.Success)
{
return regRes.Groups[1].Value;
}
}
}
catch { }
return null;
}
}
}