mirror of
https://github.com/simon-ding/polaris.git
synced 2026-05-26 20:47:57 +08:00
feat: nfo support backend
This commit is contained in:
19
db/const.go
19
db/const.go
@@ -3,15 +3,16 @@ package db
|
|||||||
var Version = "undefined"
|
var Version = "undefined"
|
||||||
|
|
||||||
const (
|
const (
|
||||||
SettingTmdbApiKey = "tmdb_api_key"
|
SettingTmdbApiKey = "tmdb_api_key"
|
||||||
SettingLanguage = "language"
|
SettingLanguage = "language"
|
||||||
SettingJacketUrl = "jacket_url"
|
SettingJacketUrl = "jacket_url"
|
||||||
SettingJacketApiKey = "jacket_api_key"
|
SettingJacketApiKey = "jacket_api_key"
|
||||||
SettingDownloadDir = "download_dir"
|
SettingDownloadDir = "download_dir"
|
||||||
SettingLogLevel = "log_level"
|
SettingLogLevel = "log_level"
|
||||||
SettingProxy = "proxy"
|
SettingProxy = "proxy"
|
||||||
SettingPlexMatchEnabled = "plexmatch_enabled"
|
SettingPlexMatchEnabled = "plexmatch_enabled"
|
||||||
SettingAllowQiangban = "filter_qiangban"
|
SettingNfoSupportEnabled = "nfo_support_enabled"
|
||||||
|
SettingAllowQiangban = "filter_qiangban"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package core
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"encoding/xml"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"os"
|
"os"
|
||||||
@@ -15,9 +16,95 @@ import (
|
|||||||
"polaris/pkg/storage"
|
"polaris/pkg/storage"
|
||||||
"polaris/pkg/utils"
|
"polaris/pkg/utils"
|
||||||
"slices"
|
"slices"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (c *Client) writeNfoFile(historyId int) error {
|
||||||
|
if !c.nfoSupportEnabled() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
his := c.db.GetHistory(historyId)
|
||||||
|
|
||||||
|
md, err := c.db.GetMedia(his.MediaID)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if md.MediaType == media.MediaTypeTv { //tvshow.nfo
|
||||||
|
st, err := c.getStorage(md.StorageID, media.MediaTypeTv)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "get storage")
|
||||||
|
}
|
||||||
|
|
||||||
|
nfoPath := filepath.Join(md.TargetDir, "tvshow.nfo")
|
||||||
|
_, err = st.ReadFile(nfoPath)
|
||||||
|
if err != nil {
|
||||||
|
log.Infof("tvshow.nfo file missing, create new one, tv series name: %s", md.NameEn)
|
||||||
|
show := Tvshow{
|
||||||
|
Title: md.NameCn,
|
||||||
|
Originaltitle: md.OriginalName,
|
||||||
|
Showtitle: md.NameCn,
|
||||||
|
Plot: md.Overview,
|
||||||
|
ID: strconv.Itoa(md.TmdbID),
|
||||||
|
Uniqueid: []UniqueId{
|
||||||
|
{
|
||||||
|
Text: strconv.Itoa(md.TmdbID),
|
||||||
|
Type: "tmdb",
|
||||||
|
Default: "true",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Text: md.ImdbID,
|
||||||
|
Type: "imdb",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
data, err := xml.Marshal(&show)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "xml marshal")
|
||||||
|
}
|
||||||
|
return st.WriteFile(nfoPath, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if md.MediaType == media.MediaTypeMovie { //movie.nfo
|
||||||
|
st, err := c.getStorage(md.StorageID, media.MediaTypeMovie)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "get storage")
|
||||||
|
}
|
||||||
|
|
||||||
|
nfoPath := filepath.Join(md.TargetDir, "movie.nfo")
|
||||||
|
_, err = st.ReadFile(nfoPath)
|
||||||
|
if err != nil {
|
||||||
|
log.Infof("movie.nfo file missing, create new one, tv series name: %s", md.NameEn)
|
||||||
|
nfoData := Movie{
|
||||||
|
Title: md.NameCn,
|
||||||
|
Originaltitle: md.OriginalName,
|
||||||
|
Sorttitle: md.NameCn,
|
||||||
|
Plot: md.Overview,
|
||||||
|
ID: strconv.Itoa(md.TmdbID),
|
||||||
|
Uniqueid: []UniqueId{
|
||||||
|
{
|
||||||
|
Text: strconv.Itoa(md.TmdbID),
|
||||||
|
Type: "tmdb",
|
||||||
|
Default: "true",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Text: md.ImdbID,
|
||||||
|
Type: "imdb",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
data, err := xml.Marshal(&nfoData)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "xml marshal")
|
||||||
|
}
|
||||||
|
return st.WriteFile(nfoPath, data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Client) writePlexmatch(historyId int) error {
|
func (c *Client) writePlexmatch(historyId int) error {
|
||||||
|
|
||||||
if !c.plexmatchEnabled() {
|
if !c.plexmatchEnabled() {
|
||||||
@@ -30,7 +117,7 @@ func (c *Client) writePlexmatch(historyId int) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if series.MediaType != media.MediaTypeTv {
|
if series.MediaType != media.MediaTypeTv { //.plexmatch only support tv series
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
st, err := c.getStorage(series.StorageID, media.MediaTypeTv)
|
st, err := c.getStorage(series.StorageID, media.MediaTypeTv)
|
||||||
@@ -104,6 +191,10 @@ func (c *Client) plexmatchEnabled() bool {
|
|||||||
return c.db.GetSetting(db.SettingPlexMatchEnabled) == "true"
|
return c.db.GetSetting(db.SettingPlexMatchEnabled) == "true"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Client) nfoSupportEnabled() bool {
|
||||||
|
return c.db.GetSetting(db.SettingNfoSupportEnabled) == "true"
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Client) getStorage(storageId int, mediaType media.MediaType) (storage.Storage, error) {
|
func (c *Client) getStorage(storageId int, mediaType media.MediaType) (storage.Storage, error) {
|
||||||
st := c.db.GetStorage(storageId)
|
st := c.db.GetStorage(storageId)
|
||||||
targetPath := st.TvPath
|
targetPath := st.TvPath
|
||||||
|
|||||||
@@ -46,24 +46,20 @@ type Tvshow struct {
|
|||||||
Preview string `xml:"preview,attr"`
|
Preview string `xml:"preview,attr"`
|
||||||
} `xml:"thumb"`
|
} `xml:"thumb"`
|
||||||
} `xml:"fanart"`
|
} `xml:"fanart"`
|
||||||
Mpaa string `xml:"mpaa"`
|
Mpaa string `xml:"mpaa"`
|
||||||
Playcount string `xml:"playcount"`
|
Playcount string `xml:"playcount"`
|
||||||
Lastplayed string `xml:"lastplayed"`
|
Lastplayed string `xml:"lastplayed"`
|
||||||
ID string `xml:"id"`
|
ID string `xml:"id"`
|
||||||
Uniqueid []struct {
|
Uniqueid []UniqueId `xml:"uniqueid"`
|
||||||
Text string `xml:",chardata"`
|
Genre string `xml:"genre"`
|
||||||
Type string `xml:"type,attr"`
|
Premiered string `xml:"premiered"`
|
||||||
Default string `xml:"default,attr"`
|
Year string `xml:"year"`
|
||||||
} `xml:"uniqueid"`
|
Status string `xml:"status"`
|
||||||
Genre string `xml:"genre"`
|
Code string `xml:"code"`
|
||||||
Premiered string `xml:"premiered"`
|
Aired string `xml:"aired"`
|
||||||
Year string `xml:"year"`
|
Studio string `xml:"studio"`
|
||||||
Status string `xml:"status"`
|
Trailer string `xml:"trailer"`
|
||||||
Code string `xml:"code"`
|
Actor []struct {
|
||||||
Aired string `xml:"aired"`
|
|
||||||
Studio string `xml:"studio"`
|
|
||||||
Trailer string `xml:"trailer"`
|
|
||||||
Actor []struct {
|
|
||||||
Text string `xml:",chardata"`
|
Text string `xml:",chardata"`
|
||||||
Name string `xml:"name"`
|
Name string `xml:"name"`
|
||||||
Role string `xml:"role"`
|
Role string `xml:"role"`
|
||||||
@@ -82,6 +78,11 @@ type Tvshow struct {
|
|||||||
Dateadded string `xml:"dateadded"`
|
Dateadded string `xml:"dateadded"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type UniqueId struct {
|
||||||
|
Text string `xml:",chardata"`
|
||||||
|
Type string `xml:"type,attr"`
|
||||||
|
Default string `xml:"default,attr"`
|
||||||
|
}
|
||||||
|
|
||||||
type Episodedetails struct {
|
type Episodedetails struct {
|
||||||
XMLName xml.Name `xml:"episodedetails"`
|
XMLName xml.Name `xml:"episodedetails"`
|
||||||
@@ -150,7 +151,6 @@ type Episodedetails struct {
|
|||||||
Dateadded string `xml:"dateadded"`
|
Dateadded string `xml:"dateadded"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
type Movie struct {
|
type Movie struct {
|
||||||
XMLName xml.Name `xml:"movie"`
|
XMLName xml.Name `xml:"movie"`
|
||||||
Text string `xml:",chardata"`
|
Text string `xml:",chardata"`
|
||||||
@@ -189,18 +189,14 @@ type Movie struct {
|
|||||||
Preview string `xml:"preview,attr"`
|
Preview string `xml:"preview,attr"`
|
||||||
} `xml:"thumb"`
|
} `xml:"thumb"`
|
||||||
} `xml:"fanart"`
|
} `xml:"fanart"`
|
||||||
Mpaa string `xml:"mpaa"`
|
Mpaa string `xml:"mpaa"`
|
||||||
Playcount string `xml:"playcount"`
|
Playcount string `xml:"playcount"`
|
||||||
Lastplayed string `xml:"lastplayed"`
|
Lastplayed string `xml:"lastplayed"`
|
||||||
ID string `xml:"id"`
|
ID string `xml:"id"`
|
||||||
Uniqueid []struct {
|
Uniqueid []UniqueId `xml:"uniqueid"`
|
||||||
Text string `xml:",chardata"`
|
Genre string `xml:"genre"`
|
||||||
Type string `xml:"type,attr"`
|
Country []string `xml:"country"`
|
||||||
Default string `xml:"default,attr"`
|
Set struct {
|
||||||
} `xml:"uniqueid"`
|
|
||||||
Genre string `xml:"genre"`
|
|
||||||
Country []string `xml:"country"`
|
|
||||||
Set struct {
|
|
||||||
Text string `xml:",chardata"`
|
Text string `xml:",chardata"`
|
||||||
Name string `xml:"name"`
|
Name string `xml:"name"`
|
||||||
Overview string `xml:"overview"`
|
Overview string `xml:"overview"`
|
||||||
|
|||||||
@@ -74,6 +74,9 @@ func (c *Client) postTaskProcessing(id int) {
|
|||||||
if err := c.writePlexmatch(id); err != nil {
|
if err := c.writePlexmatch(id); err != nil {
|
||||||
log.Errorf("write plexmatch file error: %v", err)
|
log.Errorf("write plexmatch file error: %v", err)
|
||||||
}
|
}
|
||||||
|
if err := c.writeNfoFile(id); err != nil {
|
||||||
|
log.Errorf("write nfo file error: %v", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if err := c.moveCompletedTask(id); err != nil {
|
if err := c.moveCompletedTask(id); err != nil {
|
||||||
log.Infof("post tasks for id %v fail: %v", id, err)
|
log.Infof("post tasks for id %v fail: %v", id, err)
|
||||||
|
|||||||
Reference in New Issue
Block a user