This commit is contained in:
bel
2025-05-04 10:34:03 -06:00
parent 32a010e697
commit 0399fc9316
2 changed files with 56 additions and 1 deletions

View File

@@ -49,7 +49,12 @@ func (feed Feed) ShouldExecute() (bool, error) {
}
func (feed Feed) Fetch(ctx context.Context) (Items, error) {
resp, err := proxyFetch(ctx, feed.Version.URL)
u, err := feed.FetchURL()
if err != nil {
return nil, err
}
resp, err := proxyFetch(ctx, u.String())
if err != nil {
return nil, err
}
@@ -132,3 +137,32 @@ func proxyFetch(ctx context.Context, u string) (string, error) {
return string(b), nil
}
func (feed Feed) FetchURL() (*url.URL, error) {
u, err := url.Parse(feed.Version.URL)
if err != nil {
return nil, err
}
switch u.Scheme {
case "nyaa": // `nyaa://?q=A B` to `https://nyaa.si/?page=rss&q=A%20B&c=0_0&f=0`
q := u.Query()
if q.Get("q") == "" {
return nil, fmt.Errorf("invalid nyaa:// (%s): no ?q", feed.Version.URL)
}
q.Set("page", "rss")
q.Set("c", "0_0")
q.Set("f", "0")
u.RawQuery = q.Encode()
u.Scheme = "https"
u.Host = "nyaa.si"
u.Path = "/"
case "http", "https":
default:
return nil, fmt.Errorf("not impl mapping %s:// to url", u.Scheme)
}
return u, nil
}