Exemple #1
0
        private async Task <IEnumerable <VideoFeedItem> > ParseFeed(string rss)
        {
            return(await Task.Run(() =>
            {
                var xdoc = XDocument.Parse(rss);
                var list = new List <VideoFeedItem>();
                XNamespace media = "http://search.yahoo.com/mrss/";
                XNamespace itunes = "http://www.itunes.com/dtds/podcast-1.0.dtd";
                foreach (var item in xdoc.Descendants("item"))
                {
                    try
                    {
                        bool foundTheMagicKeyword = false;
                        foreach (var element in item.Elements())
                        {
                            var keyword = "hanselman".ToLowerInvariant();
                            if (element.Value.ToLowerInvariant().Contains(keyword))
                            {
                                foundTheMagicKeyword = true;
                                break;
                            }
                        }
                        if (!foundTheMagicKeyword)
                        {
                            continue;
                        }

                        var mediaGroup = item.Element(media + "group");
                        if (mediaGroup == null)
                        {
                            continue;
                        }

                        List <VideoContentItem> videoUrls = new List <VideoContentItem>();
                        foreach (var mediaUrl in mediaGroup.Elements())
                        {
                            var duration = mediaUrl.Attribute("duration").Value;
                            var fileSize = mediaUrl.Attribute("fileSize").Value;
                            var url = mediaUrl.Attribute("url").Value;
                            videoUrls.Add(new VideoContentItem()
                            {
                                Duration = TimeSpan.FromSeconds(Convert.ToInt32(duration)),
                                FileSize = long.Parse(fileSize),
                                Url = url,
                            }
                                          );
                        }

                        var videoFeedItem = new VideoFeedItem
                        {
                            VideoUrls = videoUrls.OrderByDescending(url => url.FileSize).ToList(),
                            Title = (string)item.Element("title"),
                            Description = (string)item.Element(itunes + "summary")?.Value,
                            Link = (string)item.Element("link"),
                            PublishDate = (string)item.Element("pubDate"),
                            Category = (string)item.Element("category"),
                            ThumbnailUrl = (string)item.Element(media + "thumbnail")?.Attribute("url")?.Value
                        };

                        list.Add(videoFeedItem);
                    }
                    catch (Exception)
                    {
                        Debug.WriteLine("Unable to parse rss for item");
                    }
                }
                return list;
            }));
        }
Exemple #2
0
 public Channel9VideoPlaybackPage(VideoFeedItem item)
 {
     InitializeComponent();
     BindingContext = item;
 }