Пример #1
0
        public static SimpleTrack FileLookup(MusicBrainzClient client, string artistName, string albumName, string trackName, int trackNumber, int duration)
        {
            Rdf rdf = new Rdf();

            SimpleTrack track = null;

            if (client != null)
            {
                client.QueryDepth = 4;

                if (!client.Query(rdf.QueryFileInfoLookup, new string[]
                                  { string.Empty,             // trmid
                                    artistName,
                                    albumName,
                                    trackName,
                                    trackNumber.ToString(System.Globalization.CultureInfo.InvariantCulture),
                                    duration.ToString(System.Globalization.CultureInfo.InvariantCulture),
                                    string.Empty,             // filename
                                    string.Empty,             // artistid
                                    string.Empty,             // albumid
                                    string.Empty }))
                {
                    //"File Lookup Query unsuccessful"
                    throw new ApplicationException("File Lookup Query unsuccessful");
                }

                client.Select(rdf.SelectRewind);

                if (!client.Select(rdf.SelectLookupResult, 1))
                {
                    // "Selection failed"
                    throw new ApplicationException("Selection failed");
                }

                track = new SimpleTrack();
                string result_type = client.GetId(client.GetResultData(rdf.ExpressionLookupGetType));

                switch (result_type)
                {
                case "AlbumTrackResult":
                    client.Select(rdf.SelectLookupResultTrack);
                    //track.Title = client.GetResultData(rdf.ExpressionTrackGetTrackName);
                    track.Title  = client.GetResultData(rdf.ExpressionTrackGetTrackName);
                    track.Artist = client.GetResultData(rdf.ExpressionTrackGetArtistName);
                    int length = (client.GetResultInt(rdf.ExpressionTrackGetTrackDuration) / 1000);
                    track.Duration = new TimeSpan(0, 0, 0, 0, length);
                    //track.Length = client.GetResultInt(rdf.ExpressionTrackGetTrackDuration);
                    client.Select(rdf.SelectBack);

                    client.Select(rdf.SelectLookupResultAlbum, 1);
                    track.Album      = client.GetResultData(rdf.ExpressionAlbumGetAlbumName);
                    track.TrackCount = client.GetResultInt(rdf.ExpressionAlbumGetNumberTracks);
                    track.Number     = client.GetResultInt(rdf.ExpressionAlbumGetTrackNumber);
                    track.Asin       = client.GetResultData(rdf.ExpressionAlbumGetAmazonAsin);
                    client.Select(rdf.SelectBack);
                    break;

                case "AlbumResult":
                    client.Select(rdf.SelectLookupResultAlbum, 1);
                    track.TrackCount = client.GetResultInt(rdf.ExpressionAlbumGetNumberTracks);
                    track.Album      = client.GetResultData(rdf.ExpressionAlbumGetAlbumName);
                    track.Asin       = client.GetResultData(rdf.ExpressionAlbumGetAmazonAsin);

                    string track_id = client.GetResultData(rdf.ExpressionAlbumGetTrackId, trackNumber);

                    if (client.Query(rdf.QueryGetTrackById, new string[] { client.GetId(track_id) }))
                    {
                        client.Select(rdf.SelectTrack, 1);
                        //track.Title = client.GetResultData(rdf.ExpressionTrackGetTrackName);
                        track.Title  = client.GetResultData(rdf.ExpressionTrackGetTrackName);
                        track.Artist = client.GetResultData(rdf.ExpressionTrackGetArtistName);
                        track.Number = client.GetResultInt(rdf.ExpressionTrackGetTrackNumber);
                        track.Length = client.GetResultInt(rdf.ExpressionTrackGetTrackDuration);
                        client.Select(rdf.SelectBack);
                    }

                    client.Select(rdf.SelectBack);
                    break;

                default:
                    //"Invalid result type: " + result_type
                    throw new ApplicationException("Invalid result type: " + result_type);
                }
            }
            return(track);
        }
Пример #2
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);
        }
Пример #3
0
        public static SimpleTrack FileLookup(MusicBrainzClient client, string artistName, string albumName, string trackName, int trackNumber, int duration)
        {
			Rdf rdf = new Rdf();
        
			SimpleTrack track = null;
        
			if (client != null)
			{
				client.QueryDepth = 4;

				if (!client.Query(rdf.QueryFileInfoLookup, new string[]
					{	string.Empty, // trmid
						artistName,
						albumName,
						trackName,
						trackNumber.ToString(System.Globalization.CultureInfo.InvariantCulture),
						duration.ToString(System.Globalization.CultureInfo.InvariantCulture),
						string.Empty, // filename
						string.Empty, // artistid
						string.Empty, // albumid
						string.Empty
					}))
				{
					//"File Lookup Query unsuccessful"
					throw new ApplicationException("File Lookup Query unsuccessful");
				}

				client.Select(rdf.SelectRewind);

				if (!client.Select(rdf.SelectLookupResult, 1))
				{
					// "Selection failed"
					throw new ApplicationException("Selection failed");
				}
				
				track = new SimpleTrack();
				string result_type = client.GetId(client.GetResultData(rdf.ExpressionLookupGetType));
            
				switch(result_type)
				{
					case "AlbumTrackResult":
						client.Select(rdf.SelectLookupResultTrack);
						//track.Title = client.GetResultData(rdf.ExpressionTrackGetTrackName);
						track.Title = client.GetResultData(rdf.ExpressionTrackGetTrackName);
						track.Artist = client.GetResultData(rdf.ExpressionTrackGetArtistName);
						int length = (client.GetResultInt(rdf.ExpressionTrackGetTrackDuration) / 1000);
						track.Duration = new TimeSpan(0, 0, 0, 0, length);
						//track.Length = client.GetResultInt(rdf.ExpressionTrackGetTrackDuration);
						client.Select(rdf.SelectBack);

						client.Select(rdf.SelectLookupResultAlbum, 1);
						track.Album = client.GetResultData(rdf.ExpressionAlbumGetAlbumName);
						track.TrackCount = client.GetResultInt(rdf.ExpressionAlbumGetNumberTracks);
						track.Number = client.GetResultInt(rdf.ExpressionAlbumGetTrackNumber);
						track.Asin = client.GetResultData(rdf.ExpressionAlbumGetAmazonAsin);
						client.Select(rdf.SelectBack);
						break;
					case "AlbumResult":
						client.Select(rdf.SelectLookupResultAlbum, 1);
						track.TrackCount = client.GetResultInt(rdf.ExpressionAlbumGetNumberTracks);
						track.Album = client.GetResultData(rdf.ExpressionAlbumGetAlbumName);
						track.Asin = client.GetResultData(rdf.ExpressionAlbumGetAmazonAsin);

						string track_id = client.GetResultData(rdf.ExpressionAlbumGetTrackId, trackNumber);

						if (client.Query(rdf.QueryGetTrackById, new string[] { client.GetId(track_id) }))
						{
							client.Select(rdf.SelectTrack, 1);
							//track.Title = client.GetResultData(rdf.ExpressionTrackGetTrackName);
							track.Title = client.GetResultData(rdf.ExpressionTrackGetTrackName);
							track.Artist = client.GetResultData(rdf.ExpressionTrackGetArtistName);
							track.Number = client.GetResultInt(rdf.ExpressionTrackGetTrackNumber);
							track.Length = client.GetResultInt(rdf.ExpressionTrackGetTrackDuration);
							client.Select(rdf.SelectBack);
						}

						client.Select(rdf.SelectBack);
						break;
					default:
						//"Invalid result type: " + result_type
						throw new ApplicationException("Invalid result type: " + result_type);
				}
            }
            return track;
        }