Example #1
0
        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);
                    }
                }
            }
        }
Example #2
0
        private void lvRecordings_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (_canFingerprint)
            {
                //ClearText();

                string _lastFmQueryAddress = RockBox.Properties.Resources.LastFmQueryAddress + "?";
                string _lastFmApiKey = RockBox.Properties.Resources.LastFmApiKey;

                LastFmApi.Session s = new LastFmApi.Session(_lastFmApiKey, _lastFmQueryAddress);
                RecordingItem li = lvRecordings.SelectedItem as RecordingItem;


                // 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(li.Artist, li.Title);
                    LastFmApi.DataTypes.Track.RootObject o = q.Get(s);
                    ProcessTrack(o);
                }
                catch (Exception ex)
                {
                    LastFmApi.Query.Track2.GetInfo q = new LastFmApi.Query.Track2.GetInfo(li.Artist, li.Title);
                    LastFmApi.DataTypes.Track2.RootObject o = q.Get(s);
                    ProcessTrack2(o);
                }


            }
        }