mirror of
https://github.com/simon-ding/polaris.git
synced 2026-05-30 22:47:51 +08:00
feat: check movie folder upon added
This commit is contained in:
@@ -14,6 +14,16 @@ type MovieMetadata struct {
|
|||||||
IsQingban bool
|
IsQingban bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *MovieMetadata) IsAcceptable(name string) bool {
|
||||||
|
re := regexp.MustCompile(`[^\p{L}\w\s]`)
|
||||||
|
name = re.ReplaceAllString(strings.ToLower(name), " ")
|
||||||
|
name2 := re.ReplaceAllString(strings.ToLower(m.Name), " ")
|
||||||
|
name = strings.Join(strings.Fields(name), " ")
|
||||||
|
name2 = strings.Join(strings.Fields(name2), " ")
|
||||||
|
return strings.Contains(name2, name)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
func ParseMovie(name string) *MovieMetadata {
|
func ParseMovie(name string) *MovieMetadata {
|
||||||
name = strings.Join(strings.Fields(name), " ") //remove unnessary spaces
|
name = strings.Join(strings.Fields(name), " ") //remove unnessary spaces
|
||||||
name = strings.ToLower(strings.TrimSpace(name))
|
name = strings.ToLower(strings.TrimSpace(name))
|
||||||
|
|||||||
@@ -18,6 +18,18 @@ type Metadata struct {
|
|||||||
IsSeasonPack bool
|
IsSeasonPack bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *Metadata) IsAcceptable(name string) bool {
|
||||||
|
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), " ")
|
||||||
|
return strings.Contains(nameCN, name) || strings.Contains(nameEN, name)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
func ParseTv(name string) *Metadata {
|
func ParseTv(name string) *Metadata {
|
||||||
name = strings.ToLower(name)
|
name = strings.ToLower(name)
|
||||||
name = strings.ReplaceAll(name, "\u200b", "") //remove unicode hidden character
|
name = strings.ReplaceAll(name, "\u200b", "") //remove unicode hidden character
|
||||||
|
|||||||
@@ -10,11 +10,13 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"polaris/db"
|
"polaris/db"
|
||||||
"polaris/ent"
|
"polaris/ent"
|
||||||
|
"polaris/ent/episode"
|
||||||
"polaris/ent/importlist"
|
"polaris/ent/importlist"
|
||||||
"polaris/ent/media"
|
"polaris/ent/media"
|
||||||
"polaris/ent/schema"
|
"polaris/ent/schema"
|
||||||
"polaris/log"
|
"polaris/log"
|
||||||
"polaris/pkg/importlist/plexwatchlist"
|
"polaris/pkg/importlist/plexwatchlist"
|
||||||
|
"polaris/pkg/metadata"
|
||||||
"polaris/pkg/utils"
|
"polaris/pkg/utils"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -299,6 +301,9 @@ func (c *Client) AddMovie2Watchlist(in AddWatchlistIn) (interface{}, error) {
|
|||||||
if err := c.downloadBackdrop(detail.BackdropPath, r.ID); err != nil {
|
if err := c.downloadBackdrop(detail.BackdropPath, r.ID); err != nil {
|
||||||
log.Errorf("download backdrop error: %v", err)
|
log.Errorf("download backdrop error: %v", err)
|
||||||
}
|
}
|
||||||
|
if err := c.checkMovieFolder(r); err != nil {
|
||||||
|
log.Warnf("check movie folder error: %v", err)
|
||||||
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
log.Infof("add movie %s to watchlist success", detail.Title)
|
log.Infof("add movie %s to watchlist success", detail.Title)
|
||||||
@@ -306,6 +311,33 @@ func (c *Client) AddMovie2Watchlist(in AddWatchlistIn) (interface{}, error) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Client) checkMovieFolder(m *ent.Media) error {
|
||||||
|
var storageImpl, err = c.getStorage(m.StorageID, media.MediaTypeMovie)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
files, err := storageImpl.ReadDir(m.TargetDir)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
ep, err := c.db.GetMovieDummyEpisode(m.ID)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _,f := range files {
|
||||||
|
if f.IsDir() || f.Size() < 100 * 1000 * 1000 /* 100M */{ //忽略路径和小于100M的文件
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
meta := metadata.ParseMovie(f.Name())
|
||||||
|
if meta.IsAcceptable(m.NameCn) || meta.IsAcceptable(m.NameEn) {
|
||||||
|
log.Infof("found already downloaded movie: %v", f.Name())
|
||||||
|
c.db.SetEpisodeStatus(ep.ID, episode.StatusDownloaded)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func IsJav(detail *tmdb.MovieDetails) bool {
|
func IsJav(detail *tmdb.MovieDetails) bool {
|
||||||
if detail.Adult && len(detail.ProductionCountries) > 0 && strings.ToUpper(detail.ProductionCountries[0].Iso3166_1) == "JP" {
|
if detail.Adult && len(detail.ProductionCountries) > 0 && strings.ToUpper(detail.ProductionCountries[0].Iso3166_1) == "JP" {
|
||||||
return true
|
return true
|
||||||
|
|||||||
Reference in New Issue
Block a user