mirror of
https://github.com/simon-ding/polaris.git
synced 2026-04-21 19:27:30 +08:00
basic find download ability
This commit is contained in:
@@ -4,8 +4,8 @@ import (
|
||||
"fmt"
|
||||
"polaris/db"
|
||||
"polaris/log"
|
||||
"polaris/pkg/downloader"
|
||||
"polaris/pkg/torznab"
|
||||
"polaris/pkg/transmission"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/pkg/errors"
|
||||
@@ -49,9 +49,9 @@ func (s *Server) AddTorznabInfo(c *gin.Context) (interface{}, error) {
|
||||
}
|
||||
|
||||
type searchAndDownloadIn struct {
|
||||
Title string `json:"title"`
|
||||
Season int `json:"season"`
|
||||
Episode int `json:"episode"`
|
||||
Title string `json:"title"`
|
||||
Season int `json:"season"`
|
||||
Episode int `json:"episode"`
|
||||
}
|
||||
|
||||
func (s *Server) SearchAndDownload(c *gin.Context) (interface{}, error) {
|
||||
@@ -59,13 +59,43 @@ func (s *Server) SearchAndDownload(c *gin.Context) (interface{}, error) {
|
||||
if err := c.ShouldBindJSON(&in); err != nil {
|
||||
return nil, errors.Wrap(err, "bind json")
|
||||
}
|
||||
tr := s.db.GetTransmission()
|
||||
trc, err := transmission.NewClient(tr.URL, tr.User, tr.Password)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "connect transmission")
|
||||
}
|
||||
|
||||
res := s.searchTvWithTorznab(in.Title, in.Season, in.Episode)
|
||||
r1 := res[0]
|
||||
t, err := downloader.DownloadByMagnet(r1.Magnet, "~")
|
||||
log.Infof("found resource to download: %v", r1)
|
||||
torrent, err := trc.Download(r1.Magnet)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "download torrent")
|
||||
return nil, errors.Wrap(err, "downloading")
|
||||
}
|
||||
s.tasks[r1.Name] = t
|
||||
s.tasks[r1.Name] = torrent
|
||||
// t, err := downloader.DownloadByMagnet(r1.Magnet, "~")
|
||||
// if err != nil {
|
||||
// return nil, errors.Wrap(err, "download torrent")
|
||||
// }
|
||||
log.Errorf("success add %s to download task", r1.Name)
|
||||
return nil, nil
|
||||
}
|
||||
}
|
||||
|
||||
type downloadClientIn struct {
|
||||
Name string `json:"name"`
|
||||
URL string `json:"url"`
|
||||
User string `json:"user"`
|
||||
Password string `json:"password"`
|
||||
Implementation string `json:"implementation"`
|
||||
}
|
||||
|
||||
func (s *Server) AddDownloadClient(c *gin.Context) (interface{}, error) {
|
||||
var in downloadClientIn
|
||||
if err := c.ShouldBindJSON(&in); err != nil {
|
||||
return nil, errors.Wrap(err, "bind json")
|
||||
}
|
||||
if err := s.db.SaveTransmission(in.Name, in.URL, in.User, in.Password); err != nil {
|
||||
return nil, errors.Wrap(err, "save transmission")
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user