add Summary field for ApplePodcast
This commit is contained in:
2
main.go
2
main.go
@@ -11,7 +11,7 @@ func main() {
|
||||
provider := search.NewITunesProvider()
|
||||
|
||||
// podcast, err := provider.SearchPodcasts("golang", &search.SearchOptions{Country: "us", Language: "en-us"})
|
||||
podcast, err := provider.Charts(&search.ChartsOptions{Country: "us", Language: "en-us", Limit: 200})
|
||||
podcast, err := provider.Charts(&search.ChartsOptions{Country: "us", Language: "en-us", Limit: 10})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ type ApplePodcast struct {
|
||||
TrackCensoredName string `json:"trackCensoredName,omitempty"`
|
||||
CollectionViewURL string `json:"collectionViewUrl,omitempty"`
|
||||
FeedURL string `json:"feedUrl,omitempty"`
|
||||
Summary string `json:"summary,omitempty"`
|
||||
TrackViewURL string `json:"trackViewUrl,omitempty"`
|
||||
ArtworkURL30 string `json:"artworkUrl30,omitempty"`
|
||||
ArtworkURL60 string `json:"artworkUrl60,omitempty"`
|
||||
|
||||
@@ -147,7 +147,7 @@ func (p *ITunesProvider) SearchPodcasts(term string, options *SearchOptions) (*m
|
||||
|
||||
// 构建URL
|
||||
url := fmt.Sprintf("%s?%s", p.SearchAPIEndpoint, params.Encode())
|
||||
fmt.Printf("url: %s\n", url)
|
||||
// fmt.Printf("url: %s\n", url)
|
||||
|
||||
// 发送请求
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
@@ -175,13 +175,7 @@ func (p *ITunesProvider) SearchPodcasts(term string, options *SearchOptions) (*m
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("读取响应失败: %w", err)
|
||||
}
|
||||
fmt.Printf("body: %s\n", string(body))
|
||||
|
||||
// 解析JSON响应
|
||||
// var response struct {
|
||||
// ResultCount int `json:"resultCount"`
|
||||
// Results []model.ApplePodcast `json:"results"`
|
||||
// }
|
||||
// fmt.Printf("body: %s\n", string(body))
|
||||
|
||||
// 创建搜索结果
|
||||
result := &model.SearchResult2{
|
||||
@@ -205,7 +199,7 @@ func (p *ITunesProvider) SearchPodcasts(term string, options *SearchOptions) (*m
|
||||
func (p *ITunesProvider) Charts(options *ChartsOptions) (*model.SearchResult2, error) {
|
||||
// 构建URL
|
||||
url := p.buildChartsURL(options)
|
||||
fmt.Printf("url: %s\n", url)
|
||||
// fmt.Printf("url: %s\n", url)
|
||||
|
||||
// 发送请求
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
@@ -279,15 +273,16 @@ func (p *ITunesProvider) Charts(options *ChartsOptions) (*model.SearchResult2, e
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
fmt.Printf("lookupBody: %s\n", string(lookupBody))
|
||||
// fmt.Printf("lookupBody: %s\n", string(lookupBody))
|
||||
|
||||
var tempResult model.LookupResult
|
||||
if err := json.Unmarshal(lookupBody, &tempResult); err != nil {
|
||||
var lookupResult model.LookupResult
|
||||
if err := json.Unmarshal(lookupBody, &lookupResult); err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if tempResult.ResultCount > 0 && len(tempResult.Items) > 0 {
|
||||
result.Items = append(result.Items, tempResult.Items[0])
|
||||
if lookupResult.ResultCount > 0 && len(lookupResult.Items) > 0 {
|
||||
lookupResult.Items[0].Summary = entry.Summary.Label
|
||||
result.Items = append(result.Items, lookupResult.Items[0])
|
||||
}
|
||||
}
|
||||
result.ResultCount = len(result.Items)
|
||||
|
||||
Reference in New Issue
Block a user