fix: name matching

This commit is contained in:
Simon Ding
2024-08-03 15:03:47 +08:00
parent 241e30152b
commit ffa5c37c4c
4 changed files with 26 additions and 38 deletions

View File

@@ -29,20 +29,11 @@ func ParseTv(name string) *Metadata {
func parseEnglishName(name string) *Metadata {
re := regexp.MustCompile(`[^\p{L}\w\s]`)
name = re.ReplaceAllString(strings.ToLower(name), " ")
splits := strings.Split(strings.TrimSpace(name), " ")
var newSplits []string
for _, p := range splits {
p = strings.TrimSpace(p)
if p == "" {
continue
}
newSplits = append(newSplits, p)
}
newSplits := strings.Split(strings.TrimSpace(name), " ")
seasonRe := regexp.MustCompile(`^s\d{1,2}`)
resRe := regexp.MustCompile(`^\d{3,4}p`)
episodeRe := regexp.MustCompile(`e\d{1,2}`)
episodeRe := regexp.MustCompile(`e\d{1,3}`)
var seasonIndex = -1
var episodeIndex = -1
@@ -58,7 +49,7 @@ func parseEnglishName(name string) *Metadata {
} else if resRe.MatchString(p) {
resIndex = i
}
if episodeRe.MatchString(p) {
if i >= seasonIndex && episodeRe.MatchString(p) {
episodeIndex = i
}
}
@@ -137,7 +128,7 @@ func parseEnglishName(name string) *Metadata {
//resolution exists
meta.Resolution = newSplits[resIndex]
}
if meta.Episode == -1 || strings.Contains(name, "complete") {
if meta.Episode == -1 {
meta.Episode = -1
meta.IsSeasonPack = true
}

View File

@@ -101,8 +101,8 @@ func Test_ParseTV10(t *testing.T) {
m := ParseTv(s1)
log.Infof("results: %+v", m)
assert.Equal(t, 2, m.Season)
assert.Equal(t, 01, m.Episode)
assert.Equal(t, false, m.IsSeasonPack)
//assert.Equal(t, 01, m.Episode)
assert.Equal(t, true, m.IsSeasonPack)
assert.Equal(t, "720p", m.Resolution)
}
@@ -127,13 +127,13 @@ func Test_ParseTV12(t *testing.T) {
}
func Test_ParseTV13(t *testing.T) {
s1 := ""
s1 := "House of Dragon 2024 1080p S02E08 Leaked HQCAM NOT COMPLETE English Audio x264 ESub BOTHD"
m := ParseTv(s1)
log.Infof("results: %+v", m)
assert.Equal(t, 2, m.Season)
assert.Equal(t, 01, m.Episode)
assert.Equal(t, 8, m.Episode)
assert.Equal(t, false, m.IsSeasonPack)
assert.Equal(t, "720p", m.Resolution)
assert.Equal(t, "1080p", m.Resolution)
}
func Test_ParseTV14(t *testing.T) {

View File

@@ -7,8 +7,6 @@ import (
"strings"
"unicode"
"github.com/adrg/strutil"
"github.com/adrg/strutil/metrics"
"github.com/pkg/errors"
"golang.org/x/crypto/bcrypt"
"golang.org/x/exp/rand"
@@ -65,7 +63,7 @@ func IsNameAcceptable(name1, name2 string) bool {
if strings.Contains(name1, name2) || strings.Contains(name2, name1) {
return true
}
return strutil.Similarity(name1, name2, metrics.NewHamming()) > 0.4
return false
}
func FindSeasonEpisodeNum(name string) (se int, ep int, err error) {

View File

@@ -21,7 +21,7 @@ func SearchTvSeries(db1 *db.Client, seriesId, seasonNum int, episodes []int, che
if series == nil {
return nil, fmt.Errorf("no tv series of id %v", seriesId)
}
slices.Contains(episodes, 1)
log.Debugf("check tv series %s, season %d, episode %v", series.NameEn, seasonNum, episodes)
res := searchWithTorznab(db1, series.NameEn)
resCn := searchWithTorznab(db1, series.NameCn)
@@ -34,19 +34,19 @@ func SearchTvSeries(db1 *db.Client, seriesId, seasonNum int, episodes []int, che
if meta == nil { //cannot parse name
continue
}
if !isNumberedSeries(series) { //do not check season on series that only rely on episode number
if meta.Season != seasonNum {
continue
}
if !isNumberedSeries(series) && meta.Season != seasonNum { //do not check season on series that only rely on episode number
continue
}
if isNumberedSeries(series) && len(episodes) == 0 {
//should not want season
continue
}
if len(episodes) > 0 && slices.Contains(episodes, meta.Episode) { //not season pack, episode number equals
if len(episodes) > 0 && !slices.Contains(episodes, meta.Episode) { //not season pack, but episode number not equal
continue
}else if len(episodes) == 0 && !meta.IsSeasonPack { //want season pack, but not season pack
} else if len(episodes) == 0 && !meta.IsSeasonPack { //want season pack, but not season pack
continue
}
if checkResolution && meta.Resolution != series.Resolution.String() {
@@ -56,8 +56,8 @@ func SearchTvSeries(db1 *db.Client, seriesId, seasonNum int, episodes []int, che
continue
}
if checkFileSize && series.Limiter != nil {
if series.Limiter.SizeMin > 0 && r.Size < series.Limiter.SizeMin {
if checkFileSize && series.Limiter != nil {
if series.Limiter.SizeMin > 0 && r.Size < series.Limiter.SizeMin {
//min size not satified
continue
}
@@ -115,8 +115,8 @@ func SearchMovie(db1 *db.Client, movieId int, checkResolution bool, checkFileSiz
continue
}
if checkFileSize && movieDetail.Limiter != nil {
if movieDetail.Limiter.SizeMin > 0 && r.Size < movieDetail.Limiter.SizeMin {
if checkFileSize && movieDetail.Limiter != nil {
if movieDetail.Limiter.SizeMin > 0 && r.Size < movieDetail.Limiter.SizeMin {
//min size not satified
continue
}
@@ -195,17 +195,17 @@ func searchWithTorznab(db *db.Client, q string) []torznab.Result {
sort.SliceStable(res, func(i, j int) bool {
var s1 = res[i]
var s2 = res[j]
if s1.IndexerId == s2.IndexerId && s1.IsPrivate {
if s1.IndexerId == s2.IndexerId && s1.IsPrivate {
return s1.DownloadVolumeFactor < s2.DownloadVolumeFactor
}
return false
})
//同一indexer内部如果下载消耗一样则优先下载上传奖励较多的
sort.SliceStable(res, func(i, j int) bool {
sort.SliceStable(res, func(i, j int) bool {
var s1 = res[i]
var s2 = res[j]
if s1.IndexerId == s2.IndexerId && s1.IsPrivate && s1.DownloadVolumeFactor == s2.DownloadVolumeFactor{
if s1.IndexerId == s2.IndexerId && s1.IsPrivate && s1.DownloadVolumeFactor == s2.DownloadVolumeFactor {
return s1.UploadVolumeFactor > s2.UploadVolumeFactor
}
return false
@@ -214,12 +214,11 @@ func searchWithTorznab(db *db.Client, q string) []torznab.Result {
return res
}
func dedup(list []torznab.Result) []torznab.Result {
var res = make([]torznab.Result, 0, len(list))
seen := make(map[string]bool, 0)
for _, r := range list {
key := fmt.Sprintf("%s%s%d%d", r.Name, r.Source, r.Seeders,r.Peers)
key := fmt.Sprintf("%s%s%d%d", r.Name, r.Source, r.Seeders, r.Peers)
if seen[key] {
continue
}
@@ -227,4 +226,4 @@ func dedup(list []torznab.Result) []torznab.Result {
res = append(res, r)
}
return res
}
}