mirror of
https://github.com/simon-ding/polaris.git
synced 2026-03-07 18:10:49 +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"
|
||||
|
||||
const (
|
||||
SettingTmdbApiKey = "tmdb_api_key"
|
||||
SettingLanguage = "language"
|
||||
SettingJacketUrl = "jacket_url"
|
||||
SettingJacketApiKey = "jacket_api_key"
|
||||
SettingDownloadDir = "download_dir"
|
||||
SettingLogLevel = "log_level"
|
||||
SettingProxy = "proxy"
|
||||
SettingPlexMatchEnabled = "plexmatch_enabled"
|
||||
SettingAllowQiangban = "filter_qiangban"
|
||||
SettingTmdbApiKey = "tmdb_api_key"
|
||||
SettingLanguage = "language"
|
||||
SettingJacketUrl = "jacket_url"
|
||||
SettingJacketApiKey = "jacket_api_key"
|
||||
SettingDownloadDir = "download_dir"
|
||||
SettingLogLevel = "log_level"
|
||||
SettingProxy = "proxy"
|
||||
SettingPlexMatchEnabled = "plexmatch_enabled"
|
||||
SettingNfoSupportEnabled = "nfo_support_enabled"
|
||||
SettingAllowQiangban = "filter_qiangban"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -2,6 +2,7 @@ package core
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"github.com/pkg/errors"
|
||||
"os"
|
||||
@@ -15,9 +16,95 @@ import (
|
||||
"polaris/pkg/storage"
|
||||
"polaris/pkg/utils"
|
||||
"slices"
|
||||
"strconv"
|
||||
"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 {
|
||||
|
||||
if !c.plexmatchEnabled() {
|
||||
@@ -30,7 +117,7 @@ func (c *Client) writePlexmatch(historyId int) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if series.MediaType != media.MediaTypeTv {
|
||||
if series.MediaType != media.MediaTypeTv { //.plexmatch only support tv series
|
||||
return nil
|
||||
}
|
||||
st, err := c.getStorage(series.StorageID, media.MediaTypeTv)
|
||||
@@ -104,6 +191,10 @@ func (c *Client) plexmatchEnabled() bool {
|
||||
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) {
|
||||
st := c.db.GetStorage(storageId)
|
||||
targetPath := st.TvPath
|
||||
|
||||
@@ -46,24 +46,20 @@ type Tvshow struct {
|
||||
Preview string `xml:"preview,attr"`
|
||||
} `xml:"thumb"`
|
||||
} `xml:"fanart"`
|
||||
Mpaa string `xml:"mpaa"`
|
||||
Playcount string `xml:"playcount"`
|
||||
Lastplayed string `xml:"lastplayed"`
|
||||
ID string `xml:"id"`
|
||||
Uniqueid []struct {
|
||||
Text string `xml:",chardata"`
|
||||
Type string `xml:"type,attr"`
|
||||
Default string `xml:"default,attr"`
|
||||
} `xml:"uniqueid"`
|
||||
Genre string `xml:"genre"`
|
||||
Premiered string `xml:"premiered"`
|
||||
Year string `xml:"year"`
|
||||
Status string `xml:"status"`
|
||||
Code string `xml:"code"`
|
||||
Aired string `xml:"aired"`
|
||||
Studio string `xml:"studio"`
|
||||
Trailer string `xml:"trailer"`
|
||||
Actor []struct {
|
||||
Mpaa string `xml:"mpaa"`
|
||||
Playcount string `xml:"playcount"`
|
||||
Lastplayed string `xml:"lastplayed"`
|
||||
ID string `xml:"id"`
|
||||
Uniqueid []UniqueId `xml:"uniqueid"`
|
||||
Genre string `xml:"genre"`
|
||||
Premiered string `xml:"premiered"`
|
||||
Year string `xml:"year"`
|
||||
Status string `xml:"status"`
|
||||
Code string `xml:"code"`
|
||||
Aired string `xml:"aired"`
|
||||
Studio string `xml:"studio"`
|
||||
Trailer string `xml:"trailer"`
|
||||
Actor []struct {
|
||||
Text string `xml:",chardata"`
|
||||
Name string `xml:"name"`
|
||||
Role string `xml:"role"`
|
||||
@@ -82,6 +78,11 @@ type Tvshow struct {
|
||||
Dateadded string `xml:"dateadded"`
|
||||
}
|
||||
|
||||
type UniqueId struct {
|
||||
Text string `xml:",chardata"`
|
||||
Type string `xml:"type,attr"`
|
||||
Default string `xml:"default,attr"`
|
||||
}
|
||||
|
||||
type Episodedetails struct {
|
||||
XMLName xml.Name `xml:"episodedetails"`
|
||||
@@ -148,8 +149,7 @@ type Episodedetails struct {
|
||||
Total string `xml:"total"`
|
||||
} `xml:"resume"`
|
||||
Dateadded string `xml:"dateadded"`
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
type Movie struct {
|
||||
XMLName xml.Name `xml:"movie"`
|
||||
@@ -189,18 +189,14 @@ type Movie struct {
|
||||
Preview string `xml:"preview,attr"`
|
||||
} `xml:"thumb"`
|
||||
} `xml:"fanart"`
|
||||
Mpaa string `xml:"mpaa"`
|
||||
Playcount string `xml:"playcount"`
|
||||
Lastplayed string `xml:"lastplayed"`
|
||||
ID string `xml:"id"`
|
||||
Uniqueid []struct {
|
||||
Text string `xml:",chardata"`
|
||||
Type string `xml:"type,attr"`
|
||||
Default string `xml:"default,attr"`
|
||||
} `xml:"uniqueid"`
|
||||
Genre string `xml:"genre"`
|
||||
Country []string `xml:"country"`
|
||||
Set struct {
|
||||
Mpaa string `xml:"mpaa"`
|
||||
Playcount string `xml:"playcount"`
|
||||
Lastplayed string `xml:"lastplayed"`
|
||||
ID string `xml:"id"`
|
||||
Uniqueid []UniqueId `xml:"uniqueid"`
|
||||
Genre string `xml:"genre"`
|
||||
Country []string `xml:"country"`
|
||||
Set struct {
|
||||
Text string `xml:",chardata"`
|
||||
Name string `xml:"name"`
|
||||
Overview string `xml:"overview"`
|
||||
@@ -254,4 +250,4 @@ type Movie struct {
|
||||
Order string `xml:"order"`
|
||||
Thumb string `xml:"thumb"`
|
||||
} `xml:"actor"`
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,6 +74,9 @@ func (c *Client) postTaskProcessing(id int) {
|
||||
if err := c.writePlexmatch(id); err != nil {
|
||||
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 {
|
||||
log.Infof("post tasks for id %v fail: %v", id, err)
|
||||
|
||||
Reference in New Issue
Block a user