Esempio n. 1
0
        private void Search(string startingDirectory)
        {
            DirectoryInfo X = new DirectoryInfo(startingDirectory);
            Collection _Collection = new Collection();
            Artist _Artist = new Artist();
            Album _Album = new Album();
            _Collection.Artists.Add(_Artist);
            _Artist.Albums.Add(_Album);
            Collections.Add(_Collection);
            try
            {
                foreach (FileInfo _File in X.GetFiles())
                {
                    if (_File.FullName.EndsWith(".mp3"))
                    {
                        TagLib.Mpeg.File Sn = new TagLib.Mpeg.File(_File.FullName);

                        Song _Song = new Song();
                        _Song.Name = Sn.Tag.Title;
                        _Song.Artist = Sn.Tag.Artists[0];
                        _Album.Songs.Add(_Song);
                        _Song.Type = "application/mp3";
                        _Song.File = _File.FullName;

                    }
                    else if (_File.FullName.EndsWith(".txt"))
                    {

                        {
                            Song _Song = new Song();
                            _Song.Name = _File.Name;
                            _Song.Artist = _File.DirectoryName;

                            _Album.Songs.Add(_Song);
                            _Song.Type = "text";
                            _Song.File = _File.FullName;
                        }
                    }
                    else if (_File.Extension == "exe")
                    {
                        Song _Song = new Song();
                        _Song.Artist = (_File.DirectoryName);
                        _Song.Name = _File.Name;
                        _Song.Type="application/exe";
                        _Album.Songs.Add(_Song);
                    }
                }

                foreach (DirectoryInfo Dir in X.GetDirectories())
                {
                    SearchX(Dir.FullName, _Album);
                }
            }
            catch
            {
            }
            List();
        }
Esempio n. 2
0
        public void LoadCollection(string fileName)
        {
            this.collections.Clear();
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(fileName);
            if (xmlDoc.DocumentElement.Name == "collection")
            {
                Collection _Collection = new Collection();
                _Collection.Name = xmlDoc.GetElementsByTagName("name")[0].InnerText;
                XmlNodeList xnlArtists = xmlDoc.GetElementsByTagName("artist");

                foreach (XmlElement Artist in xnlArtists)
                {
                    Artist _Artist = new Artist();
                    _Artist.Name = Artist.GetAttribute("name");
                    XmlNodeList xnlAlbums = Artist.GetElementsByTagName("album");
                    foreach (XmlElement xeAlbum in xnlAlbums)
                    {
                        Album _Album = new Album();
                        _Album.Name = xeAlbum.GetAttribute("name");
                        XmlNodeList xnlSongs = xeAlbum.GetElementsByTagName("song");
                        foreach (XmlElement XeSong in xnlSongs)
                        {
                            Song R = new Song();
                            R.Name = XeSong.GetAttribute("name");
                            R.Artist = XeSong.GetAttribute("artist");
                            R.File = XeSong.GetAttribute("path");
                            R.Type = XeSong.GetAttribute("type");
                            try
                            {
                                R.Number = int.Parse(XeSong.GetAttribute("number"));
                            }
                            catch
                            {
                                R.Number = 0;
                            }
                            _Album.Songs.Add(R);
                        }
                        _Artist.Albums.Add(_Album);
                    }
                    _Collection.Artists.Add(_Artist);
                }
                collections.Add(_Collection);
                List();
            }
            else if (xmlDoc.DocumentElement.Name == "rss")
            {
                Collection SR = new Collection();
                SR.Name = xmlDoc.GetElementsByTagName("title")[0].InnerText;
                XmlNodeList Items = xmlDoc.GetElementsByTagName("item");
                string Author = xmlDoc.GetElementsByTagName("copyright")[0].InnerText;
                Artist X = new Artist();
                X.Name = Author;
                SR.Artists.Add(X);
                Album _Album = new Album();
                _Album.Name = SR.Name;
                X.Albums.Add(_Album);
                int i = 0;
                foreach (XmlElement Item in Items)
                {
                    XmlNode Enclosure = Item.GetElementsByTagName("enclosure")[0];
                    Song S = new Song();
                    S.Name = Item.GetElementsByTagName("title")[0].InnerText;
                    S.Artist = Author;
                    S.File = Enclosure.Attributes["url"].InnerText;
                    S.Number = i;
                    S.Type = "application/mp3";
                    _Album.Songs.Add(S);
                    i++;
                }
                Collections.Add(SR);
            }
            List();
        }