Solocast.Services.FeedParserService.GetPodcastAsync C# (CSharp) Method

GetPodcastAsync() public method

public GetPodcastAsync ( string feedUrl ) : Task
feedUrl string
return Task
        public async Task<Podcast> GetPodcastAsync(string feedUrl)
        {
            var json = await GetChannelNodeAsync(feedUrl);

            string link = feedUrl;
            string title = json.title.ToString();
            string author = json["itunes:author"]?.ToString();
            string summary = json["itunes:summary"]?.ToString();
            string description = json.description?.ToString();
            string imageLink = json.image.url ?? json["itunes:image"]["@href"].ToString();
            string podcastDescription = string.Empty;

            if (description == null)
                podcastDescription = summary;
            else if (summary == null)
                podcastDescription = description;
            else
                podcastDescription = description;

            podcastDescription = podcastDescription.RemoveCData();

            var podcast = new Podcast(title, podcastDescription, author, link, imageLink, DateTime.Now);

            var episodes = new List<Episode>();

            var items = json.item;

            foreach (var item in items)
            {
                title = item.title.ToString();
                string subtitle = item["itunes:subtitle"].ToString();
                string path = item.enclosure["@url"].ToString();
                author = item["itunes:author"].ToString();
                summary = item["itunes:summary"].ToString();
                string pubDate = item.pubDate.ToString();
                string imageUrl = item["itunes:image"] != null ? item["itunes:image"]["@href"] : imageLink;
                string guid = item.guid.ToString();

                var episode = new Episode(title, subtitle, path, author, summary, pubDate, imageUrl, guid);
                episode.SetPodcast(podcast);
                episodes.Add(episode);
            }

            podcast.SetEpisodes(episodes.OrderByDescending(e=>e.Published));
            return podcast;
        }
    }

Usage Example

Ejemplo n.º 1
0
        public void RandomTest()
        {
            var feedParser = new FeedParserService();
            var podcast = feedParser.GetPodcastAsync("http://monstercat.com/podcast/feed.xml").Result;

            Assert.AreEqual(true, true);
        }