Skip to content

Commit

Permalink
特殊字符处理
Browse files Browse the repository at this point in the history
  • Loading branch information
fengqi committed Apr 4, 2023
1 parent 57c0fe5 commit 9d19a5e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
18 changes: 9 additions & 9 deletions utils/video.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func init() {
seasonMatch, _ = regexp.Compile("[sS](0|)[0-9]+")
optionsMatch, _ = regexp.Compile("\\[.*?\\](\\.)?")
chsMatch, _ = regexp.Compile("([零一二三四五六七八九十百千万亿]+)[季|集]")
chsSeasonMatch, _ = regexp.Compile("第([0-9]+)([-至到])?([0-9]+)?季")
chsSeasonMatch, _ = regexp.Compile("(.*?)(\\.|)第([0-9]+)([-至到])?([0-9]+)?季")
resolutionMatch, _ = regexp.Compile("[0-9]{3,4}Xx*[0-9]{3,4}")
seasonRangeMatch, _ = regexp.Compile("[sS](0|)[0-9]+-[sS](0|)[0-9]+")
}
Expand Down Expand Up @@ -382,23 +382,23 @@ func FilterCorrecting(name string) string {
name = ReplaceChsNumber(name)
right := ""
find := chsSeasonMatch.FindStringSubmatch(name)
if len(find) == 4 {
if find[2] == "" && find[3] == "" {
num, err := strconv.Atoi(find[1])
if len(find) == 6 {
if find[4] == "" && find[5] == "" {
num, err := strconv.Atoi(find[3])
if err == nil && num > 0 {
right = fmt.Sprintf("S%.2d", num)
}
} else {
num1, err := strconv.Atoi(find[1])
num2, err := strconv.Atoi(find[3])
num1, err := strconv.Atoi(find[3])
num2, err := strconv.Atoi(find[5])
if err == nil && num1 > 0 && num2 > 0 {
right = fmt.Sprintf("S%.2d-S%.2d", num1, num2)
}
}
}

if right != "" {
return chsSeasonMatch.ReplaceAllString(name, right)
if right != "" {
name = strings.Replace(name, find[0], find[1]+"."+right, 1)
}
}

return name
Expand Down
7 changes: 4 additions & 3 deletions utils/video_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func TestIsSeason(t *testing.T) {

func TestSplit(t *testing.T) {
unit := map[string][]string{
"[梦蓝字幕组]Crayonshinchan 蜡笔小新[1105][2021.11.06][AVC][1080P][GB_JP][MP4]V2.mp4": []string{
"[梦蓝字幕组]Crayonshinchan 蜡笔小新[1105][2021.11.06][AVC][1080P][GB_JP][MP4]V2.mp4": {
"梦蓝字幕组",
"Crayonshinchan",
"蜡笔小新",
Expand All @@ -86,14 +86,14 @@ func TestSplit(t *testing.T) {
"V2",
"mp4",
},
"The Last Son 2021.mkv": []string{
"The Last Son 2021.mkv": {
"The",
"Last",
"Son",
"2021",
"mkv",
},
"Midway 2019 2160p CAN UHD Blu-ray HEVC DTS-HD MA [email protected]": []string{
"Midway 2019 2160p CAN UHD Blu-ray HEVC DTS-HD MA [email protected]": {
"Midway",
"2019",
"2160p",
Expand Down Expand Up @@ -191,6 +191,7 @@ func TestFilterCorrecting(t *testing.T) {
"堕落.第一季.2013.中英字幕£CMCT无影": "堕落.S01.2013.中英字幕£CMCT无影",
"一年一度喜剧大赛": "一年一度喜剧大赛",
"亿万富犬.第一季": "亿万富犬.S01",
"超级宝贝JOJO第二季": "超级宝贝JOJO.S02",
}

for title, want := range cases {
Expand Down

0 comments on commit 9d19a5e

Please sign in to comment.