deezer-lookup 1.1 → 1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/_sample.rb +2 -1
- data/lib/deezer-lookup.rb +21 -14
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 520fa1d126f05911efd703c2af2b148bc28a2308
|
4
|
+
data.tar.gz: 43dae851208c67b4527a7e3802e665e170f398c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 43f942930f977d5bdb36f39b9c6ebb94a4575b367db91ca6425ee5bd16f75e3bc9c67ca3bf9a96e7636822a503d99e92d973be26b6bffa7484d976b15be2bd73
|
7
|
+
data.tar.gz: 6099bfd8a765886ac31db3d34b09d2962f6072ae7195c8a8545d5de3ed7b0daa7d5bbfb5dbb330e493b5120367d5a881aeaa3507c9e7eb12b5872f5186f60893
|
data/lib/_sample.rb
CHANGED
data/lib/deezer-lookup.rb
CHANGED
@@ -15,27 +15,34 @@ module Deezer
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def self.lookup(*query)
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
if query.size == 2
|
19
|
+
base_url = "http://api.deezer.com/search?access_token=#{@access_token}&q="
|
20
|
+
base_url += URI.escape( query.join(' ').downcase )
|
21
|
+
raw_json = open(base_url).read()
|
21
22
|
|
22
|
-
|
23
|
+
results, input_song_title, input_artist_name, filtered_results = JSON.parse(raw_json)['data'], query[0].downcase, query[1].downcase, []
|
23
24
|
|
24
|
-
results.each do |r|
|
25
|
-
song_title, artist_name = r['title'].downcase, r['artist']['name'].downcase
|
26
|
-
r['levenshtein'] = [ DamerauLevenshtein.distance(song_title, input_song_title), DamerauLevenshtein.distance(artist_name, input_artist_name) ]
|
27
|
-
end
|
28
|
-
|
29
|
-
if @levenshtein_thresholds
|
30
25
|
results.each do |r|
|
31
26
|
song_title, artist_name = r['title'].downcase, r['artist']['name'].downcase
|
32
|
-
|
33
|
-
|
27
|
+
r['levenshtein'] = [ DamerauLevenshtein.distance(song_title, input_song_title), DamerauLevenshtein.distance(artist_name, input_artist_name) ]
|
28
|
+
end
|
29
|
+
|
30
|
+
if @levenshtein_thresholds
|
31
|
+
results.each do |r|
|
32
|
+
song_title, artist_name = r['title'].downcase, r['artist']['name'].downcase
|
33
|
+
if r['levenshtein'][0] <= @levenshtein_thresholds[:song] and r['levenshtein'][1] <= @levenshtein_thresholds[:artist]
|
34
|
+
filtered_results.push(r)
|
35
|
+
end
|
34
36
|
end
|
37
|
+
filtered_results
|
38
|
+
else
|
39
|
+
results
|
35
40
|
end
|
36
|
-
filtered_results
|
37
41
|
else
|
38
|
-
|
42
|
+
# single track
|
43
|
+
base_url = "http://api.deezer.com/track/#{query.first}"
|
44
|
+
raw_json = open(base_url).read()
|
45
|
+
return JSON.parse(raw_json)
|
39
46
|
end
|
40
47
|
end
|
41
48
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deezer-lookup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '1.
|
4
|
+
version: '1.2'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matias Insaurralde
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: damerau-levenshtein
|