mirror of
https://github.com/simon-ding/polaris.git
synced 2026-02-06 15:10:49 +08:00
feat: improve name parsing
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
||||
type Info struct {
|
||||
NameEn string
|
||||
NameCn string
|
||||
Year int
|
||||
Season int
|
||||
StartEpisode int
|
||||
EndEpisode int
|
||||
@@ -32,17 +33,23 @@ func (m *Info) ParseExtraDescription(desc string) {
|
||||
}
|
||||
|
||||
func (m *Info) IsAcceptable(names ...string) bool {
|
||||
re := regexp.MustCompile(`[^\p{L}\w\s]`)
|
||||
|
||||
nameCN := re.ReplaceAllString(strings.ToLower(m.NameCn), " ")
|
||||
nameEN := re.ReplaceAllString(strings.ToLower(m.NameEn), " ")
|
||||
nameCN = strings.Join(strings.Fields(nameCN), " ")
|
||||
nameEN = strings.Join(strings.Fields(nameEN), " ")
|
||||
|
||||
for _, name := range names {
|
||||
re := regexp.MustCompile(`[^\p{L}\w\s]`)
|
||||
name = re.ReplaceAllString(strings.ToLower(name), " ")
|
||||
nameCN := re.ReplaceAllString(strings.ToLower(m.NameCn), " ")
|
||||
nameEN := re.ReplaceAllString(strings.ToLower(m.NameEn), " ")
|
||||
name = strings.Join(strings.Fields(name), " ")
|
||||
nameCN = strings.Join(strings.Fields(nameCN), " ")
|
||||
nameEN = strings.Join(strings.Fields(nameEN), " ")
|
||||
if utils.IsASCII(name) { //ascii name should match words
|
||||
re := regexp.MustCompile(`\b` + name + `\b`)
|
||||
return re.MatchString(nameCN) || re.MatchString(nameEN)
|
||||
if re.MatchString(nameCN) || re.MatchString(nameEN) {
|
||||
return true
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if strings.Contains(nameCN, name) || strings.Contains(nameEN, name) {
|
||||
@@ -462,17 +469,18 @@ func parseName(name string) *Info {
|
||||
}
|
||||
}
|
||||
}
|
||||
meta.NameEn = title
|
||||
|
||||
//匹配title中最长拉丁字符串
|
||||
enRe := regexp.MustCompile(`[[:ascii:]]*`)
|
||||
enM := enRe.FindAllString(title, -1)
|
||||
if len(enM) > 0 {
|
||||
for _, t := range enM {
|
||||
if len(t) > len(meta.NameEn) {
|
||||
meta.NameEn = strings.TrimSpace(strings.ToLower(t))
|
||||
}
|
||||
}
|
||||
}
|
||||
////匹配title中最长拉丁字符串
|
||||
//enRe := regexp.MustCompile(`[[:ascii:]]*`)
|
||||
//enM := enRe.FindAllString(title, -1)
|
||||
//if len(enM) > 0 {
|
||||
// for _, t := range enM {
|
||||
// if len(t) > len(meta.NameEn) {
|
||||
// meta.NameEn = strings.TrimSpace(strings.ToLower(t))
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -207,3 +207,9 @@ func Test_ParseTV19(t *testing.T) {
|
||||
assert.Equal(t, true, m.IsSeasonPack)
|
||||
//assert.Equal(t, "720p", m.Resolution)
|
||||
}
|
||||
|
||||
func Test_Name(t *testing.T) {
|
||||
m := Info{NameEn: "word кибердеревня новый год 2023 webrip 1080p"}
|
||||
b := m.IsAcceptable("word")
|
||||
assert.True(t, b)
|
||||
}
|
||||
|
||||
@@ -299,12 +299,15 @@ func (c *Client) DownloadSeriesAllEpisodes(id int) []string {
|
||||
continue
|
||||
}
|
||||
wantedSeasonPack := true
|
||||
seasonEpisodesWanted := make(map[int][]int, 0)
|
||||
for _, ep := range epsides {
|
||||
if !ep.Monitored {
|
||||
wantedSeasonPack = false
|
||||
continue
|
||||
}
|
||||
if ep.Status != episode.StatusMissing {
|
||||
wantedSeasonPack = false
|
||||
continue
|
||||
}
|
||||
if ep.AirDate != "" {
|
||||
t, err := time.Parse("2006-01-02", ep.AirDate)
|
||||
@@ -318,8 +321,10 @@ func (c *Client) DownloadSeriesAllEpisodes(id int) []string {
|
||||
*/
|
||||
if time.Now().Before(t.Add(-24 * time.Hour)) { //not aired
|
||||
wantedSeasonPack = false
|
||||
continue
|
||||
}
|
||||
}
|
||||
seasonEpisodesWanted[ep.SeasonNumber] = append(seasonEpisodesWanted[ep.SeasonNumber], ep.EpisodeNumber)
|
||||
}
|
||||
if wantedSeasonPack {
|
||||
names, err := c.SearchAndDownload(id, seasonNum)
|
||||
@@ -330,32 +335,9 @@ func (c *Client) DownloadSeriesAllEpisodes(id int) []string {
|
||||
log.Warnf("finding season pack error: %v", err)
|
||||
wantedSeasonPack = false
|
||||
}
|
||||
|
||||
}
|
||||
if !wantedSeasonPack {
|
||||
seasonEpisodesWanted := make(map[int][]int, 0)
|
||||
for _, ep := range epsides {
|
||||
if !ep.Monitored {
|
||||
continue
|
||||
}
|
||||
if ep.Status != episode.StatusMissing {
|
||||
continue
|
||||
}
|
||||
if ep.AirDate != "" {
|
||||
if t, err := time.Parse("2006-01-02", ep.AirDate); err == nil {
|
||||
/*
|
||||
-------- now ------ t -----
|
||||
t - 1day < now 要检测的剧集
|
||||
提前一天开始检测
|
||||
*/
|
||||
if time.Now().Before(t.Add(-24 * time.Hour)) { //not aired
|
||||
continue
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
seasonEpisodesWanted[ep.SeasonNumber] = append(seasonEpisodesWanted[ep.SeasonNumber], ep.EpisodeNumber)
|
||||
}
|
||||
for se, eps := range seasonEpisodesWanted {
|
||||
names, err := c.SearchAndDownload(id, se, eps...)
|
||||
if err != nil {
|
||||
|
||||
@@ -80,7 +80,7 @@ lo:
|
||||
continue
|
||||
}
|
||||
|
||||
if !torrentSizeOk(series, r.Size, param) {
|
||||
if !torrentSizeOk(series, r.Size, meta.EndEpisode+1-meta.StartEpisode, param) {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ func imdbIDMatchExact(id1, id2 string) bool {
|
||||
return id1 == id2
|
||||
}
|
||||
|
||||
func torrentSizeOk(detail *db.MediaDetails, torrentSize int, param *SearchParam) bool {
|
||||
func torrentSizeOk(detail *db.MediaDetails, torrentSize int, torrentEpisodeNum int, param *SearchParam) bool {
|
||||
defaultMinSize := 80 * 1000 * 1000 //tv, 80M min
|
||||
if detail.MediaType == media.MediaTypeMovie {
|
||||
defaultMinSize = 200 * 1000 * 1000 // movie, 200M min
|
||||
@@ -123,9 +123,13 @@ func torrentSizeOk(detail *db.MediaDetails, torrentSize int, param *SearchParam)
|
||||
defaultMinSize = detail.Limiter.SizeMin
|
||||
}
|
||||
|
||||
multiplier := 1 //大小倍数,正常为1,如果是季包则为季内集数
|
||||
if detail.MediaType == media.MediaTypeTv && len(param.Episodes) == 0 { //tv season pack
|
||||
multiplier = seasonEpisodeCount(detail, param.SeasonNum)
|
||||
multiplier := 1 //大小倍数,正常为1,如果是季包则为季内集数
|
||||
if detail.MediaType == media.MediaTypeTv {
|
||||
if len(param.Episodes) == 0 { //want tv season pack
|
||||
multiplier = seasonEpisodeCount(detail, param.SeasonNum)
|
||||
} else {
|
||||
multiplier = torrentEpisodeNum
|
||||
}
|
||||
}
|
||||
|
||||
if param.CheckFileSize { //check file size when trigger automatic download
|
||||
@@ -217,7 +221,7 @@ func SearchMovie(db1 *db.Client, param *SearchParam) ([]torznab.Result, error) {
|
||||
continue
|
||||
}
|
||||
|
||||
if !torrentSizeOk(movieDetail, r.Size, param) {
|
||||
if !torrentSizeOk(movieDetail, r.Size, 1, param) {
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user