mirror of
https://github.com/simon-ding/polaris.git
synced 2026-02-06 15:10:49 +08:00
better match year
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type MovieMetadata struct {
|
type MovieMetadata struct {
|
||||||
@@ -15,7 +16,7 @@ type MovieMetadata struct {
|
|||||||
IsQingban bool
|
IsQingban bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MovieMetadata) IsAcceptable(names... string) bool {
|
func (m *MovieMetadata) IsAcceptable(names ...string) bool {
|
||||||
for _, name := range names {
|
for _, name := range names {
|
||||||
re := regexp.MustCompile(`[^\p{L}\w\s]`)
|
re := regexp.MustCompile(`[^\p{L}\w\s]`)
|
||||||
name = re.ReplaceAllString(strings.ToLower(name), " ")
|
name = re.ReplaceAllString(strings.ToLower(name), " ")
|
||||||
@@ -26,8 +27,8 @@ func (m *MovieMetadata) IsAcceptable(names... string) bool {
|
|||||||
re := regexp.MustCompile(`\b` + name + `\b`)
|
re := regexp.MustCompile(`\b` + name + `\b`)
|
||||||
return re.MatchString(name2)
|
return re.MatchString(name2)
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.Contains(name2, name) {
|
if strings.Contains(name2, name) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -51,16 +52,15 @@ func findYear(name string) (year int, index int) {
|
|||||||
yearMatches := yearRe.FindAllString(name, -1)
|
yearMatches := yearRe.FindAllString(name, -1)
|
||||||
if len(yearMatches) > 0 {
|
if len(yearMatches) > 0 {
|
||||||
year, index = findYearInMatches(yearMatches, name)
|
year, index = findYearInMatches(yearMatches, name)
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func findYearInMatches(matches []string, name string) (year int, index int) {
|
func findYearInMatches(matches []string, name string) (year int, index int) {
|
||||||
if len(matches) == 0 {
|
if len(matches) == 0 {
|
||||||
return 0, -1
|
return 0, -1
|
||||||
}
|
}
|
||||||
for _, y := range matches {
|
for _, y := range matches {
|
||||||
index = strings.Index(name, y)
|
index = strings.Index(name, y)
|
||||||
@@ -68,7 +68,7 @@ func findYearInMatches(matches []string, name string) (year int, index int) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Sprintf("convert %s error: %v", y, err))
|
panic(fmt.Sprintf("convert %s error: %v", y, err))
|
||||||
}
|
}
|
||||||
if n < 1900 || n > 2050 {
|
if n < 1900 || n > time.Now().Year()+1 { //filter invalid year
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
year = n
|
year = n
|
||||||
@@ -101,7 +101,7 @@ func ParseMovie(name string) *MovieMetadata {
|
|||||||
|
|
||||||
// https://en.wikipedia.org/wiki/Pirated_movie_release_types
|
// https://en.wikipedia.org/wiki/Pirated_movie_release_types
|
||||||
func isQiangban(name string) bool {
|
func isQiangban(name string) bool {
|
||||||
qiangbanFilter := []string{"CAMRip","CAM-Rip", "CAM", "HDCAM", "TS","TSRip", "HDTS", "TELESYNC", "PDVD", "PreDVDRip", "TC", "HDTC", "TELECINE", "WP", "WORKPRINT"}
|
qiangbanFilter := []string{"CAMRip", "CAM-Rip", "CAM", "HDCAM", "TS", "TSRip", "HDTS", "TELESYNC", "PDVD", "PreDVDRip", "TC", "HDTC", "TELECINE", "WP", "WORKPRINT"}
|
||||||
re := regexp.MustCompile(`\W`)
|
re := regexp.MustCompile(`\W`)
|
||||||
name = re.ReplaceAllString(strings.ToLower(name), " ")
|
name = re.ReplaceAllString(strings.ToLower(name), " ")
|
||||||
fields := strings.Fields(name)
|
fields := strings.Fields(name)
|
||||||
|
|||||||
Reference in New Issue
Block a user