mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 16:59:12 +00:00
fix(announce): parse torrentUrl (#557)
fix(announce): generate torrentUrl
This commit is contained in:
parent
4623921cbb
commit
6ad4abe296
2 changed files with 51 additions and 3 deletions
|
@ -209,7 +209,8 @@ func (p *IndexerIRCParse) ParseMatch(baseURL string, vars map[string]string) (*I
|
||||||
return nil, errors.New("could not write torrent url template output")
|
return nil, errors.New("could not write torrent url template output")
|
||||||
}
|
}
|
||||||
|
|
||||||
parsedUrl, err := url.Parse(urlBytes.String())
|
templateUrl := urlBytes.String()
|
||||||
|
parsedUrl, err := url.Parse(templateUrl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -223,12 +224,16 @@ func (p *IndexerIRCParse) ParseMatch(baseURL string, vars map[string]string) (*I
|
||||||
}
|
}
|
||||||
|
|
||||||
// join baseURL with query
|
// join baseURL with query
|
||||||
torrentURL, err := url.JoinPath(baseURL, parsedUrl.Path)
|
baseUrlPath, err := url.JoinPath(baseURL, parsedUrl.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "could not join torrent url")
|
return nil, errors.Wrap(err, "could not join torrent url")
|
||||||
}
|
}
|
||||||
|
|
||||||
matched.TorrentURL = torrentURL
|
// reconstruct url
|
||||||
|
torrentUrl, _ := url.Parse(baseUrlPath)
|
||||||
|
torrentUrl.RawQuery = parsedUrl.RawQuery
|
||||||
|
|
||||||
|
matched.TorrentURL = torrentUrl.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
if p.Match.TorrentName != "" {
|
if p.Match.TorrentName != "" {
|
||||||
|
|
|
@ -200,6 +200,49 @@ func TestIndexerIRCParse_ParseMatch(t *testing.T) {
|
||||||
},
|
},
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "test_04",
|
||||||
|
fields: fields{
|
||||||
|
Type: "",
|
||||||
|
ForceSizeUnit: "",
|
||||||
|
Lines: []IndexerIRCParseLine{
|
||||||
|
{
|
||||||
|
Test: nil,
|
||||||
|
Pattern: "New Torrent in category \\[([^\\]]*)\\] (.*) \\(([^\\)]*)\\) uploaded! Download\\: (https?\\:\\/\\/[^\\/]+\\/).+id=(.+)",
|
||||||
|
Vars: []string{
|
||||||
|
"category",
|
||||||
|
"torrentName",
|
||||||
|
"uploader",
|
||||||
|
"freeleech",
|
||||||
|
"baseUrl",
|
||||||
|
"torrentId",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Match: IndexerIRCParseMatch{
|
||||||
|
TorrentURL: "/rss/?action=download&key={{ .key }}&token={{ .token }}&hash={{ .torrentId }}&title={{ .torrentName }}",
|
||||||
|
Encode: []string{"torrentName"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
args: args{
|
||||||
|
baseURL: "https://mock.local/",
|
||||||
|
vars: map[string]string{
|
||||||
|
"category": "Movies/Remux",
|
||||||
|
"torrentName": "The Show 2019 S03E08 2160p DV WEBRip 6CH x265 HEVC-GROUP",
|
||||||
|
"uploader": "Anonymous",
|
||||||
|
"torrentSize": "",
|
||||||
|
"baseUrl": "https://mock.local/",
|
||||||
|
"torrentId": "240860011",
|
||||||
|
"key": "KEY",
|
||||||
|
"token": "TOKEN",
|
||||||
|
"rsskey": "00000000000000000000",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
want: &IndexerIRCParseMatched{
|
||||||
|
TorrentURL: "https://mock.local/rss/?action=download&key=KEY&token=TOKEN&hash=240860011&title=The+Show+2019+S03E08+2160p+DV+WEBRip+6CH+x265+HEVC-GROUP",
|
||||||
|
},
|
||||||
|
wantErr: false,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue