如何从iTunes搜索API中过滤音频播客?

4
通过在iTunes API(http://www.apple.com/itunes/affiliates/resources/documentation/itunes-store-web-service-search-api.html)中搜索播客,结果包含音频和视频播客。有没有办法仅从API中检索音频播客?
提前感谢你的帮助 :-)
2个回答

0

从文档中看来,似乎无法过滤音频和视频播客;但是,您可以循环遍历结果项并检查每个项是否为音频或视频以进行过滤。您可以通过从RSS提要中获取其他信息或使用subscribePodcast URL(请参见示例)向iTunes发出另一个调用来实现这一点。

使用System;
使用System.Collections.Generic;
使用System.Linq;
使用System.Text;
使用System.Net;
使用System.Web.Script.Serialization;
使用System.Xml.Linq;
使用System.IO;
命名空间ConsoleTest { 类Program { 静态void Main(string[] args) {
//搜索Windows Weekly string url = "https://itunes.apple.com/search?term=Windows%20Weekly&media=podcast&attibute=audio";
string json = FetchHTML(url);
JavaScriptSerializer s = new JavaScriptSerializer(); var result = s.Deserialize(json);
var audioOnly = new List();
foreach (var item in result.Results) {
if (!IsVideo(item.TrackId)) { audioOnly.Add(item); }
}
foreach (var au in audioOnly) { Console.WriteLine(au.TrackName); }
Console.ReadLine(); }
静态bool IsVideo(string id) { string req = "https://buy.itunes.apple.com/WebObjects/MZFinance.woa/wa/com.apple.jingle.app.finance.DirectAction/subscribePodcast?id=" + id + "&wasWarnedAboutPodcasts=true";
string xml = FetchHTML(req,true);
bool isVideo = false;
var re = XElement.Load(new StringReader(xml)).Elements("dict").Elements("dict");
bool next = false; foreach (var e in re.Elements()) { if (next) { //这是视频值 isVideo = e.Name.LocalName.Trim().ToLower() == "true"; next = false; break; } if (e.Value == "is-video") { next = true; } }
return isVideo; }
静态string FetchHTML(string url,bool doItAsITunes = false) { string htmlCode = "";
使用(WebClient client = new WebClient()) { if (doItAsITunes) { client.Headers.Add("user-agent", "iTunes/9.1.1"); }
htmlCode = client.DownloadString(url); }
返回htmlCode; }
}
公共类SearchResult { public SearchResult() { Results = new List(); }
public int ResultCount { set; get; } public List Results { set; get; } }
公共类Item { public Item() { GenreIDs = new List(); Genres = new List();
}
public string WrapperType { set; get; } public string Kind { set; get; } public string ArtistID { set; get; } public string CollectionID { set; get; } public string TrackId { set; get; } public string ArtistName { set; get; } public string CollectionName { set; get; } public string TrackName { set; get; } public string CollectionCensoredName { set; get; } public string TrackCensoredName { set; get; } public string ArtistViewUrl { set; get; } public string FeedUrl { set; get; } public string TrackViewUrl { set; get; } public string PreviewUrl { set; get; } public string ArtworkUrl60 { set; get; } public string ArtworkUrl100 { set; get; } public float CollectionPrice { set; get; } public float TrackPrice { set; get; } public string CollectionExplicitness { set; get; } public string TrackExplicitness { set; get; } public string DiscCount { set; get; } public string DiscNumber { set; get; } public string TrackCount { set; get; } public string TrackNumber { set; get; } public string TrackTimeMillis { set; get; } public string Country { set; get; } public string Currency { set; get; } public string PrimaryGenreName { set; get; } public List GenreIDs { set; get; } public List Genres { set; get; } }
}

-1

是的。在常规搜索中,您可以获得所有内容: https://itunes.apple.com/search?term=jack+johnson

但是您可以添加一些参数来请求例如(针对您的情况)

&entity=song

因此请求将是:

https://itunes.apple.com/search?term=jack+johnson&entity=song

更多内容请查看this docs中的搜索部分。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接