mirror of
https://github.com/simon-ding/polaris.git
synced 2026-02-06 23:21:00 +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), " ")
|
||||||
@@ -27,7 +28,7 @@ func (m *MovieMetadata) IsAcceptable(names... string) bool {
|
|||||||
return re.MatchString(name2)
|
return re.MatchString(name2)
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.Contains(name2, name) {
|
if strings.Contains(name2, name) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -52,7 +53,6 @@ func findYear(name string) (year int, index int) {
|
|||||||
if len(yearMatches) > 0 {
|
if len(yearMatches) > 0 {
|
||||||
year, index = findYearInMatches(yearMatches, name)
|
year, index = findYearInMatches(yearMatches, name)
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@@ -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