Пример #1
0
 public PodcastViewModel(Podcast podcast)
 {
     this.Podcast = podcast;
     this._episodes = new ObservableCollection<EpisodeViewModel>();
     var episodes = podcast.Episodes.Select(ep => new EpisodeViewModel(ep));
     foreach (var episode in episodes)
     {
         episode.Episode.Podcast = podcast;
         _episodes.Add(episode);
     }
 }
Пример #2
0
 public Episode(System.Xml.Linq.XElement element, Podcast podcast)
 {
     XNamespace itunes = "http://www.itunes.com/dtds/podcast-1.0.dtd";
     Name = element.Element("title").Value;
     WebPath = WebPath = element.Element("enclosure").Attribute("url").Value;
     Author = element.Element(itunes + "author").Value;
     IsLocal = false;
     Published = element.Element("pubDate").Value.ToDateTime();
     ImageUrl = element.Element(itunes + "image") != null ? new Uri(element.Element(itunes + "image").Attribute("href").Value) : podcast.ImageUrl;
     Summary = element.Element(itunes + "summary") != null ? element.Element(itunes + "summary").Value : null;
     Description = element.Element("description") != null ? element.Element("description").Value : null;
     Podcast = podcast;
 }
Пример #3
0
        public Episode(System.Xml.Linq.XElement element, Podcast podcast)
        {
            XNamespace itunes = "http://www.itunes.com/dtds/podcast-1.0.dtd";

            Name      = element.Element("title").Value;
            WebPath   = WebPath = element.Element("enclosure").Attribute("url").Value;
            Author    = element.Element(itunes + "author").Value;
            IsLocal   = false;
            Published = element.Element("pubDate").Value.ToDateTime();
            ImageUrl  = element.Element(itunes + "image") != null ? new Uri(element.Element(itunes + "image").Attribute("href").Value) : podcast.ImageUrl;
            Summary   = element.Element(itunes + "summary") != null?element.Element(itunes + "summary").Value : null;

            Description = element.Element("description") != null?element.Element("description").Value : null;

            Podcast = podcast;
        }
Пример #4
0
        public static async Task<Podcast> LoadPodcastAsync(Uri url)
        {
            try
            {
                var httpClient = new HttpClient();
                var xml = await httpClient.GetStringAsync(url);
                var xmlDocument = XDocument.Parse(xml);

                var channelTitle = xmlDocument.Element("rss").Element("channel").Element("title").Value;
                XNamespace itunes = "http://www.itunes.com/dtds/podcast-1.0.dtd";
                var elements = xmlDocument.Element("rss").Element("channel").Elements("item");
                var description = xmlDocument.Element("rss").Element("channel").Element("description").Value;
                var imageUrl = xmlDocument.Element("rss").Element("channel").Element(itunes + "image").Attribute("href").Value;
                var author = xmlDocument.Element("rss").Element("channel").Element(itunes + "author").Value;

                var podcast = new Podcast
                {
                    FeedUrl = url,
                    Name = channelTitle,
                    ImageUrl = new Uri(imageUrl),
                    Author = author,
                    Description = description,
                    DateAdded = DateTime.Now
                };

                var episodes = new List<Episode>();

                foreach (var element in elements)
                {
                    var episode = new Episode(element, podcast);
                    episodes.Add(episode);
                }
                podcast.Episodes = episodes.OrderByDescending(episode => episode.Published).ToList();

                return podcast;
            }
            catch
            {
                return null;
            }
        }
Пример #5
0
 public static async Task<IList<Episode>> GetPodcastEpisodesFromStorageAsync(Podcast podcast)
 {
     var podcasts = await GetPodcastsFromStorageAsync();
     return podcasts.Where(p => p.Name == podcast.Name).SingleOrDefault().Episodes;
 }