mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 00:39:13 +00:00
Feature: Download client rules (#18)
* feat(web): add and update download client rules * feat: add and update download client rules * feat: add active downloads check * chore: update pkg * feat: deluge max active downloads * feat: use basic rules for deluge * feat: add as paused * refactor: download file if needed * feat: better errors qbit
This commit is contained in:
parent
09eb0b1716
commit
c02f16b64d
25 changed files with 628 additions and 228 deletions
|
@ -1,14 +1,11 @@
|
|||
package release
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"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"
|
||||
)
|
||||
|
||||
|
@ -31,54 +28,14 @@ func (s *service) Process(announce domain.Announce) error {
|
|||
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().Stack().Err(err).Msgf("could not download file: %v", announce.TorrentName)
|
||||
return err
|
||||
}
|
||||
|
||||
if res.FileName == "" {
|
||||
return errors.New("error downloading file, no tmp file")
|
||||
}
|
||||
|
||||
if res.Body == nil {
|
||||
log.Error().Stack().Err(err).Msgf("tmp file error - empty body: %v", announce.TorrentName)
|
||||
return errors.New("empty body")
|
||||
}
|
||||
|
||||
//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)
|
||||
err = s.actionSvc.RunActions(res.FileName, hash, *announce.Filter, announce)
|
||||
// run actions (watchFolder, test, exec, qBittorrent, Deluge etc.)
|
||||
err := s.actionSvc.RunActions(announce.Filter.Actions, announce)
|
||||
if err != nil {
|
||||
log.Error().Stack().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