通過使用iTunes API搜索播客(http://www.apple.com/itunes/affiliates/resources/documentation/itunes-store-web-service-search-api.html),結果包含音頻和視頻播客。有沒有什麼辦法只從API檢索音頻播客?如何從iTunes Search API過濾音頻Podcast?
在此先感謝:-)
通過使用iTunes API搜索播客(http://www.apple.com/itunes/affiliates/resources/documentation/itunes-store-web-service-search-api.html),結果包含音頻和視頻播客。有沒有什麼辦法只從API檢索音頻播客?如何從iTunes Search API過濾音頻Podcast?
在此先感謝:-)
是的。在常規的檢索算法,你得到的一切: https://itunes.apple.com/search?term=jack+johnson
但是你可以添加一些PARAMS要求,例如(對於你的情況)
&entity=song
因此請求將是:
https://itunes.apple.com/search?term=jack+johnson&entity=song
更多看看搜索在this docs
從th e文檔似乎並不像過濾音頻和視頻播客是可能的;但是,您可以遍歷結果項目並檢查每個項目是音頻還是視頻進行過濾。您可以通過RSS訂閱源查找更多信息,或者使用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; } } }
你有沒有想過這個? – Padraig