mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 00:39:13 +00:00
feat: add backend
This commit is contained in:
parent
bc418ff248
commit
a838d994a6
68 changed files with 9561 additions and 0 deletions
79
internal/release/process.go
Normal file
79
internal/release/process.go
Normal file
|
@ -0,0 +1,79 @@
|
|||
package release
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/anacrolix/torrent/metainfo"
|
||||
"github.com/rs/zerolog/log"
|
||||
|
||||
"github.com/autobrr/autobrr/internal/action"
|
||||
"github.com/autobrr/autobrr/internal/client"
|
||||
"github.com/autobrr/autobrr/internal/domain"
|
||||
)
|
||||
|
||||
type Service interface {
|
||||
Process(announce domain.Announce) error
|
||||
}
|
||||
|
||||
type service struct {
|
||||
actionSvc action.Service
|
||||
}
|
||||
|
||||
func NewService(actionService action.Service) Service {
|
||||
return &service{actionSvc: actionService}
|
||||
}
|
||||
|
||||
func (s *service) Process(announce domain.Announce) error {
|
||||
log.Debug().Msgf("start to process release: %+v", announce)
|
||||
|
||||
if announce.Filter.Actions == nil {
|
||||
return fmt.Errorf("no actions for filter: %v", announce.Filter.Name)
|
||||
}
|
||||
|
||||
// check can download
|
||||
// smart episode?
|
||||
// check against rules like active downloading torrents
|
||||
|
||||
// create http client
|
||||
c := client.NewHttpClient()
|
||||
|
||||
// download torrent file
|
||||
// TODO check extra headers, cookie
|
||||
res, err := c.DownloadFile(announce.TorrentUrl, nil)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msgf("could not download file: %v", announce.TorrentName)
|
||||
return err
|
||||
}
|
||||
|
||||
if res.FileName == "" {
|
||||
return err
|
||||
}
|
||||
|
||||
//log.Debug().Msgf("downloaded torrent file: %v", res.FileName)
|
||||
|
||||
// onTorrentDownloaded
|
||||
|
||||
// match more filters like torrent size
|
||||
|
||||
// Get meta info from file to find out the hash for later use
|
||||
meta, err := metainfo.LoadFromFile(res.FileName)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msgf("metainfo could not open file: %v", res.FileName)
|
||||
return err
|
||||
}
|
||||
|
||||
// torrent info hash used for re-announce
|
||||
hash := meta.HashInfoBytes().String()
|
||||
|
||||
// take action (watchFolder, test, runProgram, qBittorrent, Deluge etc)
|
||||
// actionService
|
||||
err = s.actionSvc.RunActions(res.FileName, hash, *announce.Filter)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msgf("error running actions for filter: %v", announce.Filter.Name)
|
||||
return err
|
||||
}
|
||||
|
||||
// safe to delete tmp file
|
||||
|
||||
return nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue