mirror of
https://github.com/simon-ding/polaris.git
synced 2026-06-09 11:39:46 +08:00
fix: lowercase
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"unicode"
|
"unicode"
|
||||||
|
|
||||||
@@ -59,3 +61,26 @@ func IsNameAcceptable(name1, name2 string) bool {
|
|||||||
name2 = re.ReplaceAllString(strings.ToLower(name2), "")
|
name2 = re.ReplaceAllString(strings.ToLower(name2), "")
|
||||||
return strutil.Similarity(name1, name2, metrics.NewHamming()) > 0.1
|
return strutil.Similarity(name1, name2, metrics.NewHamming()) > 0.1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func FindSeasonEpisodeNum(name string) (se int, ep int, err error) {
|
||||||
|
seRe := regexp.MustCompile(`S\d+`)
|
||||||
|
epRe := regexp.MustCompile(`E\d+`)
|
||||||
|
nameUpper := strings.ToUpper(name)
|
||||||
|
matchEp := epRe.FindAllString(nameUpper, -1)
|
||||||
|
if len(matchEp) == 0 {
|
||||||
|
err = errors.New("no episode num")
|
||||||
|
}
|
||||||
|
matchSe := seRe.FindAllString(nameUpper, -1)
|
||||||
|
if len(matchSe) == 0 {
|
||||||
|
err = errors.New("no season num")
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return 0, 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
epNum := strings.TrimPrefix(matchEp[0], "E")
|
||||||
|
epNum1, _ := strconv.Atoi(epNum)
|
||||||
|
seNum := strings.TrimPrefix(matchSe[0], "S")
|
||||||
|
seNum1, _ := strconv.Atoi(seNum)
|
||||||
|
return seNum1, epNum1, nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -10,9 +10,7 @@ import (
|
|||||||
"polaris/log"
|
"polaris/log"
|
||||||
"polaris/pkg"
|
"polaris/pkg"
|
||||||
"polaris/pkg/storage"
|
"polaris/pkg/storage"
|
||||||
"regexp"
|
"polaris/pkg/utils"
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
@@ -150,8 +148,7 @@ func (s *Server) checkDownloadedSeriesFiles(m *ent.Media) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "read dir %s", m.TargetDir)
|
return errors.Wrapf(err, "read dir %s", m.TargetDir)
|
||||||
}
|
}
|
||||||
seRe := regexp.MustCompile(`S\d+`)
|
|
||||||
epRe := regexp.MustCompile(`E\d+`)
|
|
||||||
for _, in := range files {
|
for _, in := range files {
|
||||||
if !in.IsDir() { //season dir, ignore file
|
if !in.IsDir() { //season dir, ignore file
|
||||||
continue
|
continue
|
||||||
@@ -164,22 +161,14 @@ func (s *Server) checkDownloadedSeriesFiles(m *ent.Media) error {
|
|||||||
}
|
}
|
||||||
for _, ep := range epFiles {
|
for _, ep := range epFiles {
|
||||||
log.Infof("found file: %v", ep.Name())
|
log.Infof("found file: %v", ep.Name())
|
||||||
matchEp := epRe.FindAllString(ep.Name(), -1)
|
seNum, epNum, err := utils.FindSeasonEpisodeNum(ep.Name())
|
||||||
if len(matchEp) == 0 {
|
if err != nil {
|
||||||
|
log.Errorf("find season episode num error: %v", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
matchSe := seRe.FindAllString(ep.Name(), -1)
|
|
||||||
if len(matchSe) == 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
epNum := strings.TrimPrefix(matchEp[0], "E")
|
|
||||||
epNum1, _ := strconv.Atoi(epNum)
|
|
||||||
seNum := strings.TrimPrefix(matchSe[0], "S")
|
|
||||||
seNum1, _ := strconv.Atoi(seNum)
|
|
||||||
var dirname = filepath.Join(in.Name(), ep.Name())
|
var dirname = filepath.Join(in.Name(), ep.Name())
|
||||||
log.Infof("found match, season num %d, episode num %d", seNum1, epNum1)
|
log.Infof("found match, season num %d, episode num %d", seNum, epNum)
|
||||||
err := s.db.UpdateEpisodeFile(m.ID, seNum1, epNum1, dirname)
|
err = s.db.UpdateEpisodeFile(m.ID, seNum, epNum, dirname)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("update episode: %v", err)
|
log.Error("update episode: %v", err)
|
||||||
}
|
}
|
||||||
@@ -217,7 +206,7 @@ func (s *Server) downloadTvSeries() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Infof("cannot find resource to download for %s: %v", lastEpisode.Title, err)
|
log.Infof("cannot find resource to download for %s: %v", lastEpisode.Title, err)
|
||||||
} else {
|
} else {
|
||||||
log.Infof("begin download torrent resource: %v",name)
|
log.Infof("begin download torrent resource: %v", name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user