Add category associated to each torrent

This commit is contained in:
LIAUD Corentin
2023-11-22 14:08:10 +01:00
parent 286609acec
commit 8c92856595
22 changed files with 171 additions and 70 deletions

View File

@@ -37,7 +37,7 @@ func LoadTorrent(tor *Torrent) *Torrent {
return tr
}
func AddTorrent(spec *torrent.TorrentSpec, title, poster string, data string) (*Torrent, error) {
func AddTorrent(spec *torrent.TorrentSpec, title, poster string, data string, category string) (*Torrent, error) {
torr, err := NewTorrent(spec, bts)
if err != nil {
log.TLogln("error add torrent:", err)
@@ -55,6 +55,17 @@ func AddTorrent(spec *torrent.TorrentSpec, title, poster string, data string) (*
torr.Title = torr.Info().Name
}
}
// Category can be override
torr.Category = category
if torr.Category == "" {
if torDB != nil {
torr.Category = torDB.Category
} else {
torr.Category = "Unknown"
}
}
if torr.Poster == "" {
torr.Poster = poster
if torr.Poster == "" && torDB != nil {

View File

@@ -22,6 +22,7 @@ func AddTorrentDB(torr *Torrent) {
t := new(settings.TorrentDB)
t.TorrentSpec = torr.TorrentSpec
t.Title = torr.Title
t.Category = torr.Category
if torr.Data == "" {
files := new(tsFiles)
files.TorrServer.Files = torr.Status().FileStats

View File

@@ -32,6 +32,7 @@ const (
type TorrentStatus struct {
Title string `json:"title"`
Category string `json:"category"`
Poster string `json:"poster"`
Data string `json:"data,omitempty"`
Timestamp int64 `json:"timestamp"`

View File

@@ -18,9 +18,10 @@ import (
)
type Torrent struct {
Title string
Poster string
Data string
Title string
Category string
Poster string
Data string
*torrent.TorrentSpec
Stat state.TorrentStat
@@ -284,6 +285,7 @@ func (t *Torrent) Status() *state.TorrentStatus {
st.Stat = t.Stat
st.StatString = t.Stat.String()
st.Title = t.Title
st.Category = t.Category
st.Poster = t.Poster
st.Data = t.Data
st.Timestamp = t.Timestamp