-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVideoInfo.cs
93 lines (79 loc) · 3.1 KB
/
VideoInfo.cs
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
using System.Text.RegularExpressions;
namespace Info
{
public enum Mode
{
YOUTUBE_DL,
CONSOLE
}
public class VideoInfo
{
public string name;
public string source;
public string url;
public VideoInfo(string filePathOrName, Mode mode)
{
string filenameFixed = Path.GetFileName(filePathOrName).Replace("07th-Mod", "(07th_mod)");
switch (mode)
{
case Mode.YOUTUBE_DL:
{
Regex re = new Regex(@"(.*)\s*-\s*(.*)\s*\[(.*)\].*");
Match match = re.Match(filenameFixed);
name = match.Groups[1].Value.Trim();
source = match.Groups[2].Value.Trim();
url = match.Groups[3].Value.Trim();
// If match fails, try re-matching without URL
if (!match.Success || string.IsNullOrEmpty(name) || string.IsNullOrEmpty(url))
{
Regex re2 = new Regex(@"(.*)\s*-\s*(.*)\s*\..*");
Match match2 = re2.Match(filenameFixed);
name = match2.Groups[1].Value.Trim();
source = match2.Groups[2].Value.Trim();
url = "";
}
}
break;
case Mode.CONSOLE:
{
Regex re = new Regex(@"([^ ]*)\s+(.*?)(\s*\[(.{11})\])?\..*");
Match match = re.Match(filenameFixed);
string filename = match.Groups[1].Value.Trim();
name = $"{match.Groups[2].Value}".Trim();
source = "".Trim();
url = "".Trim();
// URL is optional
// Wihtout URL: "semi_r BSFX Cicadas with Phasor (GIN).ogg"
// With URL: "msys23 Dancers7 (GIN) [0Wb-tFSRCnU].ogg"
if (match.Groups.Count >= 5)
{
url = match.Groups[4].Value;
}
}
break;
default:
throw new Exception("Unknown mode for parsing metainfo from filename");
}
if (string.IsNullOrEmpty(name))
{
throw new Exception($"Couldn't parse bgm/se name from {filePathOrName}, mode: {mode}\nPlease check filename format is correct, and be careful of special characters like `()-[]`");
}
}
public VideoInfo(string name, string source, string url)
{
this.name = name;
this.source = source;
this.url = url;
}
public VideoInfo(string name)
{
this.name = name;
this.source = "";
this.url = "";
}
public override string ToString()
{
return $"url: {url,-11} name: {name,-60} source: {source}";
}
}
}