node build fixed
This commit is contained in:
59
seanime-2.9.10/internal/util/parsing.go
Normal file
59
seanime-2.9.10/internal/util/parsing.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func ExtractSeasonNumber(title string) (int, string) {
|
||||
title = strings.ToLower(title)
|
||||
|
||||
rgx := regexp.MustCompile(`((?P<a>\d+)(st|nd|rd|th)?\s*(season))|((season)\s*(?P<b>\d+))`)
|
||||
|
||||
matches := rgx.FindStringSubmatch(title)
|
||||
if len(matches) < 1 {
|
||||
return 0, title
|
||||
}
|
||||
m := matches[rgx.SubexpIndex("a")]
|
||||
if m == "" {
|
||||
m = matches[rgx.SubexpIndex("b")]
|
||||
}
|
||||
if m == "" {
|
||||
return 0, title
|
||||
}
|
||||
ret, ok := StringToInt(m)
|
||||
if !ok {
|
||||
return 0, title
|
||||
}
|
||||
|
||||
cTitle := strings.TrimSpace(rgx.ReplaceAllString(title, ""))
|
||||
|
||||
return ret, cTitle
|
||||
}
|
||||
|
||||
func ExtractPartNumber(title string) (int, string) {
|
||||
title = strings.ToLower(title)
|
||||
|
||||
rgx := regexp.MustCompile(`((?P<a>\d+)(st|nd|rd|th)?\s*(cour|part))|((cour|part)\s*(?P<b>\d+))`)
|
||||
|
||||
matches := rgx.FindStringSubmatch(title)
|
||||
if len(matches) < 1 {
|
||||
return 0, title
|
||||
}
|
||||
m := matches[rgx.SubexpIndex("a")]
|
||||
if m == "" {
|
||||
m = matches[rgx.SubexpIndex("b")]
|
||||
}
|
||||
if m == "" {
|
||||
return 0, title
|
||||
}
|
||||
ret, ok := StringToInt(m)
|
||||
if !ok {
|
||||
return 0, title
|
||||
}
|
||||
|
||||
cTitle := strings.TrimSpace(rgx.ReplaceAllString(title, ""))
|
||||
|
||||
return ret, cTitle
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user