mirror of
https://github.com/simon-ding/polaris.git
synced 2026-06-05 09:27:43 +08:00
feat: check new season every 12h
This commit is contained in:
29
db/db.go
29
db/db.go
@@ -162,6 +162,10 @@ func (c *Client) UpdateEpiode(episodeId int, name, overview string) error {
|
|||||||
return c.ent.Episode.Update().Where(episode.ID(episodeId)).SetTitle(name).SetOverview(overview).Exec(context.TODO())
|
return c.ent.Episode.Update().Where(episode.ID(episodeId)).SetTitle(name).SetOverview(overview).Exec(context.TODO())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Client) UpdateEpiode2(episodeId int, name, overview, airdate string) error {
|
||||||
|
return c.ent.Episode.Update().Where(episode.ID(episodeId)).SetTitle(name).SetOverview(overview).SetAirDate(airdate).Exec(context.TODO())
|
||||||
|
}
|
||||||
|
|
||||||
type MediaDetails struct {
|
type MediaDetails struct {
|
||||||
*ent.Media
|
*ent.Media
|
||||||
Episodes []*ent.Episode `json:"episodes"`
|
Episodes []*ent.Episode `json:"episodes"`
|
||||||
@@ -207,6 +211,19 @@ func (c *Client) SaveEposideDetail(d *ent.Episode) (int, error) {
|
|||||||
return ep.ID, err
|
return ep.ID, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Client) SaveEposideDetail2(d *ent.Episode) (int, error) {
|
||||||
|
ep, err := c.ent.Episode.Create().
|
||||||
|
SetAirDate(d.AirDate).
|
||||||
|
SetSeasonNumber(d.SeasonNumber).
|
||||||
|
SetEpisodeNumber(d.EpisodeNumber).
|
||||||
|
SetMediaID(d.MediaID).
|
||||||
|
SetStatus(d.Status).
|
||||||
|
SetOverview(d.Overview).
|
||||||
|
SetTitle(d.Title).Save(context.TODO())
|
||||||
|
|
||||||
|
return ep.ID, err
|
||||||
|
}
|
||||||
|
|
||||||
type TorznabSetting struct {
|
type TorznabSetting struct {
|
||||||
URL string `json:"url"`
|
URL string `json:"url"`
|
||||||
ApiKey string `json:"api_key"`
|
ApiKey string `json:"api_key"`
|
||||||
@@ -310,16 +327,15 @@ func (s *StorageInfo) ToWebDavSetting() WebdavSetting {
|
|||||||
panic("not webdav storage")
|
panic("not webdav storage")
|
||||||
}
|
}
|
||||||
return WebdavSetting{
|
return WebdavSetting{
|
||||||
URL: s.Settings["url"],
|
URL: s.Settings["url"],
|
||||||
TvPath: s.Settings["tv_path"],
|
TvPath: s.Settings["tv_path"],
|
||||||
MoviePath: s.Settings["movie_path"],
|
MoviePath: s.Settings["movie_path"],
|
||||||
User: s.Settings["user"],
|
User: s.Settings["user"],
|
||||||
Password: s.Settings["password"],
|
Password: s.Settings["password"],
|
||||||
ChangeFileHash: s.Settings["change_file_hash"],
|
ChangeFileHash: s.Settings["change_file_hash"],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
type LocalDirSetting struct {
|
type LocalDirSetting struct {
|
||||||
TvPath string `json:"tv_path"`
|
TvPath string `json:"tv_path"`
|
||||||
MoviePath string `json:"movie_path"`
|
MoviePath string `json:"movie_path"`
|
||||||
@@ -501,7 +517,6 @@ func (c *Client) TmdbIdInWatchlist(tmdb_id int) bool {
|
|||||||
return c.ent.Media.Query().Where(media.TmdbID(tmdb_id)).CountX(context.TODO()) > 0
|
return c.ent.Media.Query().Where(media.TmdbID(tmdb_id)).CountX(context.TODO()) > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (c *Client) GetDownloadHistory(mediaID int) ([]*ent.History, error) {
|
func (c *Client) GetDownloadHistory(mediaID int) ([]*ent.History, error) {
|
||||||
return c.ent.History.Query().Where(history.MediaID(mediaID)).All(context.TODO())
|
return c.ent.History.Query().Where(history.MediaID(mediaID)).All(context.TODO())
|
||||||
}
|
}
|
||||||
@@ -23,6 +23,7 @@ func (s *Server) scheduler() {
|
|||||||
s.downloadTvSeries()
|
s.downloadTvSeries()
|
||||||
s.downloadMovie()
|
s.downloadMovie()
|
||||||
})
|
})
|
||||||
|
s.mustAddCron("@every 12h", s.checkAllSeriesNewSeason)
|
||||||
s.cron.Start()
|
s.cron.Start()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -318,3 +319,49 @@ func (s *Server) downloadMovieSingleEpisode(ep *ent.Episode) error {
|
|||||||
s.db.SetEpisodeStatus(ep.ID, episode.StatusDownloading)
|
s.db.SetEpisodeStatus(ep.ID, episode.StatusDownloading)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Server) checkAllSeriesNewSeason() {
|
||||||
|
log.Infof("begin checking series all new season")
|
||||||
|
allSeries := s.db.GetMediaWatchlist(media.MediaTypeTv)
|
||||||
|
for _, series := range allSeries {
|
||||||
|
err := s.checkSeiesNewSeason(series)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("check series new season error: series name %v, error: %v", series.NameEn, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Server) checkSeiesNewSeason(media *ent.Media) error{
|
||||||
|
d, err := s.MustTMDB().GetTvDetails(media.TmdbID, s.language)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "tmdb")
|
||||||
|
}
|
||||||
|
lastsSason := d.NumberOfSeasons
|
||||||
|
seasonDetail, err := s.MustTMDB().GetSeasonDetails(media.TmdbID, lastsSason, s.language)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "tmdb season")
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, ep := range seasonDetail.Episodes {
|
||||||
|
epDb, err := s.db.GetEpisode(media.ID, ep.SeasonNumber, ep.EpisodeNumber)
|
||||||
|
if err != nil {
|
||||||
|
if ent.IsNotFound(err) {
|
||||||
|
log.Infof("add new episode: %+v", ep)
|
||||||
|
episode := &ent.Episode{
|
||||||
|
MediaID: media.ID,
|
||||||
|
SeasonNumber: ep.SeasonNumber,
|
||||||
|
EpisodeNumber: ep.EpisodeNumber,
|
||||||
|
Title: ep.Name,
|
||||||
|
Overview: ep.Overview,
|
||||||
|
AirDate: ep.AirDate,
|
||||||
|
Status: episode.StatusMissing,
|
||||||
|
}
|
||||||
|
s.db.SaveEposideDetail2(episode)
|
||||||
|
}
|
||||||
|
} else {//update episode
|
||||||
|
log.Infof("update new episode: %+v", ep)
|
||||||
|
s.db.UpdateEpiode2(epDb.ID, ep.Name, ep.Overview, ep.AirDate)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user