Skip to content

Commit

Permalink
分集匹配策略调整 不再支持不规范的文件名
Browse files Browse the repository at this point in the history
  • Loading branch information
fengqi committed Apr 6, 2023
1 parent 18d5f79 commit 40d569f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
8 changes: 4 additions & 4 deletions utils/video.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func init() {
channelMap[item] = struct{}{}
}

episodeMatch, _ = regexp.Compile("((?:s|S|第|\\s)([0-9]+)(季|)(?:.|_|x|-|\\s|))?((?:第|E|e|Ep|P|EP|\\s)([0-9]+)(集|)?)")
episodeMatch, _ = regexp.Compile(`(?i)((?:s|第|season)([0-9]+)(?:季|)(?:.|_|x|-| |))?((?:第|e|ep|p|episode)([0-9]+)(?:集|))`)
collectionMatch, _ = regexp.Compile("[sS](0|)[0-9]+-[sS](0|)[0-9]+")
subEpisodesMatch, _ = regexp.Compile("[eE](0|)[0-9]+-[eE](0|)[0-9]+")
yearRangeLikeMatch, _ = regexp.Compile("[12][0-9]{3}-[12][0-9]{3}")
Expand Down Expand Up @@ -293,7 +293,7 @@ func SplitTitleAlias(name string) (string, string) {
// MatchEpisode 匹配季和集
func MatchEpisode(name string) (string, int, int) {
find := episodeMatch.FindStringSubmatch(name)
if len(find) != 7 {
if len(find) != 5 {
return "", 0, 0
}

Expand All @@ -306,8 +306,8 @@ func MatchEpisode(name string) (string, int, int) {
}
}

if len(find[5]) > 0 {
s, err := strconv.Atoi(find[5])
if len(find[4]) > 0 {
s, err := strconv.Atoi(find[4])
if err == nil {
episode = s
}
Expand Down
13 changes: 5 additions & 8 deletions utils/video_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,14 @@ import (
func TestMatchEpisode(t *testing.T) {
cases := map[string][]int{
"[堕落].The.Fall.2013.S02.E03.Complete.BluRay.720p.x264.AC3-CMCT.mkv": {2, 3},
"[堕落].The.Fall.2013.S10.E12.Complete.BluRay.720p.x264.AC3-CMCT.mkv": {10, 12},
"[堕落].The.Fall.2013.S120.E132.Complete.BluRay.720p.x264.AC3-CMCT.mkv": {120, 132},
"Agent.Carter.S02E01.1080p.BluRay.DD5.1.x264-HDS.mkv": {2, 1},
"[壹高清]21点灵.Leave No Soul Behind.Ep01.HDTV.1080p.H264-OneHD.ts": {1, 1},
"Kimetsu.no.Yaiba.Yuukaku-hen.E01.2021.Crunchyroll.WEB-DL.1080p.x264.AAC-HDCTV.mkv": {1, 1},
"Overlord IV - 09.mp4": {1, 9},
"宝贝揪揪 第3季 第10集.mp4": {3, 10},
"宝贝揪揪 3季 10集.mp4": {3, 10},
"宝贝揪揪 第9集.mp4": {1, 9},
"Gannibal.E01.2022": {1, 1},
"Gannibal S01 E01 2022": {1, 1},
"宝贝揪揪 第3季 第10集.mp4": {3, 10},
"宝贝揪揪 第9集.mp4": {1, 9},
"Gannibal.E01.2022.mp4": {1, 1},
"Gannibal S02 E11 2022.mp4": {2, 11},
"Gannibal-S01-E02-2022.mp4": {1, 2},
}
for name, cse := range cases {
_, s, e := MatchEpisode(name)
Expand Down

0 comments on commit 40d569f

Please sign in to comment.