mirror of
https://github.com/simon-ding/polaris.git
synced 2026-03-07 10:00:46 +08:00
feat: season plexmatch file
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"polaris/db"
|
||||
@@ -10,7 +11,7 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func (s *Server) createPlexmatchIfNotExists(seriesId int) error {
|
||||
func (s *Server) writePlexmatch(seriesId int, episodeNum int, targetDir, name string) error {
|
||||
|
||||
if !s.plexmatchEnabled() {
|
||||
return nil
|
||||
@@ -33,7 +34,21 @@ func (s *Server) createPlexmatchIfNotExists(seriesId int) error {
|
||||
log.Warnf(".plexmatch file not found, create new one: %s", series.NameEn)
|
||||
return st.WriteFile(filepath.Join(series.TargetDir, ".plexmatch"), []byte(fmt.Sprintf("tmdbid: %d\n",series.TmdbID)))
|
||||
}
|
||||
return nil
|
||||
|
||||
if episodeNum == 0 {
|
||||
return nil
|
||||
}
|
||||
buff := bytes.Buffer{}
|
||||
seasonPlex := filepath.Join(targetDir, ".plexmatch")
|
||||
data, err := st.ReadFile(seasonPlex)
|
||||
if err != nil {
|
||||
log.Infof("read season plexmatch: %v", err)
|
||||
} else {
|
||||
buff.Write(data)
|
||||
}
|
||||
buff.WriteString(fmt.Sprintf("ep: %d: %s\n", episodeNum, name))
|
||||
log.Infof("write season plexmatch file content: %s", buff.String())
|
||||
return st.WriteFile(seasonPlex, buff.Bytes())
|
||||
}
|
||||
|
||||
func (s *Server) plexmatchEnabled() bool {
|
||||
|
||||
@@ -71,9 +71,6 @@ func (s *Server) moveCompletedTask(id int) (err1 error) {
|
||||
log.Errorf("no season id: %v", r.TargetDir)
|
||||
seasonNum = -1
|
||||
}
|
||||
if err := s.createPlexmatchIfNotExists(r.MediaID); err != nil {
|
||||
log.Errorf("create .plexmatch file error: %v", err)
|
||||
}
|
||||
|
||||
if err1 != nil {
|
||||
s.db.SetHistoryStatus(r.ID, history.StatusFail)
|
||||
@@ -84,6 +81,11 @@ func (s *Server) moveCompletedTask(id int) (err1 error) {
|
||||
}
|
||||
s.sendMsg(fmt.Sprintf(message.ProcessingFailed, err))
|
||||
} else {
|
||||
// .plexmatch file
|
||||
if err := s.writePlexmatch(r.MediaID, r.EpisodeID, r.TargetDir, torrent.Name()); err != nil {
|
||||
log.Errorf("create .plexmatch file error: %v", err)
|
||||
}
|
||||
|
||||
delete(s.tasks, r.ID)
|
||||
s.db.SetHistoryStatus(r.ID, history.StatusSuccess)
|
||||
if r.EpisodeID != 0 {
|
||||
|
||||
Reference in New Issue
Block a user