Beispiel #1
0
 public Album(string id, string name, Artist artist)
 {
     this.id = id;
     this.name = name;
     this.artist = artist;
     songs = new Dictionary<string, Song>();
 }
Beispiel #2
0
 public Album(string id, string name, Artist artist)
 {
     this.id = id;
     if(!String.IsNullOrEmpty(name))
         this.name = name;
     this.artist = artist;
     songs = new Dictionary<string, Song>();
 }
Beispiel #3
0
 public Song(string title, Album album, Artist artist, string mediaFilePath,Nullable<uint> albumTrack, string trackId, TimeSpan duration )
 {
     this.title = title;
     this.album = album;
     this.artist = artist;
     this.mediaFilePath = mediaFilePath;
     this.albumTrack = albumTrack;
     this.id = trackId;
     this.duration = duration;
 }
        public void Initialize()
        {
            artistDictionary = new Dictionary<string, Artist>();
            WindowsMediaPlayer wmp = new WindowsMediaPlayerClass();
            var items = wmp.mediaCollection.getByAttribute("MediaType", "audio");

            int albumId = 0;
            int artistId = 0;

            for (int i = 0; i < items.count; i++)
            {
                IWMPMedia media = items.get_Item(i);
                string albumArtistName = media.getItemInfo("AlbumArtist").Trim();
                if (albumArtistName == "")
                {
                    albumArtistName = media.getItemInfo("Artist").Trim();
                    if(albumArtistName == "")
                        albumArtistName = "Unknown";
                }
                string albumName = media.getItemInfo("Album").Trim();
                if (albumName == "")
                    albumName = "Unknown";
                string trackName = media.getItemInfo("Title").Trim();
                if (trackName == "")
                    trackName = "Unknown"+i;
                string trackLocation = media.getItemInfo("SourceUrl");
                string trackNumberString = media.getItemInfo("OriginalIndex");
                uint trackNumber = 0;
                var duration = TimeSpan.FromSeconds(media.duration);
                UInt32.TryParse(trackNumberString, out trackNumber);

                Artist artist;

                if (!artistDictionary.TryGetValue(albumArtistName, out artist))
                {
                    artist = new Artist("artist"+artistId++, albumArtistName);
                    artistDictionary.Add(albumArtistName, artist);
                }

                Album album = (Album)artist.Albums.FirstOrDefault(al => al.Name == albumName);
                if(album == null)
                    album = artist.AddAlbum("album"+albumId++, albumName);

                Song song = new Song(trackName, album, artist, trackLocation, trackNumber, i.ToString(), duration);
                album.AddSong(song);
            }
        }
        public void Initialize()
        {
            XDocument xmlDoc = XDocument.Load(rhythmboxDatabase);

            var entries = from e in xmlDoc.Descendants("entry")
                where ((string)e.Attribute("type")).Equals("song")
                select new
            {
                Title = (string)e.Element("title"),
                Artist = (string)e.Element("artist"),
                Album = (string)e.Element("album"),
                Location = (string) e.Element("location"),
                ArtistId = (string) e.Element("mb-artistid"),
                AlbumId = (string) e.Element("mb-albumid"),
                TrackNumber = (string) e.Element("track-number"),
                TrackId = (string) e.Element("mb-trackid"),
                Duration = (string) e.Element("duration")
            };

            int entryCount = 0;
            foreach( var entry in entries)
            {
                entryCount++;
                Artist a;
                if( artists.ContainsKey(entry.ArtistId))
                {
                    a = artists[entry.ArtistId];
                }
                else
                {
                    a = new Artist(entry.ArtistId, entry.Artist);
                    artists.Add(entry.ArtistId,a);
                }
                a.AddAlbum(entry.AlbumId, entry.Album);
                var duration = TimeSpan.FromSeconds(Int32.Parse(entry.Duration));
                a.AddSong(entry.AlbumId,entry.Title, entry.Location, Convert.ToUInt32(entry.TrackNumber), entry.TrackId, duration);
            }
            log.Debug(entryCount+ " entries found in rhythmbox user database.");
        }
        private void FillArtistsList(IDbConnection dbcon)
        {
            using (IDbCommand dbcmd = dbcon.CreateCommand())
            {
                string sql =
                    "SELECT ArtistID, Name " +
                    "FROM CoreArtists";
                dbcmd.CommandText = sql;

                using (IDataReader reader = dbcmd.ExecuteReader())
                {
                    while (reader.Read())
                    {

                        Artist a;
                        string ArtistID = reader.GetValue(0).ToString();
                        string ArtistName = reader.GetValue(1).ToString();
                        if (artists.ContainsKey(ArtistID))
                        {
                            a = artists[ArtistID];
                        }
                        else
                        {
                            a = new Artist(ArtistID, ArtistName);
                            artists.Add(ArtistID, a);
                        }
                    }
                }
            }
        }