rbrainz 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,5 +1,10 @@
1
1
  = Changelog
2
2
 
3
+ == 0.4.0 (2007-12-16)
4
+ * NEW: Complete tagging (folksonomy) support.
5
+ * NEW: Support release event format.
6
+ * NEW: Support for HTTP proxies
7
+
3
8
  == 0.3.0 (2007-08-11)
4
9
  * BUG: Relation end date was not set correctly in MBXML.
5
10
  * NEW: Allow release type constants to be passed to include and filter objects.
@@ -7,7 +12,6 @@
7
12
  * NEW: Methods Release#earliest_release_event and Release#earliest_release_date
8
13
  * NEW: Entity#get_relations allows string with or without namespace for
9
14
  target_type, relation_type and required_attributes
10
- * BUG: Corrected constant TYPE_PSEUDO_RELEASE
11
15
 
12
16
  == 0.2.1 (2007-07-24)
13
17
  * Erroneous date strings in the XML are ignored. No error is raised and nil
@@ -49,4 +53,4 @@
49
53
  == 0.1.0 (2007-05-23)
50
54
  * Initial release
51
55
 
52
- $Id: CHANGES 167 2007-08-11 09:18:30Z phw $
56
+ $Id: CHANGES 192 2007-12-16 00:30:15Z phw $
data/doc/README.rdoc CHANGED
@@ -71,6 +71,12 @@ should make the usage clear:
71
71
  Releases : #{artist.releases.map{|r| r.title}.uniq.join("\r\n ")}
72
72
  EOF
73
73
 
74
+ == Unicode support
75
+ The MusicBrainz webservice returns all data in UTF-8 encoding. RBrainz does
76
+ not change or modify the encoding. So if you are using RBrainz you should be
77
+ aware that all strings returned by RBrainz are UTF-8 encoded as well.
78
+ Furthermore all strings you pass to RBrainz need to be UTF-8 encoded as well.
79
+
74
80
  == The MusicBrainz webservice
75
81
  For more information about the MusicBrainz webservice visit the
76
82
  following resources:
@@ -94,4 +100,4 @@ RBrainz is Copyright (c) 2007 Philipp Wolfer and Nigel Graham.
94
100
  It is free softare distributed under a BSD style license. See
95
101
  LICENSE[link:files/LICENSE.html] for details.
96
102
 
97
- $Id: README.rdoc 145 2007-07-19 13:11:44Z phw $
103
+ $Id: README.rdoc 191 2007-12-04 13:30:26Z phw $
@@ -3,7 +3,7 @@
3
3
  # Example script which queries the database for an
4
4
  # release and displays the release's data.
5
5
  #
6
- # $Id: getrelease.rb 160 2007-07-27 13:18:04Z phw $
6
+ # $Id: getrelease.rb 190 2007-12-04 12:51:17Z phw $
7
7
 
8
8
  # Just make sure we can run this example from the command
9
9
  # line even if RBrainz is not yet installed properly.
data/examples/getuser.rb CHANGED
@@ -1,9 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
  #
3
- # Example script which queries the database for a
4
- # User
3
+ # Example script which queries the database for a user.
5
4
  #
6
- # $Id: getuser.rb 145 2007-07-19 13:11:44Z phw $
5
+ # $Id: getuser.rb 183 2007-10-16 22:13:33Z phw $
7
6
 
8
7
  # Just make sure we can run this example from the command
9
8
  # line even if RBrainz is not yet installed properly.
@@ -3,7 +3,7 @@
3
3
  # Example script which searches the database for
4
4
  # releases and displays the release data.
5
5
  #
6
- # $Id: searchreleases.rb 160 2007-07-27 13:18:04Z phw $
6
+ # $Id: searchreleases.rb 183 2007-10-16 22:13:33Z phw $
7
7
 
8
8
  # Just make sure we can run this example from the command
9
9
  # line even if RBrainz is not yet installed properly.
@@ -16,7 +16,7 @@ include MusicBrainz
16
16
  # Define the search parameters: Search for releases with the
17
17
  # title "Paradise Lost" and return a maximum of 10 releases.
