feat: better jav search support

This commit is contained in:
Simon Ding
2024-08-19 17:39:37 +08:00
parent 821d6859ff
commit ff63084014
13 changed files with 235 additions and 8 deletions

View File

@@ -160,6 +160,10 @@ func SearchMovie(db1 *db.Client, param *SearchParam) ([]torznab.Result, error) {
}
res := searchWithTorznab(db1, movieDetail.NameEn, movieDetail.NameCn, movieDetail.OriginalName)
if movieDetail.Extras.IsJav {
res1 := searchWithTorznab(db1, movieDetail.Extras.JavId)
res = append(res, res1...)
}
if len(res) == 0 {
return nil, fmt.Errorf("no resource found")
@@ -176,10 +180,12 @@ func SearchMovie(db1 *db.Client, param *SearchParam) ([]torznab.Result, error) {
if !torrentNameOk(movieDetail, r.Name) {
continue
}
ss := strings.Split(movieDetail.AirDate, "-")[0]
year, _ := strconv.Atoi(ss)
if meta.Year != year && meta.Year != year-1 && meta.Year != year+1 { //year not match
continue
if !movieDetail.Extras.IsJav {
ss := strings.Split(movieDetail.AirDate, "-")[0]
year, _ := strconv.Atoi(ss)
if meta.Year != year && meta.Year != year-1 && meta.Year != year+1 { //year not match
continue
}
}
}
@@ -295,6 +301,9 @@ func dedup(list []torznab.Result) []torznab.Result {
}
func torrentNameOk(detail *db.MediaDetails, torrentName string) bool {
if detail.Extras.IsJav && isNameAcceptable(torrentName, detail.Extras.JavId) {
return true
}
return isNameAcceptable(torrentName, detail.NameCn) || isNameAcceptable(torrentName, detail.NameEn) ||
isNameAcceptable(torrentName, detail.OriginalName)
}

View File

@@ -13,6 +13,7 @@ import (
"polaris/ent/schema"
"polaris/log"
"strconv"
"strings"
"time"
tmdb "github.com/cyruzin/golang-tmdb"
@@ -174,6 +175,26 @@ func (s *Server) AddTv2Watchlist(c *gin.Context) (interface{}, error) {
return nil, nil
}
func isJav(detail *tmdb.MovieDetails) bool {
if detail.Adult && len(detail.ProductionCountries)> 0 && strings.ToUpper(detail.ProductionCountries[0].Iso3166_1) == "JP" {
return true
}
return false
}
func (s *Server) getJavid(id int) string {
alters, err := s.MustTMDB().GetMovieAlternativeTitles(id, s.language)
if err != nil {
return ""
}
for _, t := range alters.Titles {
if t.Iso3166_1 == "JP" && t.Type == "" {
return t.Title
}
}
return ""
}
func (s *Server) AddMovie2Watchlist(c *gin.Context) (interface{}, error) {
var in addWatchlistIn
if err := c.ShouldBindJSON(&in); err != nil {
@@ -196,6 +217,7 @@ func (s *Server) AddMovie2Watchlist(c *gin.Context) (interface{}, error) {
}
log.Infof("find detail for movie id %d: %v", in.TmdbID, detail)
epid, err := s.db.SaveEposideDetail(&ent.Episode{
SeasonNumber: 1,
EpisodeNumber: 1,
@@ -209,7 +231,7 @@ func (s *Server) AddMovie2Watchlist(c *gin.Context) (interface{}, error) {
}
log.Infof("added dummy episode for movie: %v", nameEn)
r, err := s.db.AddMediaWatchlist(&ent.Media{
movie := ent.Media{
TmdbID: int(detail.ID),
ImdbID: detail.IMDbID,
MediaType: media.MediaTypeMovie,
@@ -222,7 +244,19 @@ func (s *Server) AddMovie2Watchlist(c *gin.Context) (interface{}, error) {
StorageID: in.StorageID,
TargetDir: in.Folder,
Limiter: schema.MediaLimiter{SizeMin: in.SizeMin, SizeMax: in.SizeMax},
}, []int{epid})
}
if isJav(detail) {
javid := s.getJavid(in.TmdbID)
movie.Extras = schema.MediaExtras{
IsJav: true,
JavId: javid,
}
}
if detail.Adult {
movie.Extras.IsAdult = true
}
r, err := s.db.AddMediaWatchlist(&movie, []int{epid})
if err != nil {
return nil, errors.Wrap(err, "add to list")
}