mirror of
https://github.com/simon-ding/polaris.git
synced 2026-05-28 05:27:41 +08:00
feat: season plexmatch file
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"polaris/db"
|
"polaris/db"
|
||||||
@@ -10,7 +11,7 @@ import (
|
|||||||
"github.com/pkg/errors"
|
"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() {
|
if !s.plexmatchEnabled() {
|
||||||
return nil
|
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)
|
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 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 {
|
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)
|
log.Errorf("no season id: %v", r.TargetDir)
|
||||||
seasonNum = -1
|
seasonNum = -1
|
||||||
}
|
}
|
||||||
if err := s.createPlexmatchIfNotExists(r.MediaID); err != nil {
|
|
||||||
log.Errorf("create .plexmatch file error: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err1 != nil {
|
if err1 != nil {
|
||||||
s.db.SetHistoryStatus(r.ID, history.StatusFail)
|
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))
|
s.sendMsg(fmt.Sprintf(message.ProcessingFailed, err))
|
||||||
} else {
|
} 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)
|
delete(s.tasks, r.ID)
|
||||||
s.db.SetHistoryStatus(r.ID, history.StatusSuccess)
|
s.db.SetHistoryStatus(r.ID, history.StatusSuccess)
|
||||||
if r.EpisodeID != 0 {
|
if r.EpisodeID != 0 {
|
||||||
|
|||||||
Reference in New Issue
Block a user