作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
通过使用 iTunes API (http://www.apple.com/itunes/affiliates/resources/documentation/itunes-store-web-service-search-api.html) 搜索播客,结果包含音频和视频播客。有没有办法从 API 中仅检索音频播客?
提前致谢:-)
最佳答案
从文档来看,过滤音频和视频播客似乎是不可能的;但是,您可以循环遍历结果项目并检查每个项目是音频还是视频以进行过滤。您可以通过从 RSS feed 查找其他信息或使用 subscribePodcast url 再次调用 iTunes(参见示例)来实现此目的。
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net; using System.Web.Script.Serialization; using System.Xml.Linq; using System.IO; namespace ConsoleTest { class Program { static void Main(string[] args) { //Searching for 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(); } static 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) { //This is the is video value isVideo = e.Name.LocalName.Trim().ToLower() == "true"; next = false; break; } if (e.Value == "is-video") { next = true; } } return isVideo; } static string FetchHTML(string url,bool doItAsITunes = false) { string htmlCode = ""; using (WebClient client = new WebClient()) { if (doItAsITunes) { client.Headers.Add("user-agent", "iTunes/9.1.1"); } htmlCode = client.DownloadString(url); } return htmlCode; } } public class SearchResult { public SearchResult() { Results = new List(); } public int ResultCount { set; get; } public List Results { set; get; } } public class 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; } } }
关于api - 如何从 iTunes 搜索 API 过滤音频播客?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11114381/
我是一名优秀的程序员,十分优秀!