private void ReadCDToc() { client.Query(rdf.QueryGetCDToc); int track_count = client.GetResultInt(rdf.ExpressionTocGetLastTrack); if (track_count <= 0) { // "Reading audio CD Table of Contents returned an invalid track count." throw new ApplicationException("Reading audio CD Table of Contents returned an invalid track count."); } lengths = new int[track_count]; for (int i = 1; i <= lengths.Length; i++) { lengths[i - 1] = SectorsToSeconds(client.GetResultInt(rdf.ExpressionTocGetTrackNumberSectors, i + 1)); } }
private SimpleAlbum DebugLookupAlbumById(string id) { SimpleAlbum album = null; StringBuilder output = new StringBuilder(); string data, temp = null; bool ret, isMultipleArtist = false; int numTracks, trackNum = 0; //string id = //"cCQzv12PgDzszIK8_ZLHSK7oHJc-"; // Create the musicbrainz object, which will be needed for subsequent calls //MusicBrainzClient o = new MusicBrainzClient(); //Client o = new Client(); // Set the proper server to use. Defaults to mm.musicbrainz.org:80 if (Environment.GetEnvironmentVariable("MB_SERVER") != null) { client.Server = new ServerInfo(Environment.GetEnvironmentVariable("MB_SERVER"), 80); } // Check to see if the debug env var has been set if (Environment.GetEnvironmentVariable("MB_DEBUG") != null) { client.Debug = (Environment.GetEnvironmentVariable("MB_DEBUG") != "0"); } // Tell the server to only return 2 levels of data, unless the MB_DEPTH env var is set if (Environment.GetEnvironmentVariable("MB_DEPTH") != null) { client.QueryDepth = (int.Parse(Environment.GetEnvironmentVariable("MB_DEPTH"), System.Globalization.CultureInfo.InvariantCulture)); } else { client.QueryDepth = 4; } // Set up the args for the find album query string[] args = new string[] { id }; if (id.Length != MusicBrainzConstants.CDINDEX_ID_LEN) { // Execute the MBQ_GetAlbumById query ret = client.Query(rdf.QueryGetAlbumById, args); } else { // Execute the MBQ_GetCDInfoFromCDIndexId ret = client.Query(rdf.QueryGetCDInfoFromCDIndexId, args); } if (!ret) { //o.GetQueryError(out error); System.Diagnostics.Debug.WriteLine("Query failed: {0}", client.QueryError); return(album); //o.QueryError; } // Select the first album client.Select(rdf.SelectAlbum, 1); // Pull back the album id to see if we got the album data = client.GetResultData(rdf.ExpressionAlbumGetAlbumId); if (client.CurrentResult == 0) { System.Diagnostics.Debug.WriteLine("Album not found."); return(album); //string.Empty; } temp = client.GetIdFromUrl(data); System.Diagnostics.Debug.WriteLine(" AlbumId: {0}", temp); output.AppendLine("AlbumId: " + temp); // Extract the album name data = client.GetResultData(rdf.ExpressionAlbumGetAlbumName); if (client.CurrentResult != 0) { System.Diagnostics.Debug.WriteLine(" Name: {0}", data); output.AppendLine("Name: " + data); } // Extract the number of tracks numTracks = client.GetResultInt(rdf.ExpressionAlbumGetNumberTracks); if (numTracks > 0 && numTracks < 100) { System.Diagnostics.Debug.WriteLine(" NumTracks: {0}", numTracks.ToString(System.Globalization.NumberFormatInfo.InvariantInfo)); output.AppendLine("Tracks: " + numTracks.ToString(System.Globalization.NumberFormatInfo.InvariantInfo)); } // Check to see if there is more than one artist for this album for (int i = 1; i <= numTracks; i++) { data = client.GetResultData(rdf.ExpressionAlbumGetArtistId, i); if (client.CurrentResult == 0) { break; } if (i == 1) { temp = data; } if (temp != data) { isMultipleArtist = true; break; } } if (!isMultipleArtist) { // Extract the artist name from the album data = client.GetResultData(rdf.ExpressionAlbumGetArtistName, 1); if (client.CurrentResult != 0) { System.Diagnostics.Debug.WriteLine("AlbumArtist: {0}", data); output.AppendLine("Album Artist: " + data); } // Extract the artist id from the album data = client.GetResultData(rdf.ExpressionAlbumGetArtistId, 1); if (client.CurrentResult != 0) { temp = client.GetIdFromUrl(data); System.Diagnostics.Debug.WriteLine(" ArtistId: {0}", temp); output.AppendLine("ArtistId: " + temp); } } System.Diagnostics.Debug.WriteLine(string.Empty); for (int i = 1; i <= numTracks; i++) { // Extract the track name from the album. data = client.GetResultData(rdf.ExpressionAlbumGetTrackName, i); if (client.CurrentResult != 0) { System.Diagnostics.Debug.WriteLine(" Track: {0}", data); output.AppendLine("Track: " + data); } else { break; } // Extract the album id from the track. Just use the // first album that this track appears on data = client.GetResultData(rdf.ExpressionAlbumGetTrackId, i); if (client.CurrentResult != 0) { temp = client.GetIdFromUrl(data); System.Diagnostics.Debug.WriteLine(" TrackId: {0}", temp); output.AppendLine("TrackId: " + temp); // Extract the track number trackNum = client.GetOrdinalFromList(rdf.ExpressionAlbumGetTrackList, data); if (trackNum > 0 && trackNum < 100) { System.Diagnostics.Debug.WriteLine(" TrackNum: {0}", trackNum.ToString(System.Globalization.NumberFormatInfo.InvariantInfo)); output.AppendLine("Track Number: " + trackNum.ToString(System.Globalization.NumberFormatInfo.InvariantInfo)); } } // If its a multple artist album, print out the artist for each track if (isMultipleArtist) { // Extract the artist name from this track data = client.GetResultData(rdf.ExpressionAlbumGetArtistName, i); if (client.CurrentResult != 0) { System.Diagnostics.Debug.WriteLine("TrackArtist: {0}", data); output.AppendLine("Track Artist: " + data); } // Extract the artist id from this track data = client.GetResultData(rdf.ExpressionAlbumGetArtistId, i); if (client.CurrentResult != 0) { temp = client.GetIdFromUrl(data); System.Diagnostics.Debug.WriteLine(" ArtistId: {0}", temp); output.AppendLine("Track ArtistId: " + temp); } } System.Diagnostics.Debug.WriteLine(string.Empty); } //return output.ToString(); return(album); }
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); }
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; }