mirror of
https://github.com/simon-ding/polaris.git
synced 2026-05-28 21:47:56 +08:00
feat: improve name parsing
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
|||||||
type Info struct {
|
type Info struct {
|
||||||
NameEn string
|
NameEn string
|
||||||
NameCn string
|
NameCn string
|
||||||
|
Year int
|
||||||
Season int
|
Season int
|
||||||
StartEpisode int
|
StartEpisode int
|
||||||
EndEpisode int
|
EndEpisode int
|
||||||
@@ -32,17 +33,23 @@ func (m *Info) ParseExtraDescription(desc string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *Info) IsAcceptable(names ...string) bool {
|
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 {
|
for _, name := range names {
|
||||||
re := regexp.MustCompile(`[^\p{L}\w\s]`)
|
|
||||||
name = re.ReplaceAllString(strings.ToLower(name), " ")
|
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), " ")
|
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
|
if utils.IsASCII(name) { //ascii name should match words
|
||||||
re := regexp.MustCompile(`\b` + name + `\b`)
|
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) {
|
if strings.Contains(nameCN, name) || strings.Contains(nameEN, name) {
|
||||||
@@ -462,17 +469,18 @@ func parseName(name string) *Info {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
meta.NameEn = title
|
||||||
|
|
||||||
//匹配title中最长拉丁字符串
|
////匹配title中最长拉丁字符串
|
||||||
enRe := regexp.MustCompile(`[[:ascii:]]*`)
|
//enRe := regexp.MustCompile(`[[:ascii:]]*`)
|
||||||
enM := enRe.FindAllString(title, -1)
|
//enM := enRe.FindAllString(title, -1)
|
||||||
if len(enM) > 0 {
|
//if len(enM) > 0 {
|
||||||
for _, t := range enM {
|
// for _, t := range enM {
|
||||||
if len(t) > len(meta.NameEn) {
|
// if len(t) > len(meta.NameEn) {
|
||||||
meta.NameEn = strings.TrimSpace(strings.ToLower(t))
|
// 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, true, m.IsSeasonPack)
|
||||||
//assert.Equal(t, "720p", m.Resolution)
|
//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
|
continue
|
||||||
}
|
}
|
||||||
wantedSeasonPack := true
|
wantedSeasonPack := true
|
||||||
|
seasonEpisodesWanted := make(map[int][]int, 0)
|
||||||
for _, ep := range epsides {
|
for _, ep := range epsides {
|
||||||
if !ep.Monitored {
|
if !ep.Monitored {
|
||||||
wantedSeasonPack = false
|
wantedSeasonPack = false
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
if ep.Status != episode.StatusMissing {
|
if ep.Status != episode.StatusMissing {
|
||||||
wantedSeasonPack = false
|
wantedSeasonPack = false
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
if ep.AirDate != "" {
|
if ep.AirDate != "" {
|
||||||
t, err := time.Parse("2006-01-02", 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
|
if time.Now().Before(t.Add(-24 * time.Hour)) { //not aired
|
||||||
wantedSeasonPack = false
|
wantedSeasonPack = false
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
seasonEpisodesWanted[ep.SeasonNumber] = append(seasonEpisodesWanted[ep.SeasonNumber], ep.EpisodeNumber)
|
||||||
}
|
}
|
||||||
if wantedSeasonPack {
|
if wantedSeasonPack {
|
||||||
names, err := c.SearchAndDownload(id, seasonNum)
|
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)
|
log.Warnf("finding season pack error: %v", err)
|
||||||
wantedSeasonPack = false
|
wantedSeasonPack = false
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if !wantedSeasonPack {
|
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 {
|
for se, eps := range seasonEpisodesWanted {
|
||||||
names, err := c.SearchAndDownload(id, se, eps...)
|
names, err := c.SearchAndDownload(id, se, eps...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ lo:
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if !torrentSizeOk(series, r.Size, param) {
|
if !torrentSizeOk(series, r.Size, meta.EndEpisode+1-meta.StartEpisode, param) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,7 +114,7 @@ func imdbIDMatchExact(id1, id2 string) bool {
|
|||||||
return id1 == id2
|
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
|
defaultMinSize := 80 * 1000 * 1000 //tv, 80M min
|
||||||
if detail.MediaType == media.MediaTypeMovie {
|
if detail.MediaType == media.MediaTypeMovie {
|
||||||
defaultMinSize = 200 * 1000 * 1000 // movie, 200M min
|
defaultMinSize = 200 * 1000 * 1000 // movie, 200M min
|
||||||
@@ -123,9 +123,13 @@ func torrentSizeOk(detail *db.MediaDetails, torrentSize int, param *SearchParam)
|
|||||||
defaultMinSize = detail.Limiter.SizeMin
|
defaultMinSize = detail.Limiter.SizeMin
|
||||||
}
|
}
|
||||||
|
|
||||||
multiplier := 1 //大小倍数,正常为1,如果是季包则为季内集数
|
multiplier := 1 //大小倍数,正常为1,如果是季包则为季内集数
|
||||||
if detail.MediaType == media.MediaTypeTv && len(param.Episodes) == 0 { //tv season pack
|
if detail.MediaType == media.MediaTypeTv {
|
||||||
multiplier = seasonEpisodeCount(detail, param.SeasonNum)
|
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
|
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
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if !torrentSizeOk(movieDetail, r.Size, param) {
|
if !torrentSizeOk(movieDetail, r.Size, 1, param) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user