private void btnOpen_Click(object sender, EventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); dlg.Filter = "MP3 files (*.mp3)|*.mp3|WAV files (*.wav)|*.wav"; if (dlg.ShowDialog() == DialogResult.OK) { lbFile.Text = dlg.FileName; if (decoder != null) { decoder.Dispose(); } decoder = new NAudioDecoder(dlg.FileName); lbAudio.Text = String.Format("{0}Hz, {1}bit{2}, {3}", decoder.SampleRate, decoder.BitsPerSample, decoder.BitsPerSample != 16 ? " (not supported)" : "", decoder.Channels == 2 ? "stereo" : (decoder.Channels == 1 ? "mono" : "multi-channel")); lbDuration.Text = decoder.Duration.ToString(); if (decoder.Ready) { btnFingerPrint.Enabled = true; } ResetAll(); } }
internal static void Fingerprint(Database.Song row) { NAudioDecoder decoder = new NAudioDecoder(); string filename = row.Path + "\\" + row.Filename; if (System.IO.File.Exists(filename)) { decoder.Load(filename); string duration; int bits = decoder.SourceBitDepth; int channels = decoder.SourceChannels; if (decoder.Ready) { duration = decoder.Duration.ToString(); ChromaContext context = new ChromaContext(); context.Start(decoder.SampleRate, decoder.Channels); decoder.Decode(context.Consumer, 120); context.Finish(); // Release audio file handle. decoder.Dispose(); if (String.IsNullOrEmpty(AcoustID.Configuration.ApiKey)) { // TODO: display a prompt for api key. AcoustID.Configuration.ApiKey = "8XaBELgH"; } LookupService service = new LookupService(); List<Recording> recs = new List<Recording>(); List<LookupResult> results = service.Get(context.GetFingerprint(), decoder.Duration, new string[] { "recordings", "compress" }); foreach (LookupResult res in results) { foreach (Recording rec in res.Recordings) { recs.Add(rec); } } string _lastFmQueryAddress = RockBox.Properties.Resources.LastFmQueryAddress + "?"; string _lastFmApiKey = RockBox.Properties.Resources.LastFmApiKey; LastFmApi.Session s = new LastFmApi.Session(_lastFmApiKey, _lastFmQueryAddress); if (recs.Count > 0) { Recording li = recs[0]; string artist = ""; string title = ""; if (li.Artists.Count > 0) { artist = li.Artists[0].Name; } if (li.Title != null) { title = li.Title; } // we kinda have to do it this way because last.fm returns slightly different schema // depending on what data it has (Tags being a name value pair as opposed to a list of pairs, for example) try { LastFmApi.Query.Track.GetInfo q = new LastFmApi.Query.Track.GetInfo(artist, title); LastFmApi.DataTypes.Track.RootObject o = q.Get(s); ProcessTrack(o, row); Console.WriteLine("Processing " + row.Filename); } catch (Exception e) { LastFmApi.Query.Track2.GetInfo q = new LastFmApi.Query.Track2.GetInfo(artist, title); LastFmApi.DataTypes.Track2.RootObject o = q.Get(s); ProcessTrack2(o, row); Console.WriteLine("Processing " + row.Filename); } } else { Console.WriteLine("Couldn't find a recording for " + row.Filename); } } } }