mirror of
https://github.com/idanoo/autobrr
synced 2025-07-22 16:29:12 +00:00
feat(actions): implement TorrentDataRawBytes macro (#444)
* feat(action): implement TorrentDataRawBytes * better citizen * feat(filters): external support TorrentDataRawBytes macro * feat(actions): exec add TorrentDataRawBytes macro * feat(actions): exec add TorrentDataRawBytes macro
This commit is contained in:
parent
c1d2697e18
commit
c7b372ee4e
5 changed files with 59 additions and 3 deletions
|
@ -1,6 +1,7 @@
|
|||
package action
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"time"
|
||||
|
@ -20,6 +21,16 @@ func (s *service) execCmd(action domain.Action, release domain.Release) error {
|
|||
}
|
||||
}
|
||||
|
||||
// read the file into bytes we can then use in the macro
|
||||
if len(release.TorrentDataRawBytes) == 0 && release.TorrentTmpFile != "" {
|
||||
t, err := ioutil.ReadFile(release.TorrentTmpFile)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not read torrent file: %v", release.TorrentTmpFile)
|
||||
}
|
||||
|
||||
release.TorrentDataRawBytes = t
|
||||
}
|
||||
|
||||
// check if program exists
|
||||
cmd, err := exec.LookPath(action.ExecCmd)
|
||||
if err != nil {
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"bytes"
|
||||
"crypto/tls"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
|
@ -139,6 +140,15 @@ func (s *service) watchFolder(action domain.Action, release domain.Release) erro
|
|||
}
|
||||
}
|
||||
|
||||
if len(release.TorrentDataRawBytes) == 0 {
|
||||
t, err := ioutil.ReadFile(release.TorrentTmpFile)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not read torrent file: %v", release.TorrentTmpFile)
|
||||
}
|
||||
|
||||
release.TorrentDataRawBytes = t
|
||||
}
|
||||
|
||||
m := domain.NewMacro(release)
|
||||
|
||||
// parse and replace values in argument string before continuing
|
||||
|
@ -184,12 +194,23 @@ func (s *service) watchFolder(action domain.Action, release domain.Release) erro
|
|||
}
|
||||
|
||||
func (s *service) webhook(action domain.Action, release domain.Release) error {
|
||||
if release.TorrentTmpFile == "" && strings.Contains(action.WebhookData, "TorrentPathName") {
|
||||
// if webhook data contains TorrentPathName or TorrentDataRawBytes, lets download the torrent file
|
||||
if release.TorrentTmpFile == "" && (strings.Contains(action.WebhookData, "TorrentPathName") || strings.Contains(action.WebhookData, "TorrentDataRawBytes")) {
|
||||
if err := release.DownloadTorrentFile(); err != nil {
|
||||
return errors.Wrap(err, "webhook: could not download torrent file for release: %v", release.TorrentName)
|
||||
}
|
||||
}
|
||||
|
||||
// if webhook data contains TorrentDataRawBytes, lets read the file into bytes we can then use in the macro
|
||||
if len(release.TorrentDataRawBytes) == 0 && strings.Contains(action.WebhookData, "TorrentDataRawBytes") {
|
||||
t, err := ioutil.ReadFile(release.TorrentTmpFile)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not read torrent file: %v", release.TorrentTmpFile)
|
||||
}
|
||||
|
||||
release.TorrentDataRawBytes = t
|
||||
}
|
||||
|
||||
m := domain.NewMacro(release)
|
||||
|
||||
// parse and replace values in argument string before continuing
|
||||
|
|
|
@ -14,6 +14,7 @@ type Macro struct {
|
|||
TorrentPathName string
|
||||
TorrentHash string
|
||||
TorrentUrl string
|
||||
TorrentDataRawBytes []byte
|
||||
Indexer string
|
||||
Title string
|
||||
Resolution string
|
||||
|
@ -38,6 +39,7 @@ func NewMacro(release Release) Macro {
|
|||
TorrentName: release.TorrentName,
|
||||
TorrentUrl: release.TorrentURL,
|
||||
TorrentPathName: release.TorrentTmpFile,
|
||||
TorrentDataRawBytes: release.TorrentDataRawBytes,
|
||||
TorrentHash: release.TorrentHash,
|
||||
Indexer: release.Indexer,
|
||||
Title: release.Title,
|
||||
|
|
|
@ -46,6 +46,7 @@ type Release struct {
|
|||
TorrentID string `json:"torrent_id"`
|
||||
TorrentURL string `json:"-"`
|
||||
TorrentTmpFile string `json:"-"`
|
||||
TorrentDataRawBytes []byte `json:"-"`
|
||||
TorrentHash string `json:"-"`
|
||||
TorrentName string `json:"torrent_name"` // full release name
|
||||
Size uint64 `json:"size"`
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"context"
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
@ -447,6 +448,16 @@ func (s *service) execCmd(release *domain.Release, cmd string, args string) (int
|
|||
}
|
||||
}
|
||||
|
||||
// read the file into bytes we can then use in the macro
|
||||
if len(release.TorrentDataRawBytes) == 0 && release.TorrentTmpFile != "" {
|
||||
t, err := ioutil.ReadFile(release.TorrentTmpFile)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "could not read torrent file: %v", release.TorrentTmpFile)
|
||||
}
|
||||
|
||||
release.TorrentDataRawBytes = t
|
||||
}
|
||||
|
||||
// check if program exists
|
||||
cmd, err := exec.LookPath(cmd)
|
||||
if err != nil {
|
||||
|
@ -490,13 +501,23 @@ func (s *service) execCmd(release *domain.Release, cmd string, args string) (int
|
|||
}
|
||||
|
||||
func (s *service) webhook(release *domain.Release, url string, data string) (int, error) {
|
||||
|
||||
if release.TorrentTmpFile == "" && strings.Contains(data, "TorrentPathName") {
|
||||
// if webhook data contains TorrentPathName or TorrentDataRawBytes, lets download the torrent file
|
||||
if release.TorrentTmpFile == "" && (strings.Contains(data, "TorrentPathName") || strings.Contains(data, "TorrentDataRawBytes")) {
|
||||
if err := release.DownloadTorrentFile(); err != nil {
|
||||
return 0, errors.Wrap(err, "webhook: could not download torrent file for release: %v", release.TorrentName)
|
||||
}
|
||||
}
|
||||
|
||||
// if webhook data contains TorrentDataRawBytes, lets read the file into bytes we can then use in the macro
|
||||
if len(release.TorrentDataRawBytes) == 0 && strings.Contains(data, "TorrentDataRawBytes") {
|
||||
t, err := ioutil.ReadFile(release.TorrentTmpFile)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "could not read torrent file: %v", release.TorrentTmpFile)
|
||||
}
|
||||
|
||||
release.TorrentDataRawBytes = t
|
||||
}
|
||||
|
||||
m := domain.NewMacro(*release)
|
||||
|
||||
// parse and replace values in argument string before continuing
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue