daapclient 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +10 -0
- data/EXAMPLES +2 -8
- data/NOTES +21 -0
- data/lib/net/daap.rb +12 -1
- data/lib/net/daap/daap_version.rb +1 -3
- data/lib/net/daap/song.rb +19 -0
- data/lib/net/daap/speed_hacks.rb +25 -0
- data/test/mock_server.rb +1 -0
- metadata +3 -2
data/CHANGELOG
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
= Net::DAAP::Client Changelog
|
2
|
+
|
3
|
+
== 0.2.2
|
4
|
+
|
5
|
+
* Added Net::DAAP::Song#save which will automatically save files for you
|
6
|
+
* Added Net::DAAP::Client#connect_db which will automatically yield a database
|
7
|
+
* Added a new example for downloading songs
|
8
|
+
* Added 'net/daap/speed_hacks' for improving Net::HTTP speed
|
9
|
+
* Fixed a couple warnings
|
10
|
+
|
1
11
|
== 0.2.1
|
2
12
|
|
3
13
|
* Added support for DAAP server passwords
|
data/EXAMPLES
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
= Net::DAAP::Client examples
|
2
2
|
|
3
|
-
== Simple example
|
3
|
+
== Simple example, download every song
|
4
4
|
require 'net/daap'
|
5
5
|
require 'fileutils'
|
6
6
|
|
@@ -10,13 +10,7 @@
|
|
10
10
|
daap.databases.each do |db|
|
11
11
|
puts "All songs in the database"
|
12
12
|
db.songs.each do |song|
|
13
|
-
|
14
|
-
directory = "db/#{song.artist.name}/#{song.album.name}"
|
15
|
-
FileUtils::mkdir_p(directory)
|
16
|
-
|
17
|
-
File.open("#{directory}/#{filename}", "w") do |f|
|
18
|
-
song.get { |str| f.write str }
|
19
|
-
end
|
13
|
+
song.save
|
20
14
|
end
|
21
15
|
end
|
22
16
|
end
|
data/NOTES
CHANGED
@@ -1,5 +1,26 @@
|
|
1
1
|
= Net::DAAP::Client Release Notes
|
2
2
|
|
3
|
+
== 0.2.2
|
4
|
+
|
5
|
+
This release of Net::DAAP::Client (the ruby itunes client) has a few important
|
6
|
+
improvements. First, a new method called "connect_db" has been added to
|
7
|
+
Net::DAAP::Client. This method will automatically connect to a server and
|
8
|
+
yield every database to the block. Here's an example:
|
9
|
+
Net::DAAP::Client.new('localhost').connect_db { |db|
|
10
|
+
db.songs.each { |song| puts song }
|
11
|
+
}
|
12
|
+
A 'save' method has been added to Net::DAAP::Song to make it easier to save
|
13
|
+
that song. The save method comes up with a name to save the song for you.
|
14
|
+
For example, to save every song in the database you could do this:
|
15
|
+
Net::DAAP::Client.new('localhost').connect_db { |db|
|
16
|
+
db.songs.each { |song| song.save }
|
17
|
+
}
|
18
|
+
The final new addition is 'net/daap/speed_hacks'. iTunes uses HTTP as its
|
19
|
+
transport, and ruby's net/http is slow when downloading large files. Be
|
20
|
+
very careful when requiring this library as it overrides a method in the
|
21
|
+
built in net/http library. Just require the library and you will get a
|
22
|
+
significant speed increase.
|
23
|
+
|
3
24
|
== 0.2.0
|
4
25
|
|
5
26
|
Net::DAAP::Client has a newer, extended interface. In addition to the song
|
data/lib/net/daap.rb
CHANGED
@@ -9,6 +9,7 @@ require 'net/daap/song'
|
|
9
9
|
require 'net/daap/playlist'
|
10
10
|
require 'net/daap/database'
|
11
11
|
require 'net/daap/daap_version'
|
12
|
+
require 'net/daap/speed_hacks'
|
12
13
|
|
13
14
|
|
14
15
|
module Net
|
@@ -63,6 +64,7 @@ module Net
|
|
63
64
|
@log = Logger.new(nil)
|
64
65
|
@session_id = nil
|
65
66
|
@request_id = nil
|
67
|
+
@connected = nil
|
66
68
|
yield self if block_given?
|
67
69
|
end
|
68
70
|
|
@@ -84,6 +86,15 @@ module Net
|
|
84
86
|
@dsn
|
85
87
|
end
|
86
88
|
|
89
|
+
# Connect to the server and yield each database to the caller, then
|
90
|
+
# automatically disconnect from the server.
|
91
|
+
def connect_db(&block)
|
92
|
+
raise ArgumentError if block.nil?
|
93
|
+
connect
|
94
|
+
databases.each { |db| block.call(db) }
|
95
|
+
disconnect
|
96
|
+
end
|
97
|
+
|
87
98
|
# Returns the databases found on the iTunes server.
|
88
99
|
def databases
|
89
100
|
unless @connected
|
@@ -123,7 +134,7 @@ module Net
|
|
123
134
|
req = Net::HTTP::Get.new(url, request_headers(url))
|
124
135
|
req.basic_auth('iTunes_4.6', @password) if ! @password.nil?
|
125
136
|
res = @http_client.request(req) do |response|
|
126
|
-
response.read_body
|
137
|
+
response.read_body(&block)
|
127
138
|
end
|
128
139
|
|
129
140
|
case res
|
data/lib/net/daap/song.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
1
3
|
module Net
|
2
4
|
module DAAP
|
3
5
|
# This class contains song information returned from the DAAP server.
|
4
6
|
class Song
|
5
7
|
include Comparable
|
6
8
|
attr_reader :size, :album, :name, :artist, :format, :persistentid, :id
|
9
|
+
attr_accessor :path, :file
|
7
10
|
|
8
11
|
alias :to_s :name
|
9
12
|
|
@@ -18,6 +21,10 @@ module Net
|
|
18
21
|
@id = args['dmap.itemid']
|
19
22
|
@daap = args[:daap]
|
20
23
|
@db = args[:db]
|
24
|
+
@path = [@artist.name, @album.name].collect { |name|
|
25
|
+
name.gsub(File::SEPARATOR, '_')
|
26
|
+
}.join(File::SEPARATOR)
|
27
|
+
@file = "#{@name.gsub(File::SEPARATOR, '_')}.#{@format}"
|
21
28
|
end
|
22
29
|
|
23
30
|
# Fetches the song data from the DAAP server and returns it.
|
@@ -26,6 +33,18 @@ module Net
|
|
26
33
|
@daap.get_song("databases/#{@db.id}/items/#{filename}", &block)
|
27
34
|
end
|
28
35
|
|
36
|
+
def save(basedir = nil)
|
37
|
+
path = "#{basedir}#{File::SEPARATOR}#{@path}"
|
38
|
+
FileUtils::mkdir_p(path)
|
39
|
+
filename = "#{path}#{File::SEPARATOR}#{@file}"
|
40
|
+
File.open(filename, "wb") { |file|
|
41
|
+
get do |str|
|
42
|
+
file.write str
|
43
|
+
end
|
44
|
+
}
|
45
|
+
@daap.log.debug("Saved #{filename}") if @daap.log
|
46
|
+
end
|
47
|
+
|
29
48
|
def <=>(other)
|
30
49
|
name <=> other.name
|
31
50
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
if RUBY_VERSION > "1.8.2"
|
2
|
+
class Net::InternetMessageIO #:nodoc:
|
3
|
+
alias :old_rbuf_fill :rbuf_fill
|
4
|
+
def rbuf_fill
|
5
|
+
begin
|
6
|
+
@rbuf << @io.read_nonblock(65536)
|
7
|
+
rescue Errno::EWOULDBLOCK
|
8
|
+
if IO.select([@io], nil, nil, @read_timeout)
|
9
|
+
@rbuf << @io.read_nonblock(65536)
|
10
|
+
else
|
11
|
+
raise Timeout::TimeoutError
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
else
|
17
|
+
class Net::InternetMessageIO #:nodoc:
|
18
|
+
alias :old_rbuf_fill :rbuf_fill
|
19
|
+
def rbuf_fill
|
20
|
+
timeout(@read_timeout) {
|
21
|
+
@rbuf << @socket.sysread(8192)
|
22
|
+
}
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/test/mock_server.rb
CHANGED
metadata
CHANGED
@@ -3,8 +3,8 @@ 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.2
|
7
|
+
date: 2006-08-27 00:00:00 -07:00
|
8
8
|
summary: Net::DAAP::Client is an iTunes share client.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -64,6 +64,7 @@ files:
|
|
64
64
|
- lib/net/daap/dmap.rb
|
65
65
|
- lib/net/daap/playlist.rb
|
66
66
|
- lib/net/daap/song.rb
|
67
|
+
- lib/net/daap/speed_hacks.rb
|
67
68
|
- README
|
68
69
|
- LICENSE
|
69
70
|
- CHANGELOG
|