mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 08:49:13 +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
|
package action
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io/ioutil"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"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
|
// check if program exists
|
||||||
cmd, err := exec.LookPath(action.ExecCmd)
|
cmd, err := exec.LookPath(action.ExecCmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"io"
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"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)
|
m := domain.NewMacro(release)
|
||||||
|
|
||||||
// parse and replace values in argument string before continuing
|
// 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 {
|
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 {
|
if err := release.DownloadTorrentFile(); err != nil {
|
||||||
return errors.Wrap(err, "webhook: could not download torrent file for release: %v", release.TorrentName)
|
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)
|
m := domain.NewMacro(release)
|
||||||
|
|
||||||
// parse and replace values in argument string before continuing
|
// parse and replace values in argument string before continuing
|
||||||
|
|
|
@ -14,6 +14,7 @@ type Macro struct {
|
||||||
TorrentPathName string
|
TorrentPathName string
|
||||||
TorrentHash string
|
TorrentHash string
|
||||||
TorrentUrl string
|
TorrentUrl string
|
||||||
|
TorrentDataRawBytes []byte
|
||||||
Indexer string
|
Indexer string
|
||||||
Title string
|
Title string
|
||||||
Resolution string
|
Resolution string
|
||||||
|
@ -38,6 +39,7 @@ func NewMacro(release Release) Macro {
|
||||||
TorrentName: release.TorrentName,
|
TorrentName: release.TorrentName,
|
||||||
TorrentUrl: release.TorrentURL,
|
TorrentUrl: release.TorrentURL,
|
||||||
TorrentPathName: release.TorrentTmpFile,
|
TorrentPathName: release.TorrentTmpFile,
|
||||||
|
TorrentDataRawBytes: release.TorrentDataRawBytes,
|
||||||
TorrentHash: release.TorrentHash,
|
TorrentHash: release.TorrentHash,
|
||||||
Indexer: release.Indexer,
|
Indexer: release.Indexer,
|
||||||
Title: release.Title,
|
Title: release.Title,
|
||||||
|
|
|
@ -46,6 +46,7 @@ type Release struct {
|
||||||
TorrentID string `json:"torrent_id"`
|
TorrentID string `json:"torrent_id"`
|
||||||
TorrentURL string `json:"-"`
|
TorrentURL string `json:"-"`
|
||||||
TorrentTmpFile string `json:"-"`
|
TorrentTmpFile string `json:"-"`
|
||||||
|
TorrentDataRawBytes []byte `json:"-"`
|
||||||
TorrentHash string `json:"-"`
|
TorrentHash string `json:"-"`
|
||||||
TorrentName string `json:"torrent_name"` // full release name
|
TorrentName string `json:"torrent_name"` // full release name
|
||||||
Size uint64 `json:"size"`
|
Size uint64 `json:"size"`
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"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
|
// check if program exists
|
||||||
cmd, err := exec.LookPath(cmd)
|
cmd, err := exec.LookPath(cmd)
|
||||||
if err != nil {
|
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) {
|
func (s *service) webhook(release *domain.Release, url string, data string) (int, error) {
|
||||||
|
// if webhook data contains TorrentPathName or TorrentDataRawBytes, lets download the torrent file
|
||||||
if release.TorrentTmpFile == "" && strings.Contains(data, "TorrentPathName") {
|
if release.TorrentTmpFile == "" && (strings.Contains(data, "TorrentPathName") || strings.Contains(data, "TorrentDataRawBytes")) {
|
||||||
if err := release.DownloadTorrentFile(); err != nil {
|
if err := release.DownloadTorrentFile(); err != nil {
|
||||||
return 0, errors.Wrap(err, "webhook: could not download torrent file for release: %v", release.TorrentName)
|
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)
|
m := domain.NewMacro(*release)
|
||||||
|
|
||||||
// parse and replace values in argument string before continuing
|
// parse and replace values in argument string before continuing
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue