Ejemplo n.º 1
0
        public async Task <RssFeedInfo> GetFeed(string url)
        {
            using (var stream = await _client.GetStreamAsync(url))
            {
                XNamespace ns     = "http://www.w3.org/2005/Atom";
                XNamespace media  = "http://search.yahoo.com/mrss/";
                XNamespace yt     = "http://www.youtube.com/xml/schemas/2015";
                XNamespace itunes = "http://www.itunes.com/dtds/podcast-1.0.dtd";

                var doc = await XDocument.LoadAsync(stream, LoadOptions.None, CancellationToken.None);

                var nav = doc.CreateNavigator();
                nav.MoveToFollowing(XPathNodeType.Element);
                IDictionary <string, string> namespaces = nav.GetNamespacesInScope(XmlNamespaceScope.Local);

                var root = doc.Root;
                var info = new RssFeedInfo
                {
                    Id    = root.Element(ns + "id").Value,
                    Title = root.Element(ns + "title").Value
                };
                var videos = from entry in doc.Descendants(ns + "entry")
                             select new MediaFileInfo
                {
                    VideoId   = entry.Element(yt + "videoId").Value,
                    Name      = entry.Element(ns + "title").Value,
                    Thumbnail = entry.Descendants(media + "thumbnail").FirstOrDefault()?.Value,
                    Url       = GetUrl(entry, ns)
                };
                info.Videos = videos.ToList();
                return(info);
            }
        }
Ejemplo n.º 2
0
        public async Task <RssFeedInfo> GetFeed(string url)
        {
            XNamespace media  = "http://search.yahoo.com/mrss/";
            XNamespace itunes = "http://www.itunes.com/dtds/podcast-1.0.dtd";

            using (var stream = await _client.GetStreamAsync(url))
            {
                var doc = await XDocument.LoadAsync(stream, LoadOptions.None, CancellationToken.None);

                var nav = doc.CreateNavigator();
                nav.MoveToFollowing(XPathNodeType.Element);
                nav.MoveToRoot();
                IDictionary <string, string> namespaces = nav.GetNamespacesInScope(XmlNamespaceScope.Local);

                var root = doc.Root.Element("channel");
                var info = new RssFeedInfo
                {
                    Title = root.Element("title").Value
                };
                var videos = from entry in doc.Descendants("item")
                             select new MediaFileInfo
                {
                    Name      = entry.Element("title").Value,
                    Thumbnail = entry.Element(itunes + "thumbnail")?.Value,
                    Url       = entry.Element("enclosure").Attribute("url").Value
                };
                info.Videos = videos.ToList();
                return(info);
            }
        }