61 lines
1.6 KiB
C#
61 lines
1.6 KiB
C#
using System.Linq;
|
|
using System.Text.RegularExpressions;
|
|
using Learn.Models;
|
|
|
|
namespace Learn.Parsers;
|
|
|
|
public class NormalParser : ItemParser
|
|
{
|
|
private string ParseSeason(string season)
|
|
{
|
|
if (int.TryParse(season, out _)) return season;
|
|
|
|
switch (season)
|
|
{
|
|
case "零": return "0";
|
|
case "一": return "1";
|
|
case "二": return "2";
|
|
case "三": return "3";
|
|
case "四": return "4";
|
|
case "五": return "5";
|
|
case "六": return "6";
|
|
case "七": return "7";
|
|
case "八": return "8";
|
|
case "九": return "9";
|
|
}
|
|
return season;
|
|
}
|
|
|
|
public bool DoParse(TreeNode node)
|
|
{
|
|
var item = node.Info;
|
|
var name = item.Name();
|
|
var matches = Regex.Matches(name, @"[^\[\]_]+").Select(match => match.Value).ToArray();
|
|
|
|
if (matches.Length == 1)
|
|
{
|
|
node.Info.SetRawTitle(matches[0]);
|
|
return true;
|
|
}
|
|
|
|
if (matches.Length >= 2)
|
|
{
|
|
node.Info.SetGroupIfNotExist(matches[0]);
|
|
|
|
var title = matches[1].Trim();
|
|
var match = Regex.Match(title, "(.+)第(.+)季");
|
|
if (match.Success)
|
|
{
|
|
node.Info.SetSeasonIfNotExist(ParseSeason(match.Groups[2].Value.Trim()));
|
|
node.Info.SetRawTitle(match.Groups[1].Value.Trim());
|
|
}
|
|
else
|
|
{
|
|
node.Info.SetRawTitle(title);
|
|
}
|
|
}
|
|
|
|
|
|
return true;
|
|
}
|
|
} |