feat: download per media feature

This commit is contained in:
Simon Ding
2024-08-12 10:16:36 +08:00
parent 3c37948798
commit 09ff67fef7
7 changed files with 118 additions and 65 deletions

View File

@@ -7,6 +7,7 @@ import (
"polaris/log"
"polaris/pkg/torznab"
"polaris/server/core"
"strconv"
"github.com/gin-gonic/gin"
"github.com/pkg/errors"
@@ -167,3 +168,21 @@ func (s *Server) DownloadTorrent(c *gin.Context) (interface{}, error) {
}
}
func (s *Server) DownloadAll(c *gin.Context) (interface{}, error) {
ids := c.Param("id")
id, err := strconv.Atoi(ids)
if err != nil {
return nil, errors.Wrap(err, "convert")
}
m, err := s.db.GetMedia(id)
if err != nil {
return nil, errors.Wrap(err, "get media")
}
if m.MediaType == media.MediaTypeTv {
return s.core.DownloadSeriesAllEpisodes(m.ID)
}
name, err := s.core.DownloadMovieByID(m.ID)
return []string{name}, err
}