mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 08:49:13 +00:00
feat(filters): add external script and webhook checks
This commit is contained in:
parent
16dd8c5419
commit
d56693cd33
17 changed files with 635 additions and 200 deletions
|
@ -1,79 +0,0 @@
|
|||
package action
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"strings"
|
||||
"text/template"
|
||||
"time"
|
||||
|
||||
"github.com/autobrr/autobrr/internal/domain"
|
||||
"github.com/autobrr/autobrr/pkg/errors"
|
||||
)
|
||||
|
||||
type Macro struct {
|
||||
TorrentName string
|
||||
TorrentPathName string
|
||||
TorrentHash string
|
||||
TorrentUrl string
|
||||
Indexer string
|
||||
Title string
|
||||
Resolution string
|
||||
Source string
|
||||
HDR string
|
||||
FilterName string
|
||||
Season int
|
||||
Episode int
|
||||
Year int
|
||||
CurrentYear int
|
||||
CurrentMonth int
|
||||
CurrentDay int
|
||||
CurrentHour int
|
||||
CurrentMinute int
|
||||
CurrentSecond int
|
||||
}
|
||||
|
||||
func NewMacro(release domain.Release) Macro {
|
||||
currentTime := time.Now()
|
||||
|
||||
ma := Macro{
|
||||
TorrentName: release.TorrentName,
|
||||
TorrentUrl: release.TorrentURL,
|
||||
TorrentPathName: release.TorrentTmpFile,
|
||||
TorrentHash: release.TorrentHash,
|
||||
Indexer: release.Indexer,
|
||||
Title: release.Title,
|
||||
Resolution: release.Resolution,
|
||||
Source: release.Source,
|
||||
HDR: strings.Join(release.HDR, ", "),
|
||||
FilterName: release.FilterName,
|
||||
Season: release.Season,
|
||||
Episode: release.Episode,
|
||||
Year: release.Year,
|
||||
CurrentYear: currentTime.Year(),
|
||||
CurrentMonth: int(currentTime.Month()),
|
||||
CurrentDay: currentTime.Day(),
|
||||
CurrentHour: currentTime.Hour(),
|
||||
CurrentMinute: currentTime.Minute(),
|
||||
CurrentSecond: currentTime.Second(),
|
||||
}
|
||||
|
||||
return ma
|
||||
}
|
||||
|
||||
// Parse takes a string and replaces valid vars
|
||||
func (m Macro) Parse(text string) (string, error) {
|
||||
|
||||
// setup template
|
||||
tmpl, err := template.New("macro").Parse(text)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "could parse macro template")
|
||||
}
|
||||
|
||||
var tpl bytes.Buffer
|
||||
err = tmpl.Execute(&tpl, m)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "could not parse macro")
|
||||
}
|
||||
|
||||
return tpl.String(), nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue