mirror of
https://github.com/simon-ding/polaris.git
synced 2026-06-07 10:37:39 +08:00
feat: japan anime support
This commit is contained in:
@@ -3,9 +3,8 @@ package core
|
||||
import (
|
||||
"fmt"
|
||||
"polaris/db"
|
||||
"polaris/ent"
|
||||
"polaris/ent/media"
|
||||
"polaris/log"
|
||||
"polaris/pkg/metadata"
|
||||
"polaris/pkg/torznab"
|
||||
"polaris/pkg/utils"
|
||||
"sort"
|
||||
@@ -16,33 +15,7 @@ import (
|
||||
)
|
||||
|
||||
func SearchSeasonPackage(db1 *db.Client, seriesId, seasonNum int, checkResolution bool) ([]torznab.Result, error) {
|
||||
series := db1.GetMediaDetails(seriesId)
|
||||
if series == nil {
|
||||
return nil, fmt.Errorf("no tv series of id %v", seriesId)
|
||||
}
|
||||
q := fmt.Sprintf("%s S%02d", series.NameEn, seasonNum)
|
||||
|
||||
res := searchWithTorznab(db1, q)
|
||||
if len(res) == 0 {
|
||||
return nil, fmt.Errorf("no resource found")
|
||||
}
|
||||
var filtered []torznab.Result
|
||||
for _, r := range res {
|
||||
if !isNameAcceptable(r.Name, series.Media, seasonNum, -1) {
|
||||
continue
|
||||
}
|
||||
if checkResolution && !IsWantedResolution(r.Name, series.Resolution) {
|
||||
continue
|
||||
}
|
||||
|
||||
filtered = append(filtered, r)
|
||||
|
||||
}
|
||||
|
||||
if len(filtered) == 0 {
|
||||
return nil, errors.New("no resource found")
|
||||
}
|
||||
return filtered, nil
|
||||
return SearchEpisode(db1, seriesId, seasonNum, -1, checkResolution)
|
||||
}
|
||||
|
||||
func SearchEpisode(db1 *db.Client, seriesId, seasonNum, episodeNum int, checkResolution bool) ([]torznab.Result, error) {
|
||||
@@ -51,23 +24,30 @@ func SearchEpisode(db1 *db.Client, seriesId, seasonNum, episodeNum int, checkRes
|
||||
return nil, fmt.Errorf("no tv series of id %v", seriesId)
|
||||
}
|
||||
|
||||
q := fmt.Sprintf("%s S%02dE%02d", series.NameEn, seasonNum, episodeNum)
|
||||
res := searchWithTorznab(db1, q)
|
||||
if len(res) == 0 {
|
||||
return nil, fmt.Errorf("no resource found")
|
||||
}
|
||||
res := searchWithTorznab(db1, series.NameEn)
|
||||
resCn := searchWithTorznab(db1, series.NameCn)
|
||||
res = append(res, resCn...)
|
||||
|
||||
var filtered []torznab.Result
|
||||
for _, r := range res {
|
||||
if !isNameAcceptable(r.Name, series.Media, seasonNum, episodeNum) {
|
||||
meta := metadata.ParseTv(r.Name)
|
||||
if meta.Season != seasonNum {
|
||||
continue
|
||||
}
|
||||
if checkResolution && !IsWantedResolution(r.Name, series.Resolution) {
|
||||
if episodeNum != -1 && meta.Episode != episodeNum { //not season pack
|
||||
continue
|
||||
}
|
||||
if checkResolution && meta.Resolution != series.Resolution.String() {
|
||||
continue
|
||||
}
|
||||
if !utils.IsNameAcceptable(meta.NameEn, series.NameEn) && !utils.IsNameAcceptable(meta.NameCn, series.NameCn) {
|
||||
continue
|
||||
}
|
||||
|
||||
filtered = append(filtered, r)
|
||||
}
|
||||
if len(filtered) == 0 {
|
||||
return nil, errors.New("no resource found")
|
||||
}
|
||||
|
||||
return filtered, nil
|
||||
|
||||
@@ -89,10 +69,16 @@ func SearchMovie(db1 *db.Client, movieId int, checkResolution bool) ([]torznab.R
|
||||
}
|
||||
var filtered []torznab.Result
|
||||
for _, r := range res {
|
||||
if !isNameAcceptable(r.Name, movieDetail.Media, -1, -1) {
|
||||
meta := metadata.ParseMovie(r.Name)
|
||||
if !utils.IsNameAcceptable(meta.NameEn, movieDetail.NameEn) {
|
||||
continue
|
||||
}
|
||||
if checkResolution && !IsWantedResolution(r.Name, movieDetail.Resolution) {
|
||||
if checkResolution && meta.Resolution != movieDetail.Resolution.String() {
|
||||
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
|
||||
}
|
||||
|
||||
@@ -127,53 +113,3 @@ func searchWithTorznab(db *db.Client, q string) []torznab.Result {
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
func isNameAcceptable(torrentName string, m *ent.Media, seasonNum, episodeNum int) bool {
|
||||
if !utils.IsNameAcceptable(torrentName, m.NameCn) && !utils.IsNameAcceptable(torrentName, m.NameEn) && !utils.IsNameAcceptable(torrentName, m.OriginalName){
|
||||
return false //name not match
|
||||
}
|
||||
|
||||
ss := strings.Split(m.AirDate, "-")[0]
|
||||
year, _ := strconv.Atoi(ss)
|
||||
if m.MediaType == media.MediaTypeMovie {
|
||||
if !strings.Contains(torrentName, strconv.Itoa(year)) && !strings.Contains(torrentName, strconv.Itoa(year+1)) && !strings.Contains(torrentName, strconv.Itoa(year-1)) {
|
||||
return false //not the same movie, if year is not correct
|
||||
}
|
||||
}
|
||||
|
||||
if m.MediaType == media.MediaTypeTv {
|
||||
if episodeNum != -1 {
|
||||
se := fmt.Sprintf("S%02dE%02d", seasonNum, episodeNum)
|
||||
if !utils.ContainsIgnoreCase(torrentName, se) {
|
||||
return false
|
||||
}
|
||||
} else {
|
||||
//season package
|
||||
if !utils.IsSeasonPackageName(torrentName) {
|
||||
return false
|
||||
}
|
||||
|
||||
seNum, err := utils.FindSeasonPackageInfo(torrentName)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
if seNum != seasonNum {
|
||||
return false
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func IsWantedResolution(name string, res media.Resolution) bool {
|
||||
switch res {
|
||||
case media.Resolution720p:
|
||||
return utils.ContainsIgnoreCase(name, "720p")
|
||||
case media.Resolution1080p:
|
||||
return utils.ContainsIgnoreCase(name, "1080p")
|
||||
case media.Resolution4k:
|
||||
return utils.ContainsIgnoreCase(name, "4k") || utils.ContainsIgnoreCase(name, "2160p")
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -62,7 +62,7 @@ func (s *Server) SuggestedSeriesFolderName(c *gin.Context) (interface{}, error)
|
||||
}
|
||||
name = fmt.Sprintf("%s %s", name, originalName)
|
||||
|
||||
if !utils.IsChineseChar(name) {
|
||||
if !utils.ContainsChineseChar(name) {
|
||||
name = originalName
|
||||
}
|
||||
if year != "" {
|
||||
|
||||
Reference in New Issue
Block a user