private void GetYouTubeUserPlaylists(ISource source, LoadSourceRequest request) { var path = source.Path + "/playlists?v=2"; var xml = new XmlDocument(); xml.LoadXml(GetResponseBody(path)); var nsmgr = new XmlNamespaceManager(xml.NameTable); nsmgr.AddNamespace("openSearch", "http://a9.com/-/spec/opensearchrss/1.0/"); nsmgr.AddNamespace("gd", "http://schemas.google.com/g/2005"); nsmgr.AddNamespace("yt", "http://gdata.youtube.com/schemas/2007"); nsmgr.AddNamespace("atom", "http://www.w3.org/2005/Atom"); //nsmgr.AddNamespace("itunes", "http://www.itunes.com/dtds/podcast-1.0.dtd"); //nsmgr.AddNamespace("atom", "http://www.w3.org/2005/Atom"); //var userPlaylists = new YouTubePlaylistsSource() { var feedNode = xml.SelectSingleNode("/atom:feed", nsmgr); if (feedNode != null) { var titleNode = feedNode.SelectSingleNode("atom:title", nsmgr); var playlistsName = (titleNode != null) ? titleNode.InnerText : "Playlists"; var userPlaylists = source.Children.Where(x => x.Path == path).FirstOrDefault() as YouTubeUserPlaylistsSource; if (userPlaylists == null) { userPlaylists = Search(new Dictionary <string, object> { { "Path", path } }).FirstOrDefault() as YouTubeUserPlaylistsSource; if (userPlaylists == null) { userPlaylists = new YouTubeUserPlaylistsSource() { Name = playlistsName, Path = path, Parent = source }; Save(userPlaylists); } request.Invoke(() => source.AddChild(userPlaylists)); } var playlistNodes = feedNode.SelectNodes("atom:entry", nsmgr); if (playlistNodes != null && playlistNodes.Count > 0) { foreach (XmlNode node in playlistNodes) { GetYouTubePlaylist(userPlaylists, request, nsmgr, node); } } } }
private void GetYouTubePlaylist(YouTubeUserPlaylistsSource source, LoadSourceRequest request, XmlNamespaceManager nsmgr, XmlNode node) { var titleNode = node.SelectSingleNode("atom:title", nsmgr); var publishedNode = node.SelectSingleNode("atom:published", nsmgr); var contentNode = node.SelectSingleNode("atom:content", nsmgr); var authorNode = node.SelectSingleNode("atom:author/atom:name", nsmgr); var name = titleNode != null ? titleNode.InnerText : "Untitled Playlist"; var date = new DateTime(2000, 1, 1); if (publishedNode != null) { DateTime.TryParse(publishedNode.InnerText, out date); } var path = contentNode != null ? contentNode.Attributes["src"].Value : "unknown"; var creator = authorNode != null ? authorNode.InnerText : "Unknown Creator"; var playlist = source.Children.Where(x => x.Path == path).FirstOrDefault() as YouTubePlaylistSource; if (playlist == null) { playlist = Search(new Dictionary <string, object> { { "Path", path } }).FirstOrDefault() as YouTubePlaylistSource; if (playlist == null) { playlist = new YouTubePlaylistSource() { Name = name, Date = date, Creator = creator, Path = path, Parent = source }; Save(playlist); } request.Invoke(() => source.AddChild(playlist)); } GetYouTubeVideos(playlist, request); }