18
18
  release_filter = Webservice::ReleaseFilter.new(
19
- :title => 'Draconian Times',
19
+ :artistid => '10bf95b6-30e3-44f1-817f-45762cdc0de0',
20
20
  :limit => 10
21
21
  )
22
22
 
@@ -31,5 +31,6 @@ releases = query.get_releases(release_filter)
31
31
  # Display the fetched release titles and the score, which
32
32
  # indicates how good the release matches the search parameters.
33
33
  releases.each do |entry|
34
- print "%s (%i%%)\r\n" % [entry.entity.title, entry.score]
34
+ print "%s: %s (%i%%)\r\n" % [entry.entity.earliest_release_date,
35
+ entry.entity.title, entry.score]
35
36
  end
data/examples/tag.rb ADDED
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Example script showing the use of folksonomy tagging with RBrainz.
4
+ # It asks the user for his username and password and a MBID and queries the
5
+ # MusicBrainz server for the tags, the user has applied to the entitity with
6
+ # the given MBID. Afterwards the user can submit new tags.
7
+ #
8
+ # $Id: getuser.rb 145 2007-07-19 13:11:44Z phw $
9
+
10
+ # Just make sure we can run this example from the command
11
+ # line even if RBrainz is not yet installed properly.
12
+ $: << 'lib/' << '../lib/'
13
+
14
+ # Load RBrainz and include the MusicBrainz namespace.
15
+ require 'rbrainz'
16
+ include MusicBrainz
17
+
18
+ # Get the username and password
19
+ print 'Username: ' unless ARGV[0]
20
+ username = ARGV[0] ? ARGV[0] : STDIN.gets.strip
21
+ print 'Password: ' unless ARGV[1]
22
+ password = ARGV[1] ? ARGV[1] : STDIN.gets.strip
23
+
24
+ # Ask for a MBID to tag.
25
+ print 'Enter a MBID: '
26
+ mbid = Model::MBID.new(STDIN.gets.strip)
27
+
28
+ ws = Webservice::Webservice.new(:username=>username, :password=>password)
29
+
30
+ # Create a new Query object which will provide
31
+ # us an interface to the MusicBrainz web service.
32
+ query = Webservice::Query.new(ws, :client_id => 'RBrainz test ' + RBRAINZ_VERSION)
33
+
34
+ # Read and print the current tags for the given MBID
35
+ tags = query.get_user_tags(mbid)
36
+ print 'Current tags: '
37
+ puts tags.to_a.join(', ')
38
+
39
+ # Ask the user for new tags and submit them
40
+ print 'Enter new tags: '
41
+ new_tags = STDIN.gets.strip
42
+ query.submit_user_tags(mbid, new_tags)
@@ -1,4 +1,4 @@
1
- # $Id: net_http_digest.rb 136 2007-07-16 15:45:32Z phw $
1
+ # $Id: net_http_digest.rb 182 2007-10-16 14:46:17Z nigel_graham $
2
2
  #
3
3
  # Author:: Nigel Graham (mailto:nigel_graham@rubyforge.org)
4
4
  # Copyright:: Copyright (c) 2007, Nigel Graham, Philipp Wolfer
@@ -14,11 +14,47 @@ module Net # :nodoc:
14
14
  module HTTPHeader # :nodoc:
15
15
  @@nonce_count = -1
16
16
  CNONCE = Digest::MD5.new.update("%x" % (Time.now.to_i + rand(65535))).hexdigest
17
+
18
+ def select_auth(user,password,response)
19
+ response['www-authenticate'] =~ /^(\w+) (.*)/
20
+ auth_type = $1
21
+ case auth_type
22
+ when 'Digest'
23
+ digest_auth(user,password,response)
24
+ return true
25
+ when 'Basic'
26
+ basic_auth(user,password)
27
+ return true
28
+ end
29
+ return false
30
+ end
31
+
32
+ def proxy_select_auth(user, password, response)
33
+ response['proxy-authenticate'] =~ /^(\w+) (.*)/
34
+ auth_type = $1
35
+ case auth_type
36
+ when 'Digest'
37
+ proxy_digest_auth(user,password,response)
38
+ return true
39
+ when 'Basic'
40
+ proxy_basic_auth(user,password)
41
+ return true
42
+ end
43
+ return false
44
+ end
45
+
17
46
  def digest_auth(user, password, response)
47
+ @header['Authorization'] = digest_encode(response['www-authenticate'], user, password)
48
+ end
49
+
50
+ def proxy_digest_auth(user, password, response)
51
+ @header['Proxy-Authorization'] = digest_encode(response['proxy-authenticate'], user, password)
52
+ end
53
+
54
+ def digest_encode(authenticate, user, password)
18
55
  @@nonce_count += 1
19
-
20
- response['www-authenticate'] =~ /^(\w+) (.*)/
21
-
56
+ authenticate =~ /^(\w+) (.*)/
57
+
22
58
  params = {}
23
59
  $2.gsub(/(\w+)="(.*?)"/) { params[$1] = $2 }
24
60
 
@@ -46,7 +82,8 @@ module Net # :nodoc:
46
82
  header << "nc=#{'%08x' % @@nonce_count}" if params['qop']
47
83
  header << "cnonce=\"#{CNONCE}\"" if params['qop']
48
84
  header << "response=\"#{Digest::MD5.new.update(request_digest).hexdigest}\""
49
- @header['Authorization'] = header
85
+
86
+ return header
50
87
  end
51
88
  end
52
89
  end
@@ -1,4 +1,4 @@
1
- # $Id: collection.rb 130 2007-07-12 18:55:24Z nigel_graham $
1
+ # $Id: collection.rb 172 2007-08-24 11:19:19Z phw $
2
2
  #
3
3
  # Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
4
4
  # Copyright:: Copyright (c) 2007, Nigel Graham, Philipp Wolfer
@@ -42,9 +42,10 @@ module MusicBrainz
42
42
  end
43
43
  end
44
44
 
45
- # Add a new element to this collection.
45
+ # Add a new element to this collection. Returns self.
46
46
  def <<(entry)
47
47
  @entries << entry
48
+ self # return self to allow something like collection << a << b
48
49
  end
49
50
 
50
51
  # Delete an element from the collection.
@@ -93,6 +94,7 @@ module MusicBrainz
93
94
  end
94
95
  alias to_ary to_a
95
96
 
97
+ # Duplicate this collection.
96
98
  def dup
97
99
  Collection.new(self.count, self.offset, @entries)
98
100
  end
@@ -0,0 +1,96 @@
1
+
2
+ # Represents a duration in milliseconds.
3
+ class Duration < Numeric
4
+
5
+ def initialize(milliseconds=0)
6
+ @ms = milliseconds.to_i
7
+ end
8
+
9
+ def days
10
+ to_i / 86400000
11
+ end
12
+
13
+ def hours
14
+ to_i / 3600000 % 24
15
+ end
16
+
17
+ def minutes
18
+ to_i / 60000 % 60
19
+ end
20
+
21
+ def seconds
22
+ to_i / 1000 % 60
23
+ end
24
+
25
+ def milliseconds
26
+ to_i % 1000
27
+ end
28
+
29
+ def to_i
30
+ @ms
31
+ end
32
+
33
+ def to_f
34
+ @ms.to_f
35
+ end
36
+
37
+ def coerce(numeric)
38
+ if numeric.is_a?(Integer)
39
+ [numeric, to_i]
40
+ else
41
+ [Float.induced_from(numeric), to_f]
42
+ end
43
+ end
44
+
45
+ # def method_missing(m, *args)
46
+ # if ['%'.to_sym, '+'.to_sym, '-'.to_sym, '*'.to_sym, '/'.to_sym].include?(m)
47
+ # self.class.new(@ms.send(m, *args))
48
+ # end
49
+ # end
50
+
51
+ def <=> other
52
+ to_i <=> other
53
+ end
54
+
55
+ def % other
56
+ Duration.new(to_i % other)
57
+ end
58
+
59
+ def + other
60
+ Duration.new(to_i + other)
61
+ end
62
+
63
+ def - other
64
+ Duration.new(to_i - other)
65
+ end
66
+
67
+ def * other
68
+ Duration.new(to_i * other)
69
+ end
70
+
71
+ def / other
72
+ Duration.new(to_i / other)
73
+ end
74
+
75
+ def ** other
76
+ Duration.new(to_i ** other)
77
+ end
78
+
79
+ end
80
+
81
+ require 'delegate'
82
+
83
+ #class Duration < DelegateClass(Fixnum)
84
+ #
85
+ # def x_method_missing(m, *args, &block)
86
+ # if block_given?
87
+ # result = super m, *args
88
+ # else
89
+ # result = super m, *args, &block
90
+ # end
91
+ # result.is_a?(Integer) ? Duration.new(result) : result
92
+ # end
93
+ #
94
+ #end
95
+
96
+
@@ -1,4 +1,4 @@
1
- # $Id: relation.rb 151 2007-07-24 08:36:27Z phw $
1
+ # $Id: relation.rb 173 2007-08-24 15:11:11Z phw $
2
2
  #
3
3
  # Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
4
4
  # Copyright:: Copyright (c) 2007, Nigel Graham, Philipp Wolfer
@@ -55,6 +55,9 @@ module MusicBrainz
55
55
  attr_accessor :direction
56
56
 
57
57
  # The relation's target object.
58
+ #
59
+ # The target can either be an object of the type Model::Entity
60
+ # or a URL if the type of the relation is TO_URL.
58
61
  attr_reader :target
59
62
 
60
63
  # The list of attributes describing this relation.
@@ -87,8 +90,8 @@ module MusicBrainz
87
90
 
88
91
  # Set the target of this relation.
89
92
  #
90
- # The _target_ can either be a object of the type Model::Entity
91
- # or a URL.
93
+ # The _target_ can either be an object of the type Model::Entity
94
+ # or a URL if the type of the relation is TO_URL.
92
95
  def target=(target)
93
96
  if target.is_a? Entity
94
97
  @target = target
@@ -1,4 +1,4 @@
1
- # $Id: release.rb 167 2007-08-11 09:18:30Z phw $
1
+ # $Id: release.rb 190 2007-12-04 12:51:17Z phw $
2
2
  #
3
3
  # Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
4
4
  # Copyright:: Copyright (c) 2007, Nigel Graham, Philipp Wolfer
@@ -73,7 +73,7 @@ module MusicBrainz
73
73
  TYPE_BOOTLEG = NS_MMD_1 + 'Bootleg'
74
74
  # A pseudo-release is a duplicate release for translation/transliteration
75
75
  # purposes.
76
- TYPE_PSEUDO_RELEASE = NS_MMD_1 + 'Pseudo-Release'
76
+ TYPE_PSEUDO_RELEASE = NS_MMD_1 + 'PseudoRelease'
77
77
 
78
78
  # See Entity::ENTITY_TYPE.
79
79
  ENTITY_TYPE = :release # :nodoc:
@@ -161,8 +161,8 @@ module MusicBrainz
161
161
  # Returns the earliest release date as an IncompleteDate.
162
162
  #
163
163
  # This favours complete dates. For example, '2006-09' is
164
- # returned if there is '2000', too. If there is no release
165
- # event associated with this release, +nil+ is returned.
164
+ # returned if there is '2000', too. If there is no release
165
+ # event associated with this release, +nil+ is returned.
166
166
  #
167
167
  # See:: earliest_release_date
168
168
  def earliest_release_event
@@ -176,7 +176,7 @@ module MusicBrainz
176
176
  return earliest_event
177
177
  end
178
178
 
179
- # Returns the earliest release event or +nil+.
179
+ # Returns the date of the earliest release event or +nil+.
180
180
  #
181
181
  # See:: earliest_release_event
182
182
  def earliest_release_date
@@ -190,7 +190,7 @@ module MusicBrainz
190
190
  def to_s
191
191
  title.to_s
192
192
  end
193
-
193
+
194
194
  end
195
195
 
196
196
  end
@@ -1,4 +1,4 @@
1
- # $Id: release_event.rb 151 2007-07-24 08:36:27Z phw $
1
+ # $Id: release_event.rb 189 2007-11-26 00:10:49Z phw $
2
2
  #
3
3
  # Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
