完成RawParser,开始弄TMDB
This commit is contained in:
parent
596f2bc693
commit
447aaf12e7
@ -5,25 +5,25 @@ namespace Learn.Config;
|
||||
|
||||
public class MatchGroupsRules
|
||||
{
|
||||
public List<string> Full { get; set; }
|
||||
public List<string> Partial { get; set; }
|
||||
public List<string> Full { get; set; } = new();
|
||||
public List<string> Partial { get; set; } = new();
|
||||
}
|
||||
|
||||
|
||||
public class MatchTypeExtra
|
||||
{
|
||||
public List<string> IfDirNameIs { get; set; }
|
||||
public List<string> IfFileExtensionIs { get; set; }
|
||||
public List<string> IfDirNameIs { get; set; } = new();
|
||||
public List<string> IfFileExtensionIs { get; set; } = new();
|
||||
}
|
||||
|
||||
public class MatchTypeSubtitle
|
||||
{
|
||||
public List<string> IfFileExtensionIs { get; set; }
|
||||
public List<string> IfFileExtensionIs { get; set; } = new();
|
||||
}
|
||||
|
||||
public class MatchTypeEpisode
|
||||
{
|
||||
public List<string> IfFileExtensionIs { get; set; }
|
||||
public List<string> IfFileExtensionIs { get; set; } = new();
|
||||
}
|
||||
|
||||
public class MatchTypeRules
|
||||
@ -35,24 +35,59 @@ public class MatchTypeRules
|
||||
|
||||
public class MatchSeasonRules
|
||||
{
|
||||
public List<string> Regexes { get; set; }
|
||||
public List<string> Regexes { get; set; } = new();
|
||||
}
|
||||
|
||||
public class MatchEpisodeRules
|
||||
{
|
||||
public List<string> Regexes { get; set; } = new();
|
||||
}
|
||||
|
||||
public class FilterTokenRules
|
||||
{
|
||||
public List<string> Regexes { get; set; }
|
||||
public List<string> Regexes { get; set; } = new();
|
||||
}
|
||||
|
||||
[ConfigItem("RawParser")]
|
||||
public class RawParserConfig : IConfigItem
|
||||
{
|
||||
public string SplitRegex { get; set; } = "";
|
||||
|
||||
public MatchTypeRules TypeMatchRules { get; set; }
|
||||
|
||||
public MatchGroupsRules GroupsMatchRules { get; set; }
|
||||
|
||||
public MatchSeasonRules SeasonMatchRules { get; set; }
|
||||
|
||||
public FilterTokenRules TokenFilterRules { get; set; }
|
||||
public string SplitRegex { get; set; } = @"[^\[\]_【】《》]+";
|
||||
|
||||
public MatchTypeRules TypeMatchRules { get; set; } = new()
|
||||
{
|
||||
Extra = new ()
|
||||
{
|
||||
IfDirNameIs = {"NCOP&NCED", "PV", "menu", "Fonts", "Scans", "特典映像", "CDs", "迷你动画", "SPs"},
|
||||
IfFileExtensionIs = {".rar", ".zip", "png", "jpg", "jpeg"}
|
||||
},
|
||||
Subtitle = new ()
|
||||
{
|
||||
IfFileExtensionIs = {".srt", ".ass"}
|
||||
},
|
||||
Episode = new ()
|
||||
{
|
||||
IfFileExtensionIs = {".mp4", ".mkv"}
|
||||
}
|
||||
};
|
||||
|
||||
public MatchGroupsRules GroupsMatchRules { get; set; } = new()
|
||||
{
|
||||
Full = { "Rev", "Mukai", "WYQSub" },
|
||||
Partial = { "-Studio", "-Raws", "LoliHouse", "字幕组", "VCB-Studio", "Nekomoe kissaten", "Kamigami", "ANi"}
|
||||
};
|
||||
|
||||
public MatchSeasonRules SeasonMatchRules { get; set; } = new()
|
||||
{
|
||||
Regexes = {@"第(.+)季", @"[Ss]eason *(\d+)", @"S(\d{2})E\d{2}"}
|
||||
};
|
||||
|
||||
public MatchEpisodeRules EpisodeRules { get; set; } = new()
|
||||
{
|
||||
Regexes = {@"(^\d{1,2}$)", @"S\d{2}E(\d{2})"}
|
||||
};
|
||||
|
||||
public FilterTokenRules TokenFilterRules { get; set; } = new()
|
||||
{
|
||||
Regexes = { @"\d+[Pp]$", @"\d{1,2}-\d{1,2}" }
|
||||
};
|
||||
}
|
||||
27
Main.cs
27
Main.cs
@ -18,6 +18,7 @@ public partial class Main : Node
|
||||
[ExportGroup("操作面板")]
|
||||
[Export] private Button _openDirButton;
|
||||
[Export] private Button _doParseButton;
|
||||
[Export] private Button _doTMDBParseButton;
|
||||
[Export] private Button _saveButton;
|
||||
[Export] private Button _resetButton;
|
||||
[Export] private Button _loadButton;
|
||||
@ -68,6 +69,7 @@ public partial class Main : Node
|
||||
// 功能区
|
||||
_openDirButton.Pressed += ScanDir;
|
||||
_doParseButton.Pressed += DoParse;
|
||||
_doTMDBParseButton.Pressed += DoTMDBParse;
|
||||
_saveButton.Pressed += DoSave;
|
||||
_resetButton.Pressed += DoReset;
|
||||
_loadButton.Pressed += LoadData;
|
||||
@ -145,12 +147,31 @@ public partial class Main : Node
|
||||
_refreshPanels = true;
|
||||
}
|
||||
|
||||
private async void DoTMDBParse()
|
||||
{
|
||||
var root = _mainTreePanel.GetRoot();
|
||||
if (root == null) return;
|
||||
|
||||
_doTMDBParseButton.Disabled = true;
|
||||
|
||||
ItemParser parser = new TMDBParser(_configs);
|
||||
|
||||
|
||||
foreach (var node in _mainTreePanel.SelectingNodes)
|
||||
{
|
||||
await parser.Parse(node);
|
||||
}
|
||||
|
||||
_doTMDBParseButton.Disabled = false;
|
||||
_mainTreePanel.UpdateColumns();
|
||||
GD.Print("[TMDBParse] Done");
|
||||
}
|
||||
|
||||
private async void DoParse()
|
||||
{
|
||||
var root = _mainTreePanel.GetRoot();
|
||||
if (root == null) return;
|
||||
|
||||
var originName = _doParseButton.Text;
|
||||
_doParseButton.Disabled = true;
|
||||
|
||||
ItemParser parser = new RawParser(_configs);
|
||||
@ -160,10 +181,10 @@ public partial class Main : Node
|
||||
await parser.Parse(node);
|
||||
}
|
||||
|
||||
_doParseButton.Text = originName;
|
||||
_doParseButton.Disabled = false;
|
||||
|
||||
_mainTreePanel.UpdateColumns();
|
||||
GD.Print("Done");
|
||||
GD.Print("[RawParse] Done");
|
||||
}
|
||||
|
||||
private const string DataPath = "data.json";
|
||||
|
||||
@ -17,11 +17,12 @@ grow_vertical = 2
|
||||
[node name="FileDirDialog" type="FileDialog" parent="."]
|
||||
script = ExtResource("1_d2g23")
|
||||
|
||||
[node name="Main" type="Node" parent="." node_paths=PackedStringArray("_dirSelector", "_openDirButton", "_doParseButton", "_saveButton", "_resetButton", "_loadButton", "_reloadConfigButton", "_nodeInfoEditPanel", "_addKeyButton", "_removeKeyButton", "_inspectorPanel", "_mainTreePanel", "_columnIndexText", "_columnWidthText", "_columnText", "_addColumnButton", "_removeColumnButton", "_clearColumnButton", "_expandAllButton", "_foldAllButton")]
|
||||
[node name="Main" type="Node" parent="." node_paths=PackedStringArray("_dirSelector", "_openDirButton", "_doParseButton", "_doTMDBParseButton", "_saveButton", "_resetButton", "_loadButton", "_reloadConfigButton", "_nodeInfoEditPanel", "_addKeyButton", "_removeKeyButton", "_inspectorPanel", "_mainTreePanel", "_columnIndexText", "_columnWidthText", "_columnText", "_addColumnButton", "_removeColumnButton", "_clearColumnButton", "_expandAllButton", "_foldAllButton")]
|
||||
script = ExtResource("2_0727o")
|
||||
_dirSelector = NodePath("../FileDirDialog")
|
||||
_openDirButton = NodePath("../MarginContainer/HSplitContainer/ScrollContainer/VBoxContainer2/FoldableContainer4/VBoxContainer2/TabContainer/文件夹操作/ScanDir")
|
||||
_doParseButton = NodePath("../MarginContainer/HSplitContainer/ScrollContainer/VBoxContainer2/FoldableContainer4/VBoxContainer2/TabContainer/文件夹操作/DoParse")
|
||||
_doTMDBParseButton = NodePath("../MarginContainer/HSplitContainer/ScrollContainer/VBoxContainer2/FoldableContainer4/VBoxContainer2/TabContainer/文件夹操作/DoTMDBParse")
|
||||
_saveButton = NodePath("../MarginContainer/HSplitContainer/ScrollContainer/VBoxContainer2/FoldableContainer4/VBoxContainer2/TabContainer/保存操作/Save")
|
||||
_resetButton = NodePath("../MarginContainer/HSplitContainer/ScrollContainer/VBoxContainer2/FoldableContainer4/VBoxContainer2/TabContainer/保存操作/Reset")
|
||||
_loadButton = NodePath("../MarginContainer/HSplitContainer/ScrollContainer/VBoxContainer2/FoldableContainer4/VBoxContainer2/TabContainer/保存操作/Load")
|
||||
@ -86,10 +87,9 @@ layout_mode = 2
|
||||
[node name="TabContainer" type="TabContainer" parent="MarginContainer/HSplitContainer/ScrollContainer/VBoxContainer2/FoldableContainer4/VBoxContainer2"]
|
||||
custom_minimum_size = Vector2(0, 200)
|
||||
layout_mode = 2
|
||||
current_tab = 1
|
||||
current_tab = 0
|
||||
|
||||
[node name="文件夹操作" type="VBoxContainer" parent="MarginContainer/HSplitContainer/ScrollContainer/VBoxContainer2/FoldableContainer4/VBoxContainer2/TabContainer"]
|
||||
visible = false
|
||||
layout_mode = 2
|
||||
metadata/_tab_index = 0
|
||||
|
||||
@ -101,9 +101,15 @@ text = "扫描文件夹"
|
||||
[node name="DoParse" type="Button" parent="MarginContainer/HSplitContainer/ScrollContainer/VBoxContainer2/FoldableContainer4/VBoxContainer2/TabContainer/文件夹操作"]
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 4
|
||||
text = "开始解析"
|
||||
text = "初步解析"
|
||||
|
||||
[node name="DoTMDBParse" type="Button" parent="MarginContainer/HSplitContainer/ScrollContainer/VBoxContainer2/FoldableContainer4/VBoxContainer2/TabContainer/文件夹操作"]
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 4
|
||||
text = "搜刮选中部分"
|
||||
|
||||
[node name="保存操作" type="VBoxContainer" parent="MarginContainer/HSplitContainer/ScrollContainer/VBoxContainer2/FoldableContainer4/VBoxContainer2/TabContainer"]
|
||||
visible = false
|
||||
layout_mode = 2
|
||||
metadata/_tab_index = 1
|
||||
|
||||
|
||||
@ -35,16 +35,18 @@ public static class ItemFields
|
||||
#endregion
|
||||
|
||||
#region 普通字段
|
||||
|
||||
|
||||
public static string Key_Group => "Group";
|
||||
public static string Key_Title => "Title";
|
||||
public static string Key_RawTitle => "RawTitle";
|
||||
public static string Key_Season => "Season";
|
||||
public static string Key_Type => "Type";
|
||||
|
||||
public static string Key_SubtitleLanguage => "SubLang";
|
||||
|
||||
public static string Key_Episode => "Episode";
|
||||
public static string Key_Year => "Year";
|
||||
|
||||
public static string Key_EpisodeNum => "EpisodeNum";
|
||||
public static string Key_TMDBID => "TMDBID";
|
||||
|
||||
public static ItemType Type(this Item item)
|
||||
{
|
||||
|
||||
@ -272,16 +272,19 @@ public class RawParser(Configs configs) : ItemParser
|
||||
var tokens = part.Split("-");
|
||||
foreach (var token in tokens)
|
||||
{
|
||||
var match = Regex.Match(token.Trim(), @"^\d{1,2}$");
|
||||
if (match.Success)
|
||||
foreach (var regex in config.EpisodeRules.Regexes)
|
||||
{
|
||||
episode = int.Parse(match.Value).ToString();
|
||||
matchInfo = new MatchInfo
|
||||
var match = Regex.Match(token.Trim(), regex);
|
||||
if (match.Success)
|
||||
{
|
||||
content = match.Value,
|
||||
partIndex = i
|
||||
};
|
||||
return true;
|
||||
episode = int.Parse(match.Groups[1].Value).ToString();
|
||||
matchInfo = new MatchInfo
|
||||
{
|
||||
content = match.Value,
|
||||
partIndex = i
|
||||
};
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -294,11 +297,6 @@ public class RawParser(Configs configs) : ItemParser
|
||||
{
|
||||
rawTitle = null;
|
||||
matchInfo = null;
|
||||
|
||||
if (item.Name().Contains("夏目"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (item.Type() == ItemFields.ItemType.Extra)
|
||||
{
|
||||
@ -324,7 +322,21 @@ public class RawParser(Configs configs) : ItemParser
|
||||
tokens = FilterParts(tokens);
|
||||
|
||||
if(tokens.Count == 0) return false;
|
||||
|
||||
rawTitle = tokens.First().Trim();
|
||||
|
||||
// 尝试匹配年份
|
||||
foreach (var token in tokens)
|
||||
{
|
||||
var matchYear = Regex.Match(token, @"[((](\d{4})[))]");
|
||||
if (matchYear.Success)
|
||||
{
|
||||
rawTitle = rawTitle.Replace(matchYear.Value, "").Trim();
|
||||
item.Info.TryAdd(ItemFields.Key_Year, matchYear.Groups[1].Value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user