mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 08:49:13 +00:00
feat(releases): add info url link to releases list (#683)
* feat(indexers): definitions add infourl to irc parsing * feat(indexers): add infourl to releases * fix(indexers): fix info urls * fix(indexers): update btn
This commit is contained in:
parent
870e109f6c
commit
4c83787a0b
68 changed files with 189 additions and 13 deletions
|
@ -178,10 +178,12 @@ type IndexerIRCParseLine struct {
|
|||
type IndexerIRCParseMatch struct {
|
||||
TorrentURL string `json:"torrenturl"`
|
||||
TorrentName string `json:"torrentname"`
|
||||
InfoURL string `json:"infourl"`
|
||||
Encode []string `json:"encode"`
|
||||
}
|
||||
|
||||
type IndexerIRCParseMatched struct {
|
||||
InfoURL string
|
||||
TorrentURL string
|
||||
TorrentName string
|
||||
}
|
||||
|
@ -198,6 +200,45 @@ func (p *IndexerIRCParse) ParseMatch(baseURL string, vars map[string]string) (*I
|
|||
}
|
||||
}
|
||||
|
||||
if p.Match.InfoURL != "" {
|
||||
// setup text template to inject variables into
|
||||
tmpl, err := template.New("infourl").Funcs(sprig.TxtFuncMap()).Parse(p.Match.InfoURL)
|
||||
if err != nil {
|
||||
return nil, errors.New("could not create info url template")
|
||||
}
|
||||
|
||||
var urlBytes bytes.Buffer
|
||||
if err := tmpl.Execute(&urlBytes, &vars); err != nil {
|
||||
return nil, errors.New("could not write info url template output")
|
||||
}
|
||||
|
||||
templateUrl := urlBytes.String()
|
||||
parsedUrl, err := url.Parse(templateUrl)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// for backwards compatibility remove Host and Scheme to rebuild url
|
||||
if parsedUrl.Host != "" {
|
||||
parsedUrl.Host = ""
|
||||
}
|
||||
if parsedUrl.Scheme != "" {
|
||||
parsedUrl.Scheme = ""
|
||||
}
|
||||
|
||||
// join baseURL with query
|
||||
baseUrlPath, err := url.JoinPath(baseURL, parsedUrl.Path)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not join info url")
|
||||
}
|
||||
|
||||
// reconstruct url
|
||||
infoUrl, _ := url.Parse(baseUrlPath)
|
||||
infoUrl.RawQuery = parsedUrl.RawQuery
|
||||
|
||||
matched.InfoURL = infoUrl.String()
|
||||
}
|
||||
|
||||
if p.Match.TorrentURL != "" {
|
||||
// setup text template to inject variables into
|
||||
tmpl, err := template.New("torrenturl").Funcs(sprig.TxtFuncMap()).Parse(p.Match.TorrentURL)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue