sampsyo/beets — pull request #420 by pscn (2013-10-16 10:46:02+00:00)
Title: Fixed song matching in echonest_tempo plugin

Some of the code in the echonest_tempo plugin hinted at the possibility to pick the correct artist / title match from a set of results. However, only one result was fetched and in case of a match always the first result would have been returned (which works when only fetching one result).

I updated the code, to fetch 100 results (maximum according to the EchoNest API) and also use the track length / duration as an extra indicator for a good match.

Before (no match):

```bash
beet -v tempo -p title:"walking on sunshine" artist:"Katrina and the Waves"
[ ... ]
tempo not found: Katrina and the Waves - Walking on Sunshine
```

After (best match is the one with a distance of 1.07 seconds between my local track and the EchoNest track):
```bash
beet -v tempo -p title:"walking on sunshine" artist:"Katrina and the Waves"
[ ... ]
echonest_tempo: candidate Katrina and the Waves - Walking On Sunshine [abs(228.29-239.03)=10.74] = 110.156
echonest_tempo: candidate Katrina and the Waves - Walking On Sunshine [abs(159.69-239.03)=79.34] = 109.512
echonest_tempo: candidate Katrina and the Waves - Walking On Sunshine [abs(332.33-239.03)=93.30] = 109.416
echonest_tempo: candidate Katrina and the Waves - Walking On Sunshine [abs(203.28-239.03)=35.75] = 127.984
echonest_tempo: candidate Katrina and the Waves - Walking On Sunshine [abs(236.67-239.03)=2.36] = 109.792
echonest_tempo: candidate Katrina and the Waves - Walking On Sunshine [abs(29.95-239.03)=209.08] = 110.329
echonest_tempo: candidate Katrina and the Waves - Walking On Sunshine [abs(169.32-239.03)=69.71] = 109.483
echonest_tempo: candidate Katrina and the Waves - Walking On Sunshine [abs(220.97-239.03)=18.06] = 109.907
echonest_tempo: candidate Katrina and the Waves - Walking On Sunshine [abs(237.96-239.03)=1.07] = 109.867
echonest_tempo: candidate Katrina and the Waves - Walking On Sunshine [abs(235.36-239.03)=3.67] = 109.94
echonest_tempo: candidate Katrina and the Waves - Walking On Sunshine [abs(201.76-239.03)=37.27] = 116.628
fetched tempo: Katrina and the Waves - Walking on Sunshine
[ ... ]
109.867 BPM
[ ... ]
```