4
4
  # Copyright:: Copyright (c) 2007, Nigel Graham, Philipp Wolfer
@@ -18,10 +18,29 @@ module MusicBrainz
18
18
  # 'UK' or 'FR'). The dates are instances of IncompleteDate or strings which
19
19
  # must have the format 'YYYY', 'YYYY-MM' or 'YYYY-MM-DD'.
20
20
  #
21
+ # The format of the release medium is a URI that can be compared to the
22
+ # constants on this class (FORMAT_CD, FORMAT_DVD and others).
23
+ #
21
24
  # See:: http://musicbrainz.org/doc/ReleaseEvent.
22
25
  #
23
26
  class ReleaseEvent
24
27
 
28
+ FORMAT_CD = NS_MMD_1 + 'CD'
29
+ FORMAT_DVD = NS_MMD_1 + 'DVD'
30
+ FORMAT_SACD = NS_MMD_1 + 'SACD'
31
+ FORMAT_DUALDISC = NS_MMD_1 + 'DualDisc'
32
+ FORMAT_LASERDISC = NS_MMD_1 + 'LaserDisc'
33
+ FORMAT_MINIDISC = NS_MMD_1 + 'MiniDisc'
34
+ FORMAT_VINYL = NS_MMD_1 + 'Vinyl'
35
+ FORMAT_CASSETTE = NS_MMD_1 + 'Cassette'
36
+ FORMAT_CARTRIDGE = NS_MMD_1 + 'Cartridge'
37
+ FORMAT_REEL_TO_REEL = NS_MMD_1 + 'ReelToReel'
38
+ FORMAT_DAT = NS_MMD_1 + 'DAT'
39
+ FORMAT_DIGITAL = NS_MMD_1 + 'Digital'
40
+ FORMAT_WAX_CYLINDER = NS_MMD_1 + 'WaxCylinder'
41
+ FORMAT_PIANO_ROLL = NS_MMD_1 + 'PianoRoll'
42
+ FORMAT_OTHER = NS_MMD_1 + 'Other'
43
+
25
44
  # The country in which an album was released.
26
45
  # A string containing a ISO 3166 country code like
27
46
  # 'GB', 'US' or 'DE'.
@@ -42,6 +61,9 @@ module MusicBrainz
42
61
  # The release date. An instance of IncompleteDate.
43
62
  attr_reader :date
44
63
 
64
+ # The media format of the release (e.g. CD or Vinyl).
65
+ attr_accessor :format
66
+
45
67
  def initialize(country=nil, date=nil)
46
68
  self.country = country
47
69
  self.date = date
@@ -1,4 +1,4 @@
1
- # $Id: scored_collection.rb 136 2007-07-16 15:45:32Z phw $
1
+ # $Id: scored_collection.rb 172 2007-08-24 11:19:19Z phw $
2
2
  #
3
3
  # Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
4
4
  # Copyright:: Copyright (c) 2007, Nigel Graham, Philipp Wolfer
@@ -55,7 +55,7 @@ module MusicBrainz
55
55
  return map {|entry| entry.entity}
56
56
  end
57
57
 
58
- # Add a new entry to the collection.
58
+ # Add a new entry to the collection. . Returns self.
59
59
  #
60
60
  # You may either add a ScoredCollection::Entry, just an Model::Entity
61
61
  # or an object responding to +first+ and +last+ where +first+ must
@@ -68,6 +68,9 @@ module MusicBrainz
68
68
  # collection << Model::ScoredCollection::Entry.new(artist, 100)
69
69
  # collection << [artist, 100]
70
70
  # collection << artist
71
+ #
72
+ # # Add several entities in one line
73
+ # collection << artist_one << artist_two
71
74
  def <<(entry)
72
75
  super wrap(entry)
73
76
  end
@@ -80,6 +83,11 @@ module MusicBrainz
80
83
  def []=(index, entry)
81
84
  super wrap(entry)
82
85
  end
86
+
87
+ # Convert this ScoredCollection into a Collection without the scores.
88
+ def to_collection
89
+ Collection.new(count, offset, entities)
90
+ end
83
91
 
84
92
  private #-----------------------------------------------------------------
85
93