canape/backend/models/torrent_video.go
Grégoire Delattre e41c9bfdfa Return the video details embedded in the torrents
This requires the eventers to have the app env
2020-04-11 17:45:33 +02:00

43 lines
995 B
Go

package models
import (
"github.com/odwrtw/papi"
polochon "github.com/odwrtw/polochon/lib"
"github.com/sirupsen/logrus"
)
// TorrentVideo reprensents a torrent embeding the video inforamtions
type TorrentVideo struct {
*papi.Torrent
Video polochon.Video `json:"video,omitempty"`
}
// NewTorrentVideo returns a new TorrentVideo
func NewTorrentVideo(t *papi.Torrent) *TorrentVideo {
torrent := &polochon.Torrent{
ImdbID: t.ImdbID,
Type: polochon.VideoType(t.Type),
Quality: polochon.Quality(t.Quality),
Season: t.Season,
Episode: t.Episode,
}
return &TorrentVideo{
Torrent: t,
Video: torrent.Video(),
}
}
// Update updates the Torrent video with the database details
func (t *TorrentVideo) Update(detailer polochon.Detailer, log *logrus.Entry) {
if t.Video == nil {
return
}
// TODO: refresh the video in db if not found
err := detailer.GetDetails(t.Video, log)
if err != nil {
log.WithField("function", "TorrentVideo.Update").Errorf(err.Error())
}
}