feat: season plexmatch file

This commit is contained in:
Simon Ding
2024-07-30 20:01:41 +08:00
parent d4dd2da335
commit 979218f615
2 changed files with 22 additions and 5 deletions

View File

@@ -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 {

View File

@@ -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 {