deezer-lookup 1.1 → 1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/_sample.rb +2 -1
  3. data/lib/deezer-lookup.rb +21 -14
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: de809526e8bc3e88c6541aa75cb83bb563658007
4
- data.tar.gz: 03c9a04132a778097a07c8fa2452b89a491dfa3b
3
+ metadata.gz: 520fa1d126f05911efd703c2af2b148bc28a2308
4
+ data.tar.gz: 43dae851208c67b4527a7e3802e665e170f398c8
5
5
  SHA512:
6
- metadata.gz: 9c4ec78d49f18ba78ff71102af1655ae7272c3b953a0875ffd0f6d2f5481b3b9f6389ea0de8e38d99d74f477bf968f0e9ab40188f9934edfc340912c83090b44
7
- data.tar.gz: c3b1de9ba01b532348cdabf666719b2e250538c1a877d30c91183ba5daaf7c2f6f513d8cce3c6f24ed8e7d0a24760edb76084a43aaa56058747fdc5a27a0e90d
6
+ metadata.gz: 43f942930f977d5bdb36f39b9c6ebb94a4575b367db91ca6425ee5bd16f75e3bc9c67ca3bf9a96e7636822a503d99e92d973be26b6bffa7484d976b15be2bd73
7
+ data.tar.gz: 6099bfd8a765886ac31db3d34b09d2962f6072ae7195c8a8545d5de3ed7b0daa7d5bbfb5dbb330e493b5120367d5a881aeaa3507c9e7eb12b5872f5186f60893
@@ -2,4 +2,5 @@ require_relative 'deezer-lookup'
2
2
  require 'pp'
3
3
  Deezer.access_token 'nypmrN5hry5408738ae132endQ8sQed5408738ae1369wgcn7g'
4
4
  Deezer.levenshtein_thresholds = nil
5
- pp Deezer.lookup( 'riptide', 'vance joy' ).size
5
+ pp Deezer.lookup( 14495578)
6
+
@@ -15,27 +15,34 @@ module Deezer
15
15
  end
16
16
 
17
17
  def self.lookup(*query)
18
- base_url = "http://api.deezer.com/search?access_token=#{@access_token}&q="
19
- base_url += URI.escape( query.join(' ').downcase )
20
- raw_json = open(base_url).read()
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
- results, input_song_title, input_artist_name, filtered_results = JSON.parse(raw_json)['data'], query[0].downcase, query[1].downcase, []
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
- if r['levenshtein'][0] <= @levenshtein_thresholds[:song] and r['levenshtein'][1] <= @levenshtein_thresholds[:artist]
33
- filtered_results.push(r)
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
- results
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.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-09-19 00:00:00.000000000 Z
11
+ date: 2014-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: damerau-levenshtein