Пример #1
0
        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);
                    }
                }
            }
        }
Пример #2
0
        private void GetYouTubeVideos(ISource source, LoadSourceRequest request)
        {
            if (!string.IsNullOrEmpty(source.Path) && source.Path != "unknown")
            {
                var xml = new XmlDocument();
                xml.LoadXml(GetResponseBody(source.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("media", "http://search.yahoo.com/mrss/");
                nsmgr.AddNamespace("atom", "http://www.w3.org/2005/Atom");

                AddVideos(source, request, xml, nsmgr);
            }
        }
Пример #3
0
        private void GetYouTubeUserFavorites(ISource source, LoadSourceRequest request)
        {
            var path = source.Path + "/favorites?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("media", "http://search.yahoo.com/mrss/");
            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 favoritesName = (titleNode != null) ? titleNode.InnerText : "Favorites";

                var favoritesSource = source.Children.Where(x => x.Path == path).FirstOrDefault() as YouTubeUserFavoritesSource;
                if (favoritesSource == null)
                {
                    favoritesSource = Search(new Dictionary <string, object>()
                    {
                        { "Path", path }
                    }).FirstOrDefault() as YouTubeUserFavoritesSource;
                    if (favoritesSource == null)
                    {
                        favoritesSource = new YouTubeUserFavoritesSource()
                        {
                            Name = favoritesName, Path = path, Parent = source
                        };
                        Save(favoritesSource);
                    }
                    request.Invoke(() => source.AddChild(favoritesSource));
                }

                AddVideos(favoritesSource, request, xml, nsmgr);
            }
        }
Пример #4
0
        private void LoadSource(ISource source, LoadSourceRequest request)
        {
            if (source is DeviceCatalogSource)
            {
                return;
            }

            if (source is HardDiskSource)
            {
                return;
            }

            if (source is OpticalDiscSource)
            {
                return;
            }

            if (source is DirectorySource)
            {
                return;
            }

            var track = Search(new Dictionary <string, object> {
                { "Path", source.Path }
            }).FirstOrDefault();

            if (track == null)
            {
                var uri = new Uri(source.Path);
                if (uri.IsFile && System.IO.File.Exists(source.Path))
                {
                    track = ReadFromTag(source.Path);
                    tagController.LoadPicture(track);
                }
                else
                {
                    track = ConvertToTrack(source);
                }
                Save(track);
            }
            request.Invoke(() => AddTrack(track));
        }
Пример #5
0
        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);
        }
Пример #6
0
        private void AddVideos(ISource source, LoadSourceRequest request, XmlDocument xml, XmlNamespaceManager nsmgr)
        {
            var entries = xml.SelectNodes("/atom:feed/atom:entry", nsmgr);

            if (entries != null && entries.Count > 0)
            {
                foreach (XmlNode entryNode in entries)
                {
                    var     titleNode = entryNode.SelectSingleNode("atom:title", nsmgr);
                    var     linkNodes = entryNode.SelectNodes("atom:link", nsmgr); //[@rel = \"alternate\"]", nsmgr);
                    XmlNode pathNode  = null;
                    foreach (XmlNode linkNode in linkNodes)
                    {
                        var rel = linkNode.Attributes["rel"].Value;
                        if (rel == "alternate")
                        {
                            pathNode = linkNode;
                            break;
                        }
                    }

                    XmlNode imageNode      = null;
                    var     thumbnailNodes = entryNode.SelectNodes("media:group/media:thumbnail", nsmgr);
                    foreach (XmlNode thumbnailNode in thumbnailNodes)
                    {
                        var thumbNailName = thumbnailNode.Attributes["yt:name"].Value;
                        if (thumbNailName == "hqdefault")
                        {
                            imageNode = thumbnailNode;
                            break;
                        }
                    }
                    //var authorNode = entryNode.SelectSingleNode("author/name", nsmgr);
                    //var thumbnailNode = entryNode.SelectSingleNode("media:thumbnail[@yt:name=\"hqdefault\"]", nsmgr);

                    var name = titleNode != null ? titleNode.InnerText : "Untitled Video";
                    var path = pathNode != null ? pathNode.Attributes["href"].Value : "unknown";
                    if (path != null && path != "unknown")
                    {
                        path = System.Web.HttpUtility.UrlDecode(path);
                    }

                    var imagePath = imageNode != null ? imageNode.Attributes["url"].Value : null;

                    var video = source.Children.Where(x => x.Path == path).FirstOrDefault() as YouTubeVideoSource;
                    if (video == null)
                    {
                        video = Search(new Dictionary <string, object> {
                            { "Path", path }
                        }).FirstOrDefault() as YouTubeVideoSource;
                        if (video == null)
                        {
                            video = new YouTubeVideoSource()
                            {
                                Name = name, Path = path, ImagePath = imagePath, Parent = source
                            };
                            Save(video);
                        }
                        request.Invoke(() => source.AddChild(video));
                    }
                }
            }
        }