diff --git a/internal/domain/indexer.go b/internal/domain/indexer.go index 9303125..c16dcd5 100644 --- a/internal/domain/indexer.go +++ b/internal/domain/indexer.go @@ -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") } - parsedUrl, err := url.Parse(urlBytes.String()) + templateUrl := urlBytes.String() + parsedUrl, err := url.Parse(templateUrl) if err != nil { return nil, err } @@ -223,12 +224,16 @@ func (p *IndexerIRCParse) ParseMatch(baseURL string, vars map[string]string) (*I } // join baseURL with query - torrentURL, err := url.JoinPath(baseURL, parsedUrl.Path) + baseUrlPath, err := url.JoinPath(baseURL, parsedUrl.Path) if err != nil { 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 != "" { diff --git a/internal/domain/indexer_test.go b/internal/domain/indexer_test.go index f2f77f3..f25d491 100644 --- a/internal/domain/indexer_test.go +++ b/internal/domain/indexer_test.go @@ -200,6 +200,49 @@ func TestIndexerIRCParse_ParseMatch(t *testing.T) { }, 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 { t.Run(tt.name, func(t *testing.T) {