fix: 榜单逐项 lookup 带上榜单地区
ChartsContext 对榜单条目逐个 lookup 时不带 country,Apple 缺省查 US 区, 只在其他地区上架的节目因此查不到并被静默丢弃。实测 CN 区 1498(语言学习) 榜前 50 档,不带地区只查回 48 档,带 country=cn 查全 50 档。 补测试:lookup 请求带上 ChartsOptions.Country,只在该地区上架的节目能被查回。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -295,6 +295,11 @@ func (p *ITunesProvider) ChartsContext(ctx context.Context, options *ChartsOptio
|
|||||||
|
|
||||||
// 为每个播客获取详细信息
|
// 为每个播客获取详细信息
|
||||||
lookupURL := fmt.Sprintf("%s/lookup?id=%s", p.FeedAPIEndpoint, id)
|
lookupURL := fmt.Sprintf("%s/lookup?id=%s", p.FeedAPIEndpoint, id)
|
||||||
|
// 带上榜单地区:lookup 缺省查 US 区,只在其他地区上架的节目不带地区查不到
|
||||||
|
// (实测 CN 区 1498 榜前 50 档会丢 2 档)。
|
||||||
|
if options.Country != "" {
|
||||||
|
lookupURL += "&country=" + options.Country
|
||||||
|
}
|
||||||
p.Logger.Infof("%03d lookup url: %s", cnt, lookupURL)
|
p.Logger.Infof("%03d lookup url: %s", cnt, lookupURL)
|
||||||
cnt++
|
cnt++
|
||||||
lookupReq, err := http.NewRequestWithContext(ctx, "GET", lookupURL, nil)
|
lookupReq, err := http.NewRequestWithContext(ctx, "GET", lookupURL, nil)
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
package search
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"go.uber.org/ratelimit"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 榜单逐项 lookup 必须带上榜单地区:只在该地区上架的节目,缺省(US 区)lookup 查不到。
|
||||||
|
func TestChartsContextLookupUsesChartCountry(t *testing.T) {
|
||||||
|
var mu sync.Mutex
|
||||||
|
var lookupQueries []string
|
||||||
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
switch {
|
||||||
|
case strings.HasPrefix(r.URL.Path, "/cn/rss/toppodcasts/"):
|
||||||
|
_, _ = w.Write([]byte(`{"feed":{"entry":[{"id":{"attributes":{"im:id":"1796650777"}},"summary":{"label":"s"}}]}}`))
|
||||||
|
case r.URL.Path == "/lookup":
|
||||||
|
mu.Lock()
|
||||||
|
lookupQueries = append(lookupQueries, r.URL.RawQuery)
|
||||||
|
mu.Unlock()
|
||||||
|
if r.URL.Query().Get("country") != "cn" {
|
||||||
|
_, _ = w.Write([]byte(`{"resultCount":0,"results":[]}`))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
_, _ = w.Write([]byte(`{"resultCount":1,"results":[{"collectionId":1796650777,"collectionName":"CN Only","feedUrl":"https://f"}]}`))
|
||||||
|
default:
|
||||||
|
http.NotFound(w, r)
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
defer srv.Close()
|
||||||
|
|
||||||
|
p := NewITunesProvider()
|
||||||
|
p.FeedAPIEndpoint = srv.URL
|
||||||
|
p.Limiter = ratelimit.NewUnlimited()
|
||||||
|
|
||||||
|
result, err := p.ChartsContext(context.Background(), &ChartsOptions{Country: "cn", GenreID: "1498", Limit: 1})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("ChartsContext: %v", err)
|
||||||
|
}
|
||||||
|
if len(lookupQueries) != 1 || !strings.Contains(lookupQueries[0], "country=cn") {
|
||||||
|
t.Fatalf("lookup 应带 country=cn,实际 %v", lookupQueries)
|
||||||
|
}
|
||||||
|
if result.ResultCount != 1 || result.Items[0].CollectionName != "CN Only" {
|
||||||
|
t.Fatalf("只在 CN 区上架的节目应被查回,实际 %+v", result.Items)
|
||||||
|
}
|
||||||
|
if result.Items[0].Summary != "s" {
|
||||||
|
t.Fatalf("简介取自榜单条目,实际 %q", result.Items[0].Summary)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user