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:
ze0s 2023-01-29 21:40:49 +01:00 committed by GitHub
parent 870e109f6c
commit 4c83787a0b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
68 changed files with 189 additions and 13 deletions

View file

@ -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)

View file

@ -44,9 +44,10 @@ type Release struct {
Protocol ReleaseProtocol `json:"protocol"`
Implementation ReleaseImplementation `json:"implementation"` // irc, rss, api
Timestamp time.Time `json:"timestamp"`
InfoURL string `json:"info_url"`
TorrentURL string `json:"download_url"`
GroupID string `json:"group_id"`
TorrentID string `json:"torrent_id"`
TorrentURL string `json:"-"`
TorrentTmpFile string `json:"-"`
TorrentDataRawBytes []byte `json:"-"`
TorrentHash string `json:"-"`