Skip to content

Commit

Permalink
feat: improve name parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
simon-ding committed Nov 16, 2024
1 parent 196ba66 commit f0f3281
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 46 deletions.
42 changes: 25 additions & 17 deletions pkg/metadata/tv.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
type Info struct {
NameEn string
NameCn string
Year int
Season int
StartEpisode int
EndEpisode int
Expand All @@ -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) {
Expand Down Expand Up @@ -462,17 +469,18 @@ func parseName(name string) *Info {
}
}
}

//匹配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))
}
}
}
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))
// }
// }
//}

}

Expand Down
6 changes: 6 additions & 0 deletions pkg/metadata/tv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
28 changes: 5 additions & 23 deletions server/core/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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 {
Expand Down
16 changes: 10 additions & 6 deletions server/core/torrent.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ lo:
continue
}

if !torrentSizeOk(series, r.Size, param) {
if !torrentSizeOk(series, r.Size, meta.EndEpisode+1-meta.StartEpisode, param) {
continue
}

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit f0f3281

Please sign in to comment.