gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 04:02:16 25 4
gpt4 key购买 nike

通过使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com