Пример #1
0
        private SimpleAlbum LookupAlbumById(string musicBrainzId, Uri path)
        {
            System.Diagnostics.Debug.WriteLine("Parameter AlbumID=" + musicBrainzId);

            client.QueryDepth = 4;
            musicBrainzId     = client.GetId(musicBrainzId);

            System.Diagnostics.Debug.WriteLine("Client AlbumID=" + musicBrainzId);

            bool query  = client.Query(rdf.QueryGetAlbumById, new string[] { musicBrainzId });
            bool select = client.Select(rdf.SelectAlbum, 1);

            if (!query || !select)
            {
                string error = client.QueryError;
                System.Diagnostics.Debug.WriteLine("query=" + query.ToString() + " select=" + select.ToString() + " error=" + error);
                // could not fetch album
                throw new ApplicationException("Could not fetch album");
            }

            //NOTE: does this need to be a different variable?
            musicBrainzId = client.GetId(client.GetResultData(rdf.ExpressionAlbumGetAlbumId));

            string       asin             = client.GetResultData(rdf.ExpressionAlbumGetAmazonAsin);
            Uri          coverArtUrl      = new Uri(client.GetResultData(rdf.ExpressionAlbumGetAmazonCoverArtUrl));
            string       artistName       = client.GetResultData(rdf.ExpressionAlbumGetArtistName);
            string       artistSortName   = client.GetResultData(rdf.ExpressionAlbumGetArtistSortName);
            string       artistId         = client.GetResultData(rdf.ExpressionAlbumGetAlbumArtistId);
            bool         isVariousArtists = (artistId == rdf.IdVariousArtist);
            SimpleArtist albumArtist      = new SimpleArtist(new Guid(artistId), artistName, DateTime.MinValue, DateTime.MinValue, artistSortName);

            Console.WriteLine(artistName);
            string albumName = client.GetResultData(rdf.ExpressionAlbumGetAlbumName);

            int trackCount = client.GetResultInt(rdf.ExpressionAlbumGetNumberTracks, 1);

            if (trackCount <= 0)
            {
                // Invalid track count from album query
                throw new ApplicationException("Invalid track count from album query");
            }

            DateTime releaseDate = new DateTime(1900, 1, 1);

            if (client.GetResultInt(rdf.ExpressionAlbumGetNumberReleaseDates) > 0)
            {
                client.Select(rdf.SelectReleaseDate, 1);
                releaseDate = Utility.ToDateTime(client.GetResultData(rdf.ExpressionReleaseGetDate));
                client.Select(rdf.SelectBack);
            }

            SimpleAlbum album = new SimpleAlbum(Guid.NewGuid(), albumName, artistName, releaseDate, path);

            album.VariousArtists = isVariousArtists;

            for (int number = 1; number <= trackCount; number++)
            {
                client.Select(rdf.SelectTrack, number);
                string   artist       = client.GetResultData(rdf.ExpressionTrackGetArtistName);
                string   title        = client.GetResultData(rdf.ExpressionTrackGetTrackName);
                int      milliseconds = (client.GetResultInt(rdf.ExpressionTrackGetTrackDuration) / 1000);
                TimeSpan duration     = new TimeSpan(0, 0, 0, 0, milliseconds);
                //SimpleTrack track = new SimpleTrack(Guid.NewGuid(), number, title, artist, albumName, duration, releaseDate, MusicBrainzConstants.FORMAT_CD, path);
                MediaItem track = new MediaItem(Guid.NewGuid(), ModelConstants.MEDIA_SOURCE_CD, ModelConstants.MEDIA_TYPE_AUDIO, number, title, artist, albumName, duration, releaseDate, MusicBrainzConstants.FORMAT_CD, path);
                album.Items.Add(track);
                //track.Number, track);

                client.Select(rdf.SelectBack);
            }

            client.Select(rdf.SelectBack);

            return(album);
        }
		private SimpleAlbum LookupAlbumById(string musicBrainzId, Uri path)
		{
			System.Diagnostics.Debug.WriteLine("Parameter AlbumID=" + musicBrainzId);

			client.QueryDepth = 4;
			musicBrainzId = client.GetId(musicBrainzId);

			System.Diagnostics.Debug.WriteLine("Client AlbumID=" + musicBrainzId);

			bool query = client.Query(rdf.QueryGetAlbumById, new string[] { musicBrainzId });
			bool select = client.Select(rdf.SelectAlbum, 1);

			if (!query || !select)
			{
				string error = client.QueryError;
				System.Diagnostics.Debug.WriteLine("query=" + query.ToString() + " select=" + select.ToString() + " error=" + error);
				// could not fetch album
				throw new ApplicationException("Could not fetch album");
			}

			//NOTE: does this need to be a different variable?
			musicBrainzId = client.GetId(client.GetResultData(rdf.ExpressionAlbumGetAlbumId));
			
			string asin = client.GetResultData(rdf.ExpressionAlbumGetAmazonAsin);
			Uri coverArtUrl = new Uri(client.GetResultData(rdf.ExpressionAlbumGetAmazonCoverArtUrl));
			string artistName = client.GetResultData(rdf.ExpressionAlbumGetArtistName);
			string artistSortName = client.GetResultData(rdf.ExpressionAlbumGetArtistSortName);
			string artistId = client.GetResultData(rdf.ExpressionAlbumGetAlbumArtistId);
			bool isVariousArtists = (artistId == rdf.IdVariousArtist);
			SimpleArtist albumArtist = new SimpleArtist(new Guid(artistId), artistName, DateTime.MinValue, DateTime.MinValue, artistSortName);

			Console.WriteLine(artistName);
			string albumName = client.GetResultData(rdf.ExpressionAlbumGetAlbumName);

			int trackCount = client.GetResultInt(rdf.ExpressionAlbumGetNumberTracks, 1);

			if (trackCount <= 0)
			{
				// Invalid track count from album query            
				throw new ApplicationException("Invalid track count from album query");
			}

			DateTime releaseDate = new DateTime(1900, 1, 1);
			if (client.GetResultInt(rdf.ExpressionAlbumGetNumberReleaseDates) > 0)
			{
				client.Select(rdf.SelectReleaseDate, 1);
				releaseDate = Utility.ToDateTime(client.GetResultData(rdf.ExpressionReleaseGetDate));
				client.Select(rdf.SelectBack);
			}
			
			SimpleAlbum album = new SimpleAlbum(Guid.NewGuid(), albumName, artistName, releaseDate, path);
			album.VariousArtists = isVariousArtists;

			for (int number = 1; number <= trackCount; number++)
			{
				client.Select(rdf.SelectTrack, number);
				string artist = client.GetResultData(rdf.ExpressionTrackGetArtistName);
				string title = client.GetResultData(rdf.ExpressionTrackGetTrackName);
				int milliseconds = (client.GetResultInt(rdf.ExpressionTrackGetTrackDuration) / 1000);
				TimeSpan duration = new TimeSpan(0, 0, 0, 0, milliseconds);
				//SimpleTrack track = new SimpleTrack(Guid.NewGuid(), number, title, artist, albumName, duration, releaseDate, MusicBrainzConstants.FORMAT_CD, path);
                MediaItem track = new MediaItem(Guid.NewGuid(), ModelConstants.MEDIA_SOURCE_CD, ModelConstants.MEDIA_TYPE_AUDIO, number, title, artist, albumName, duration, releaseDate, MusicBrainzConstants.FORMAT_CD, path);
				album.Items.Add(track);
					//track.Number, track);
				
				client.Select(rdf.SelectBack);
			}

			client.Select(rdf.SelectBack);
			
			return album;
		}