Ejemplo n.º 1
0
        private void AddPlaylistItem(ISource source, IOldTrack track)
        {
            var item = sourceController.GetPlaylistItem(source, track);

            sourceController.Save(item);

            source.AddChild(item);
            source.IsExpanded = true;
            item.IsSelected   = true;
        }
Ejemplo n.º 2
0
        private void AddPlaylistItem(ISource source, IOldTrack track)
        {
            var item = sourceController.GetPlaylistItem(source, track);

            sourceController.Save(item);

            source.AddChild(item);
            source.IsExpanded = true;
            item.IsSelected = true;
        }
Ejemplo n.º 3
0
 private void LoadSourceChildren(ISource source)
 {
     var children = sourceController.Search(new Dictionary<string, object> { { "Parent", source.Id.ToString() } });
     if (children != null && children.Count() > 0)
     {
         foreach (var child in children)
         {
             child.Parent = source;
             source.AddChild(child);
             LoadSourceChildren(child);
         }
     }
 }
Ejemplo n.º 4
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);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        private void LoadSourceChildren(ISource source)
        {
            var children = sourceController.Search(new Dictionary <string, object> {
                { "Parent", source.Id.ToString() }
            });

            if (children != null && children.Count() > 0)
            {
                foreach (var child in children)
                {
                    child.Parent = source;
                    source.AddChild(child);
                    LoadSourceChildren(child);
                }
            }
        }
Ejemplo n.º 6
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);
            }
        }
Ejemplo n.º 7
0
        public void LoadDirectories(ISource source)
        {
            if (source.Children.Count() == 1)
            {
                //var proxy = source.Children.FirstOrDefault() as ProxySource;
                //if (proxy != null)
                //    source.RemoveChild(proxy);

                if (Directory.Exists(source.Path))
                {
                    var directory = new DirectoryInfo(source.Path);
                    foreach (var subDirectory in directory.GetDirectories())
                    {
                        var child = source.Children.Where(x => x.Path == subDirectory.FullName).FirstOrDefault();
                        if (child == null)
                        {
                            child = new DirectorySource()
                            {
                                Name = subDirectory.Name, Path = subDirectory.FullName, Parent = source
                            };
                            source.AddChild(child);
                        }
                        //LoadDirectories(child);
                    }
                    foreach (var file in directory.GetFiles("*.mp3"))
                    {
                        try
                        {
                            var track = trackController.Search(new Dictionary <string, object> {
                                { "Path", file.FullName }
                            }).FirstOrDefault();
                            if (track == null)
                            {
                                track = trackController.ReadFromTag(file.FullName);
                                trackController.Save(track);
                            }

                            var item = GetPlaylistItem(source, track);
                            source.AddChild(item);
                        }
                        catch (Exception ex)
                        {
                            log.Error("SourceController.LoadDirectories: Could not load MP3 file. path=" + file.FullName, ex);
                        }
                    }
                    foreach (var file in directory.GetFiles("*.wav"))
                    {
                        try
                        {
                            var track = trackController.Search(new Dictionary <string, object> {
                                { "Path", file.FullName }
                            }).FirstOrDefault();
                            if (track == null)
                            {
                                track = new OldTrack {
                                    Path = file.FullName, Title = file.Name
                                };
                                trackController.Save(track);
                            }

                            var item = GetPlaylistItem(source, track);
                            source.AddChild(item);
                        }
                        catch (Exception ex)
                        {
                            log.Error("SourceController.LoadDirectories: Could not load WAV file. path=" + file.FullName, ex);
                        }
                    }
                }
            }
        }
Ejemplo n.º 8
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));
                    }
                }
            }
        }