deezer-lookup 1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: de809526e8bc3e88c6541aa75cb83bb563658007
4
+ data.tar.gz: 03c9a04132a778097a07c8fa2452b89a491dfa3b
5
+ SHA512:
6
+ metadata.gz: 9c4ec78d49f18ba78ff71102af1655ae7272c3b953a0875ffd0f6d2f5481b3b9f6389ea0de8e38d99d74f477bf968f0e9ab40188f9934edfc340912c83090b44
7
+ data.tar.gz: c3b1de9ba01b532348cdabf666719b2e250538c1a877d30c91183ba5daaf7c2f6f513d8cce3c6f24ed8e7d0a24760edb76084a43aaa56058747fdc5a27a0e90d
@@ -0,0 +1,2 @@
1
+ gem 'damerau-levenshtein'
2
+ gem 'json'
@@ -0,0 +1,11 @@
1
+ GEM
2
+ specs:
3
+ damerau-levenshtein (1.0.3)
4
+ json (1.8.1)
5
+
6
+ PLATFORMS
7
+ ruby
8
+
9
+ DEPENDENCIES
10
+ damerau-levenshtein
11
+ json
@@ -0,0 +1,5 @@
1
+ require_relative 'deezer-lookup'
2
+ require 'pp'
3
+ Deezer.access_token 'nypmrN5hry5408738ae132endQ8sQed5408738ae1369wgcn7g'
4
+ Deezer.levenshtein_thresholds = nil
5
+ pp Deezer.lookup( 'riptide', 'vance joy' ).size
@@ -0,0 +1,42 @@
1
+ require 'damerau-levenshtein'
2
+ require 'open-uri'
3
+ require 'json'
4
+
5
+ LEVENSHTEIN_THRESHOLDS = { :song => 0, :artist => 0 } # by default don't accept variations
6
+
7
+ module Deezer
8
+
9
+ def self.access_token(token, levenshtein_thresholds = LEVENSHTEIN_THRESHOLDS)
10
+ @access_token, @levenshtein_thresholds = token, levenshtein_thresholds
11
+ end
12
+
13
+ def self.levenshtein_thresholds=(thresholds)
14
+ @levenshtein_thresholds = thresholds
15
+ end
16
+
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()
21
+
22
+ results, input_song_title, input_artist_name, filtered_results = JSON.parse(raw_json)['data'], query[0].downcase, query[1].downcase, []
23
+
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
+ results.each do |r|
31
+ 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)
34
+ end
35
+ end
36
+ filtered_results
37
+ else
38
+ results
39
+ end
40
+ end
41
+
42
+ end
@@ -0,0 +1,11 @@
1
+ require 'deezer-lookup'
2
+ require 'pp'
3
+
4
+ Deezer.access_token 'xxx' # get your token from developers.deezer.com, api explorer
5
+
6
+ Deezer.levenshtein_thresholds = { :song => 3, :artist => 5 } # overriding the default thresholds
7
+ pp Deezer.lookup( 'song 2', 'blur' )
8
+
9
+ Deezer.levenshtein_thresholds = nil # this would disable levenshtein distance comp.
10
+ pp Deezer.lookup( 'riptide', 'vance joy' )
11
+
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: deezer-lookup
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.1'
5
+ platform: ruby
6
+ authors:
7
+ - Matias Insaurralde
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: damerau-levenshtein
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ description: Deezer is a web-based music streaming service. This gem allows you to
28
+ lookup song/artist info using Deezer API (it uses levenshtein for better matching,
29
+ the thresholds are configurable).
30
+ email: matias@insaurral.de
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - lib/Gemfile
36
+ - lib/Gemfile.lock
37
+ - lib/_sample.rb
38
+ - lib/deezer-lookup.rb
39
+ - sample.rb
40
+ homepage: https://github.com/matiasinsaurralde/deezer-lookup
41
+ licenses:
42
+ - MIT
43
+ metadata: {}
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubyforge_project:
60
+ rubygems_version: 2.2.2
61
+ signing_key:
62
+ specification_version: 4
63
+ summary: This gem allows you to lookup song/artist info using Deezer API (it uses
64
+ levenshtein for better matching, the thresholds are configurable).
65
+ test_files: []