mirror of
https://github.com/simon-ding/polaris.git
synced 2026-06-09 19:47:47 +08:00
feat: search with alternative titles
This commit is contained in:
@@ -3,6 +3,7 @@ package core
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"polaris/db"
|
"polaris/db"
|
||||||
|
"polaris/ent"
|
||||||
"polaris/ent/media"
|
"polaris/ent/media"
|
||||||
"polaris/log"
|
"polaris/log"
|
||||||
"polaris/pkg/metadata"
|
"polaris/pkg/metadata"
|
||||||
@@ -26,6 +27,51 @@ type SearchParam struct {
|
|||||||
FilterQiangban bool //for movie, 是否过滤枪版电影
|
FilterQiangban bool //for movie, 是否过滤枪版电影
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func names2Query(media *ent.Media) []string {
|
||||||
|
var names = []string{media.NameEn}
|
||||||
|
|
||||||
|
if media.NameCn != "" {
|
||||||
|
hasName := false
|
||||||
|
for _, n := range names {
|
||||||
|
if media.NameCn == n {
|
||||||
|
hasName = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !hasName {
|
||||||
|
names = append(names, media.NameCn)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if media.OriginalName != "" {
|
||||||
|
hasName := false
|
||||||
|
for _, n := range names {
|
||||||
|
if media.OriginalName == n {
|
||||||
|
hasName = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !hasName {
|
||||||
|
names = append(names, media.OriginalName)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, t := range media.AlternativeTitles {
|
||||||
|
if (t.Iso3166_1 == "CN" || t.Iso3166_1 == "US") && t.Type == "" {
|
||||||
|
hasName := false
|
||||||
|
for _, n := range names {
|
||||||
|
if t.Title == n {
|
||||||
|
hasName = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !hasName {
|
||||||
|
names = append(names, t.Title)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.Debugf("name to query %+v", names)
|
||||||
|
return names
|
||||||
|
}
|
||||||
|
|
||||||
func SearchTvSeries(db1 *db.Client, param *SearchParam) ([]torznab.Result, error) {
|
func SearchTvSeries(db1 *db.Client, param *SearchParam) ([]torznab.Result, error) {
|
||||||
series := db1.GetMediaDetails(param.MediaId)
|
series := db1.GetMediaDetails(param.MediaId)
|
||||||
if series == nil {
|
if series == nil {
|
||||||
@@ -38,7 +84,9 @@ func SearchTvSeries(db1 *db.Client, param *SearchParam) ([]torznab.Result, error
|
|||||||
}
|
}
|
||||||
log.Debugf("check tv series %s, season %d, episode %v", series.NameEn, param.SeasonNum, param.Episodes)
|
log.Debugf("check tv series %s, season %d, episode %v", series.NameEn, param.SeasonNum, param.Episodes)
|
||||||
|
|
||||||
res := searchWithTorznab(db1, prowlarr.TV, series.NameEn, series.NameCn, series.OriginalName)
|
names := names2Query(series.Media)
|
||||||
|
|
||||||
|
res := searchWithTorznab(db1, prowlarr.TV, names...)
|
||||||
|
|
||||||
var filtered []torznab.Result
|
var filtered []torznab.Result
|
||||||
lo:
|
lo:
|
||||||
@@ -198,8 +246,9 @@ func SearchMovie(db1 *db.Client, param *SearchParam) ([]torznab.Result, error) {
|
|||||||
log.Warnf("get tv size limiter: %v", err)
|
log.Warnf("get tv size limiter: %v", err)
|
||||||
limiter = &db.MediaSizeLimiter{}
|
limiter = &db.MediaSizeLimiter{}
|
||||||
}
|
}
|
||||||
|
names := names2Query(movieDetail.Media)
|
||||||
|
|
||||||
res := searchWithTorznab(db1, prowlarr.Movie, movieDetail.NameEn, movieDetail.NameCn, movieDetail.OriginalName)
|
res := searchWithTorznab(db1, prowlarr.Movie, names...)
|
||||||
if movieDetail.Extras.IsJav() {
|
if movieDetail.Extras.IsJav() {
|
||||||
res1 := searchWithTorznab(db1, prowlarr.Movie, movieDetail.Extras.JavId)
|
res1 := searchWithTorznab(db1, prowlarr.Movie, movieDetail.Extras.JavId)
|
||||||
res = append(res, res1...)
|
res = append(res, res1...)
|
||||||
@@ -361,5 +410,7 @@ func torrentNameOk(detail *db.MediaDetails, tester NameTester) bool {
|
|||||||
if detail.Extras.IsJav() && tester.IsAcceptable(detail.Extras.JavId) {
|
if detail.Extras.IsJav() && tester.IsAcceptable(detail.Extras.JavId) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return tester.IsAcceptable(detail.NameCn, detail.NameEn, detail.OriginalName)
|
names := names2Query(detail.Media)
|
||||||
|
|
||||||
|
return tester.IsAcceptable(names...)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user