public static void Test(string[] args) { string artist = null; string album = null; string title = null; int tracknum = 0; if (args != null) { for (int i = 0; i < args.Length; i++) { switch (args[i]) { case "-artist": artist = args[++i]; break; case "-album": album = args[++i]; break; case "-title": title = args[++i]; break; case "-tracknum": tracknum = Convert.ToInt32(args[++i], System.Globalization.NumberFormatInfo.InvariantInfo); break; } } } Console.WriteLine("Querying MusicBrainz with FileLookup request:"); Console.WriteLine(" Artist [{0}]", artist); Console.WriteLine(" Album [{0}]", album); Console.WriteLine(" Track [{0}]", title); Console.WriteLine(" Number [{0}]", tracknum); Console.WriteLine("---------------------------------------------"); using (MusicBrainzClient client = new MusicBrainzClient()) { SimpleTrack track = SimpleQuery.FileLookup(client, artist, album, title, tracknum, 0); Console.WriteLine("Artist: {0}", track.Artist); Console.WriteLine("Album: {0}", track.Album); Console.WriteLine("Track: {0}", track.Title); Console.WriteLine("Duration: {0}", track.Length); Console.WriteLine("Number: {0}", track.Number); Console.WriteLine("Count: {0}", track.TrackCount); Console.WriteLine("ASIN: {0}", track.Asin); } }
public static void Test(string[] args) { string artist = null; string album = null; string title = null; int tracknum = 0; if (args != null) { for(int i = 0; i < args.Length; i++) { switch(args[i]) { case "-artist": artist = args[++i]; break; case "-album": album = args[++i]; break; case "-title": title = args[++i]; break; case "-tracknum": tracknum = Convert.ToInt32(args[++i], System.Globalization.NumberFormatInfo.InvariantInfo); break; } } } Console.WriteLine("Querying MusicBrainz with FileLookup request:"); Console.WriteLine(" Artist [{0}]", artist); Console.WriteLine(" Album [{0}]", album); Console.WriteLine(" Track [{0}]", title); Console.WriteLine(" Number [{0}]", tracknum); Console.WriteLine("---------------------------------------------"); using (MusicBrainzClient client = new MusicBrainzClient()) { SimpleTrack track = SimpleQuery.FileLookup(client, artist, album, title, tracknum, 0); Console.WriteLine("Artist: {0}", track.Artist); Console.WriteLine("Album: {0}", track.Album); Console.WriteLine("Track: {0}", track.Title); Console.WriteLine("Duration: {0}", track.Length); Console.WriteLine("Number: {0}", track.Number); Console.WriteLine("Count: {0}", track.TrackCount); Console.WriteLine("ASIN: {0}", track.Asin); } }
public SimpleDisc(string device, MusicBrainzClient client) { this.client = client; client.Device = device; Debug.WriteLine("Before ReadCDToc"); ReadCDToc(); Debug.WriteLine("After ReadCDToc lengths.Length=" + lengths.Length.ToString(NumberFormatInfo.InvariantInfo)); tracks = new List <MediaItem>(lengths.Length); Debug.WriteLine("tracks.Count=" + tracks.Count.ToString(NumberFormatInfo.InvariantInfo)); for (int i = 0; i < lengths.Length; i++) { Debug.WriteLine("i=" + i.ToString(NumberFormatInfo.InvariantInfo)); if (lengths != null) { Debug.WriteLine("lengths[i]=" + lengths[i].ToString(NumberFormatInfo.InvariantInfo)); } else { Debug.WriteLine("lengths array is null"); } try { tracks.Add(new MediaItem()); //tracks.Add(new SimpleTrack(i + 1, lengths[i])); } catch (IndexOutOfRangeException) { Debug.WriteLine("index out of range trying to initialize tracks"); } catch (ArgumentOutOfRangeException) { Debug.WriteLine("argument out of range trying to initialize tracks"); } } }
public byte[] FinalizeSignature(string collectionId) { byte[] signature; // Create a MusicBrainz instance for the sole purpose of ensuring // a session is created and WSA_Init is called if neccessary. // Calls to WSA_Init are nestable, and cleanup will occur automatically // after this instance goes out-of-scope. MusicBrainzClient mb = new MusicBrainzClient(); signature = new byte[17]; int result = NativeMethods.trm_FinalizeSignature(handle, signature, (collectionId == null) ? null : ToUtf8(collectionId)); // Unlike most mb_* methods, trm_FinalizeSignature returns 0 on success if (result == 0) { return(signature); } else { return(null); } }
public byte[] FinalizeSignature(string collectionId) { byte[] signature; // Create a MusicBrainz instance for the sole purpose of ensuring // a session is created and WSA_Init is called if neccessary. // Calls to WSA_Init are nestable, and cleanup will occur automatically // after this instance goes out-of-scope. MusicBrainzClient mb = new MusicBrainzClient(); signature = new byte[17]; int result = NativeMethods.trm_FinalizeSignature(handle, signature, (collectionId == null) ? null : ToUtf8(collectionId)); // Unlike most mb_* methods, trm_FinalizeSignature returns 0 on success if (result == 0) return signature; else return null; }
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; }