PlaydARR 0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 JP Hastings-Spital
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,3 @@
1
+ = PlaydARR!
2
+
3
+ AVAST YE! Playdar - the music resolver http://playdar.org - now accessible from Ruby!
@@ -0,0 +1,54 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "PlaydARR"
8
+ gem.version = "0.1"
9
+ gem.summary = %Q{Query Playdar from Ruby}
10
+ gem.description = %Q{A Library for querying Playdar from Ruby}
11
+ gem.email = "jphastings@gmail.com"
12
+ gem.homepage = "http://github.com/jphastings/PlaydARR"
13
+ gem.authors = ["JP Hastings-Spital"]
14
+ gem.add_development_dependency "Shoulda"
15
+ gem.add_dependency "httparty"
16
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
+ end
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
20
+ end
21
+
22
+ require 'rake/testtask'
23
+ Rake::TestTask.new(:test) do |test|
24
+ test.libs << 'lib' << 'test'
25
+ test.pattern = 'test/**/test_*.rb'
26
+ test.verbose = true
27
+ end
28
+
29
+ begin
30
+ require 'rcov/rcovtask'
31
+ Rcov::RcovTask.new do |test|
32
+ test.libs << 'test'
33
+ test.pattern = 'test/**/test_*.rb'
34
+ test.verbose = true
35
+ end
36
+ rescue LoadError
37
+ task :rcov do
38
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
39
+ end
40
+ end
41
+
42
+ task :test => :check_dependencies
43
+
44
+ task :default => :test
45
+
46
+ require 'rake/rdoctask'
47
+ Rake::RDocTask.new do |rdoc|
48
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
49
+
50
+ rdoc.rdoc_dir = 'rdoc'
51
+ rdoc.title = "PlaydARR #{version}"
52
+ rdoc.rdoc_files.include('README*')
53
+ rdoc.rdoc_files.include('lib/**/*.rb')
54
+ end
@@ -0,0 +1,96 @@
1
+ require 'rubygems'
2
+ require 'httparty'
3
+
4
+ # Playdar! A music resolver, now accessible from Ruby
5
+ #
6
+ # The basics are here, try this:
7
+ #
8
+ # PlaydARR::Server.search("Air","Sexy Boy").each do |track|
9
+ # p track
10
+ # puts track.resolve_uri
11
+ # end
12
+ module PlaydARR
13
+
14
+ # Class that represents a track, as returned from the Server.
15
+ class Track
16
+ attr_reader :duration, :size, :sid, :url, :bitrate, :mimetype, :source
17
+ attr_reader :artist, :album, :track
18
+ attr_reader :score, :preference, :resolve_uri
19
+ # Expects a Hash in the form delivered by the Playdar server
20
+ #
21
+ # Example:
22
+ # {
23
+ # "duration"=>188,
24
+ # "artist"=>"The Prodigy",
25
+ # "size"=>5199064,
26
+ # "track"=>"Omen",
27
+ # "sid"=>"232c123f-ae1a-43c2-88b7-becddbc9de08",
28
+ # "url"=>"file:///…/1-01 Omen.mp3",
29
+ # "bitrate"=>221,
30
+ # "album"=>"Addicted To Bass",
31
+ # "mimetype"=>"audio/mpeg",
32
+ # "source"=>"Your Playdar Source",
33
+ # "score"=>1.0,
34
+ # "preference"=>100
35
+ # }
36
+ def initialize(track)
37
+ track.each do |key,value|
38
+ eval("@#{key} = \"#{value}\"")
39
+ end
40
+ @resolve_uri = "http://#{Server::Address}:#{Server::Port}/sid/#{@sid}"
41
+ end
42
+
43
+ # A quick indication of what the track is, for inspection
44
+ def inspect
45
+ "#{@artist}: #{@track} (#{@album})"
46
+ end
47
+ end
48
+
49
+ # Used to access the Playdar server
50
+ class Server
51
+ Address = "127.0.0.1"
52
+ Port = 60210
53
+
54
+ include HTTParty
55
+ base_uri "#{Address}:#{Port}/api"
56
+ format :json
57
+ # If you're using the C++ version of Playdar, you should upgrade, but also you'll find you'll need to authenticate
58
+ # Throw any authorized token in here (you can find them on the playdar web interface) and uncomment the other line below
59
+ # @@auth = "1c344d17-7291-4899-b1c7-a1ca43c82346"
60
+
61
+ # Gets the stats of the server. Notably it can be used to find the server version and whether
62
+ # a playdar server is actually running.
63
+ def self.stats
64
+ get('?method=stat')
65
+ end
66
+
67
+ # Search the Playdar database for a particular song
68
+ # Album isn't required, but its suggested!
69
+ def self.search(artist, track, album = "")
70
+ qid = get('',
71
+ :query => {
72
+ :method => "resolve",
73
+ #:auth => @@auth, # Explained above
74
+ :artist => artist,
75
+ :album => album,
76
+ :track => track
77
+ }
78
+ )['qid']
79
+
80
+ res = nil
81
+ 0.upto(6) do
82
+ res = get('',
83
+ :query => {
84
+ :method => "get_results",
85
+ :auth => @@auth,
86
+ :qid => qid
87
+ }
88
+ )
89
+ break if res['query']['solved']
90
+ # This pause will respect the time suggested by playdar when that feature is implemented
91
+ sleep(0.1)
92
+ end
93
+ res['results'].collect{|track| Track.new(track)}
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'PlaydARR'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,14 @@
1
+ require 'helper'
2
+
3
+ class TestPlaydarr < Test::Unit::TestCase
4
+ context "The Playdar Server" do
5
+ # We need a playdar server to be running to test!
6
+ should "be running, and return stats" do
7
+ assert PlaydARR::Server.stats
8
+ end
9
+
10
+ should "return some tracks" do
11
+ assert_equal PlaydARR::Server.search("some artist","some track").is_a? Array
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ require 'helper'
2
+
3
+ class TestPlaydarr < Test::Unit::TestCase
4
+ context "The Playdar Server" do
5
+ # We need a playdar server to be running to test!
6
+ should "be running, and return stats" do
7
+ assert PlaydARR::Server.stats
8
+ end
9
+
10
+ should "return some tracks" do
11
+ assert_equal PlaydARR::Server.search("some artist","some track").is_a? Array
12
+ end
13
+ end
14
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: PlaydARR
3
+ version: !ruby/object:Gem::Version
4
+ version: "0.1"
5
+ platform: ruby
6
+ authors:
7
+ - JP Hastings-Spital
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-11-05 00:00:00 +00:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: Shoulda
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: httparty
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ description: A Library for querying Playdar from Ruby
36
+ email: jphastings@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.rdoc
44
+ files:
45
+ - .document
46
+ - .gitignore
47
+ - LICENSE
48
+ - README.rdoc
49
+ - Rakefile
50
+ - lib/PlaydARR.rb
51
+ - test/helper.rb
52
+ - test/test_PlaydARR.rb
53
+ has_rdoc: true
54
+ homepage: http://github.com/jphastings/PlaydARR
55
+ licenses: []
56
+
57
+ post_install_message:
58
+ rdoc_options:
59
+ - --charset=UTF-8
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "0"
67
+ version:
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: "0"
73
+ version:
74
+ requirements: []
75
+
76
+ rubyforge_project:
77
+ rubygems_version: 1.3.5
78
+ signing_key:
79
+ specification_version: 3
80
+ summary: Query Playdar from Ruby
81
+ test_files:
82
+ - test/helper.rb
83
+ - test/test_playdarr.rb