mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 08:49:13 +00:00
feat(indexers): TorrentName templating (#381)
* feat(indexers): animebytes improve parsing * Update animebytes.yaml fix music parsing * parse releaseEpisode * add torrentname template * improve releaseTags parsing * add torrentName templating conditional rendering of group and episode number add freeleech parsing * fix(indexers): improve ab releasename parsing * feat(macros): expose TorrentID, GroupID, and Size * Revert "feat(macros): expose TorrentID, GroupID, and Size" This reverts commit dae40116a1cce40f3c18d057d0af697af4407274. * change year to use parentheses Co-authored-by: ze0s <ze0s@riseup.net> Co-authored-by: varoOP <varoOP@protonmail.com>
This commit is contained in:
parent
ec07c57612
commit
48d6468503
7 changed files with 232 additions and 16 deletions
|
@ -7,6 +7,7 @@ import (
|
|||
"net/url"
|
||||
"text/template"
|
||||
|
||||
"github.com/Masterminds/sprig/v3"
|
||||
"github.com/dustin/go-humanize"
|
||||
)
|
||||
|
||||
|
@ -122,11 +123,12 @@ type IndexerParseExtract struct {
|
|||
}
|
||||
|
||||
type IndexerParseMatch struct {
|
||||
TorrentURL string `json:"torrenturl"`
|
||||
Encode []string `json:"encode"`
|
||||
TorrentURL string `json:"torrenturl"`
|
||||
TorrentName string `json:"torrentname"`
|
||||
Encode []string `json:"encode"`
|
||||
}
|
||||
|
||||
func (p *IndexerParse) ParseTorrentUrl(vars map[string]string, extraVars map[string]string, release *Release) error {
|
||||
func (p *IndexerParse) ParseMatch(vars map[string]string, extraVars map[string]string, release *Release) error {
|
||||
tmpVars := map[string]string{}
|
||||
|
||||
// copy vars to new tmp map
|
||||
|
@ -152,19 +154,37 @@ func (p *IndexerParse) ParseTorrentUrl(vars map[string]string, extraVars map[str
|
|||
}
|
||||
}
|
||||
|
||||
// setup text template to inject variables into
|
||||
tmpl, err := template.New("torrenturl").Parse(p.Match.TorrentURL)
|
||||
if err != nil {
|
||||
return errors.New("could not create torrent url template")
|
||||
if p.Match.TorrentURL != "" {
|
||||
// setup text template to inject variables into
|
||||
tmpl, err := template.New("torrenturl").Funcs(sprig.TxtFuncMap()).Parse(p.Match.TorrentURL)
|
||||
if err != nil {
|
||||
return errors.New("could not create torrent url template")
|
||||
}
|
||||
|
||||
var urlBytes bytes.Buffer
|
||||
err = tmpl.Execute(&urlBytes, &tmpVars)
|
||||
if err != nil {
|
||||
return errors.New("could not write torrent url template output")
|
||||
}
|
||||
|
||||
release.TorrentURL = urlBytes.String()
|
||||
}
|
||||
|
||||
var urlBytes bytes.Buffer
|
||||
err = tmpl.Execute(&urlBytes, &tmpVars)
|
||||
if err != nil {
|
||||
return errors.New("could not write torrent url template output")
|
||||
}
|
||||
if p.Match.TorrentName != "" {
|
||||
// setup text template to inject variables into
|
||||
tmplName, err := template.New("torrentname").Funcs(sprig.TxtFuncMap()).Parse(p.Match.TorrentName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
release.TorrentURL = urlBytes.String()
|
||||
var nameBytes bytes.Buffer
|
||||
err = tmplName.Execute(&nameBytes, &tmpVars)
|
||||
if err != nil {
|
||||
return errors.New("could not write torrent name template output")
|
||||
}
|
||||
|
||||
release.TorrentName = nameBytes.String()
|
||||
}
|
||||
|
||||
// handle cookies
|
||||
if v, ok := extraVars["cookie"]; ok {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue