예제 #1
0
 private static void FillFeed(XmlDocument xml, MSYoutubeEntry feed)
 {
     feed.Title = GetNodeValue(xml.DocumentElement, "root:title");
     feed.Author = GetNodeValue(xml.DocumentElement, "root:author/root:name");
     feed.AuthorId = GetNodeValue(xml.DocumentElement, "root:author/yt:userId");
     var nextPageUri = GetNodeValue(xml.DocumentElement, "root:link[@rel='next']/@href");
     feed.NextPageUri = (String.IsNullOrEmpty(nextPageUri)) ? null : new Uri(nextPageUri);
     string stotal = GetNodeValue(xml.DocumentElement, "openSearch:totalResults");
     int total;
     feed.Total = (int.TryParse(stotal, out total)) ? total : 0;
     var nodes = GetNodes(xml.DocumentElement, "root:entry");
     foreach (XmlElement node in nodes) {
         var entry = new MSYoutubeEntry();
         entry.Title = GetNodeValue(node, "root:title");
         entry.Description = GetNodeValue(node, "media:group/media:description");
         var tmp = GetNodeValue(node, "yt:position");
         foreach (XmlElement thumbNode in GetNodes(node, "media:group/media:thumbnail")) {
             var thumbnail = new MSYoutubeThumbnail();
             thumbnail.Url = GetNodeValue(thumbNode, "@url");
             thumbnail.Height = GetNodeValue(thumbNode, "@height");
             thumbnail.Width = GetNodeValue(thumbNode, "@width");
             entry.Thumbnails.Add(thumbnail);
         }
         tmp = GetNodeValue(node, "root:link[@rel='alternate']/@href");
         Uri uri;
         if (!Uri.TryCreate(tmp, UriKind.Absolute, out uri)) continue;
         entry.Uri = uri;
         feed.Entries.Add(entry);
     }
 }
예제 #2
0
 public async Task _GetAsync(Uri uri, MSYoutubeEntry feed, MSYoutubeLoading loading)
 {
     
     if (feed.NextPageUri == null) return;
     var document = await GetXmlDocumentAsync(feed.NextPageUri);
     FillFeed(document, feed);
     if (loading != null) loading(feed.Entries.Count, feed.Total);
     await _GetAsync(uri, feed, loading);
 }
예제 #3
0
 public async Task<MSYoutubeEntry> GetAsync(YoutubeUrl youtubeUrl, Uri uri, MSYoutubeLoading loading)
 {
     var feed = new MSYoutubeEntry {
         YoutubeUrl = youtubeUrl,
         NextPageUri =
             new Uri(uri + ((String.IsNullOrEmpty(uri.Query)) ? "?" : "&") + "start-index=1&max-results=40")
     };
     await _GetAsync(uri, feed, loading);
     return feed;
 }
        public MSYoutubeEntry GetAsync(YoutubeUrl youtubeUrl, Uri uri, MSYoutubeLoading loading)
        {
            var feed = new MSYoutubeEntry {
                YoutubeUrl  = youtubeUrl,
                NextPageUri =
                    new Uri(uri + ((String.IsNullOrEmpty(uri.Query)) ? "?" : "&") + "start-index=1&max-results=40")
            };

            _GetAsync(uri, feed, loading);
            return(feed);
        }
        public void _GetAsync(Uri uri, MSYoutubeEntry feed, MSYoutubeLoading loading)
        {
            if (feed.NextPageUri == null)
            {
                return;
            }
            var document = GetXmlDocumentAsync(feed.NextPageUri);

            FillFeed(document, feed);
            if (loading != null)
            {
                loading(feed.Entries.Count, feed.Total);
            }
            _GetAsync(uri, feed, loading);
        }
        private static void FillFeed(XmlDocument xml, MSYoutubeEntry feed)
        {
            feed.Title    = GetNodeValue(xml.DocumentElement, "root:title");
            feed.Author   = GetNodeValue(xml.DocumentElement, "root:author/root:name");
            feed.AuthorId = GetNodeValue(xml.DocumentElement, "root:author/yt:userId");
            var nextPageUri = GetNodeValue(xml.DocumentElement, "root:link[@rel='next']/@href");

            feed.NextPageUri = (String.IsNullOrEmpty(nextPageUri)) ? null : new Uri(nextPageUri);
            string stotal = GetNodeValue(xml.DocumentElement, "openSearch:totalResults");
            int    total;

            feed.Total = (int.TryParse(stotal, out total)) ? total : 0;
            var nodes = GetNodes(xml.DocumentElement, "root:entry");

            foreach (XmlElement node in nodes)
            {
                var entry = new MSYoutubeEntry {
                    Title       = GetNodeValue(node, "root:title"),
                    Description = GetNodeValue(node, "media:group/media:description")
                };
                string tmp; // = GetNodeValue(node, "yt:position");
                foreach (XmlElement thumbNode in GetNodes(node, "media:group/media:thumbnail"))
                {
                    var thumbnail = new MSYoutubeThumbnail();
                    thumbnail.Url    = GetNodeValue(thumbNode, "@url");
                    thumbnail.Height = GetNodeValue(thumbNode, "@height");
                    thumbnail.Width  = GetNodeValue(thumbNode, "@width");
                    entry.Thumbnails.Add(thumbnail);
                }
                tmp = GetNodeValue(node, "root:link[@rel='alternate']/@href");
                Uri uri;
                if (!Uri.TryCreate(tmp, UriKind.Absolute, out uri))
                {
                    continue;
                }
                entry.Uri = uri;
                feed.Entries.Add(entry);
            }
        }
예제 #7
0
 private ObservableCollection<Feed> GetMembers(MSYoutubeEntry items)
 {
     var entries = new ObservableCollection<Feed>();
     foreach (var member in items.Entries) {
         if (member.Uri == null) continue;
         var thumbnailUrl = "";
         var thumbnailUrls = new List<string>(member.Thumbnails.Count);
         foreach (var tn in member.Thumbnails) {
             thumbnailUrls.Add(tn.Url);
             if (tn.Height == "90" && tn.Width == "120")
                 thumbnailUrl = tn.Url;
         }
         entries.Add(new YoutubeEntry(this) {
             Title = member.Title,
             Uri = member.Uri,
             Description = member.Description,
             ThumbnailUrl = thumbnailUrl
         });
     }
     return entries;
 }