daapclient 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +5 -0
- data/EXAMPLES +15 -0
- data/lib/net/daap.rb +17 -3
- data/lib/net/daap/album.rb +5 -0
- data/lib/net/daap/artist.rb +5 -0
- data/lib/net/daap/daap_version.rb +1 -1
- data/lib/net/daap/song.rb +5 -0
- data/test/mock_server.rb +14 -2
- data/test/ts_daap.rb +1 -0
- metadata +15 -4
data/CHANGELOG
CHANGED
data/EXAMPLES
CHANGED
@@ -21,6 +21,21 @@
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
+
== Simple example using a password
|
25
|
+
require 'net/daap'
|
26
|
+
require 'fileutils'
|
27
|
+
|
28
|
+
daap = Net::DAAP::Client.new('localhost', :password => 'something')
|
29
|
+
|
30
|
+
daap.connect do |dsn|
|
31
|
+
daap.databases.each do |db|
|
32
|
+
puts "list all artists"
|
33
|
+
db.artists.each do |artist|
|
34
|
+
puts "#{artist.name}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
24
39
|
== Longer example
|
25
40
|
require 'rubygems'
|
26
41
|
require 'net/daap'
|
data/lib/net/daap.rb
CHANGED
@@ -54,9 +54,11 @@ module Net
|
|
54
54
|
attr_reader :dmap
|
55
55
|
|
56
56
|
# Create a new Client and pass in the host where the client will connect.
|
57
|
-
def initialize(server_host)
|
57
|
+
def initialize(server_host, parameters = {})
|
58
|
+
params = { :port => 3689, :password => nil }.merge(parameters)
|
58
59
|
@server_host = server_host
|
59
|
-
@server_port =
|
60
|
+
@server_port = params[:port]
|
61
|
+
@password = params[:password]
|
60
62
|
@validator = nil
|
61
63
|
@log = Logger.new(nil)
|
62
64
|
@session_id = nil
|
@@ -118,7 +120,19 @@ module Net
|
|
118
120
|
#end
|
119
121
|
@log.debug("Fetching url: #{url}")
|
120
122
|
|
121
|
-
|
123
|
+
req = Net::HTTP::Get.new(url, request_headers(url))
|
124
|
+
req.basic_auth('iTunes_4.6', @password) if ! @password.nil?
|
125
|
+
res = @http_client.request(req) do |response|
|
126
|
+
response.read_body &block
|
127
|
+
end
|
128
|
+
|
129
|
+
case res
|
130
|
+
when Net::HTTPSuccess
|
131
|
+
else
|
132
|
+
@log.error("This DAAP Server requires a password")
|
133
|
+
res.error!
|
134
|
+
end
|
135
|
+
|
122
136
|
@log.debug("Done Fetching url: #{url}")
|
123
137
|
|
124
138
|
content_type = res.header['content-type']
|
data/lib/net/daap/album.rb
CHANGED
@@ -2,6 +2,7 @@ module Net
|
|
2
2
|
module DAAP
|
3
3
|
# This class contains album information returned from the DAAP server.
|
4
4
|
class Album
|
5
|
+
include Comparable
|
5
6
|
attr_reader :name, :artist, :songs
|
6
7
|
|
7
8
|
alias :to_s :name
|
@@ -11,6 +12,10 @@ module Net
|
|
11
12
|
@artist = args[:artist]
|
12
13
|
@songs = []
|
13
14
|
end
|
15
|
+
|
16
|
+
def <=>(other)
|
17
|
+
name <=> other.name
|
18
|
+
end
|
14
19
|
end
|
15
20
|
end
|
16
21
|
end
|
data/lib/net/daap/artist.rb
CHANGED
@@ -2,6 +2,7 @@ module Net
|
|
2
2
|
module DAAP
|
3
3
|
# This class contains artist information returned from the DAAP server.
|
4
4
|
class Artist
|
5
|
+
include Comparable
|
5
6
|
attr_reader :name, :albums, :songs
|
6
7
|
|
7
8
|
alias :to_s :name
|
@@ -11,6 +12,10 @@ module Net
|
|
11
12
|
@albums = []
|
12
13
|
@songs = []
|
13
14
|
end
|
15
|
+
|
16
|
+
def <=>(other)
|
17
|
+
name <=> other.name
|
18
|
+
end
|
14
19
|
end
|
15
20
|
end
|
16
21
|
end
|
data/lib/net/daap/song.rb
CHANGED
@@ -2,6 +2,7 @@ module Net
|
|
2
2
|
module DAAP
|
3
3
|
# This class contains song information returned from the DAAP server.
|
4
4
|
class Song
|
5
|
+
include Comparable
|
5
6
|
attr_reader :size, :album, :name, :artist, :format, :persistentid, :id
|
6
7
|
|
7
8
|
alias :to_s :name
|
@@ -24,6 +25,10 @@ module Net
|
|
24
25
|
filename = "#{@id}.#{@format}"
|
25
26
|
@daap.get_song("databases/#{@db.id}/items/#{filename}", &block)
|
26
27
|
end
|
28
|
+
|
29
|
+
def <=>(other)
|
30
|
+
name <=> other.name
|
31
|
+
end
|
27
32
|
end
|
28
33
|
end
|
29
34
|
end
|
data/test/mock_server.rb
CHANGED
@@ -14,7 +14,7 @@ File.open("#{FILE_DIR}/song_data.txt", 'r') { |f| FILE_DATA = f.read }
|
|
14
14
|
SERVER = 'localhost'
|
15
15
|
|
16
16
|
module Net
|
17
|
-
class
|
17
|
+
class HTTPSuccess
|
18
18
|
attr_reader :header, :body
|
19
19
|
|
20
20
|
def initialize(args)
|
@@ -35,6 +35,10 @@ module Net
|
|
35
35
|
Net::HTTP.new
|
36
36
|
end
|
37
37
|
|
38
|
+
def request(req, &block)
|
39
|
+
get(req.url, block)
|
40
|
+
end
|
41
|
+
|
38
42
|
def get(*args, &block)
|
39
43
|
md5 = Digest::MD5.new(args[0])
|
40
44
|
contents = nil
|
@@ -47,10 +51,18 @@ module Net
|
|
47
51
|
File::open(dir + md5.to_s + ".txt" , "r") do |file|
|
48
52
|
contents = file.read
|
49
53
|
end
|
50
|
-
|
54
|
+
HTTPSuccess.new(:body => contents, :header => {
|
51
55
|
'content-type' => 'dmap',
|
52
56
|
'daap-server' => 'mock'
|
53
57
|
})
|
54
58
|
end
|
55
59
|
end
|
60
|
+
|
61
|
+
class HTTP::Get
|
62
|
+
attr_reader :url
|
63
|
+
|
64
|
+
def initialize(url, headers = {})
|
65
|
+
@url = url
|
66
|
+
end
|
67
|
+
end
|
56
68
|
end
|
data/test/ts_daap.rb
CHANGED
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.
|
2
|
+
rubygems_version: 0.9.0
|
3
3
|
specification_version: 1
|
4
4
|
name: daapclient
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.2.
|
7
|
-
date: 2006-
|
6
|
+
version: 0.2.1
|
7
|
+
date: 2006-07-09 00:00:00 -07:00
|
8
8
|
summary: Net::DAAP::Client is an iTunes share client.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -26,6 +26,7 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
|
|
26
26
|
platform: ruby
|
27
27
|
signing_key:
|
28
28
|
cert_chain:
|
29
|
+
post_install_message:
|
29
30
|
authors:
|
30
31
|
- Aaron Patterson
|
31
32
|
files:
|
@@ -84,4 +85,14 @@ extra_rdoc_files:
|
|
84
85
|
executables: []
|
85
86
|
extensions: []
|
86
87
|
requirements: []
|
87
|
-
dependencies:
|
88
|
+
dependencies:
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: digest-m4p
|
91
|
+
version_requirement:
|
92
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
93
|
+
requirements:
|
94
|
+
-
|
95
|
+
- ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: 0.0.1
|
98
|
+
version:
|