rbrainz 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +31 -0
- data/LICENSE +1 -1
- data/README +3 -2
- data/Rakefile +40 -22
- data/TODO +6 -23
- data/doc/README.rdoc +50 -21
- data/examples/getartist.rb +6 -4
- data/examples/getuser.rb +30 -0
- data/examples/searchartists.rb +35 -0
- data/lib/rbrainz.rb +12 -7
- data/lib/rbrainz/core_ext.rb +8 -0
- data/lib/rbrainz/core_ext/mbid.rb +30 -0
- data/lib/rbrainz/core_ext/net_http_digest.rb +52 -0
- data/lib/rbrainz/core_ext/range.rb +28 -0
- data/lib/rbrainz/core_ext/range/equality.rb +232 -0
- data/lib/rbrainz/data/countrynames.rb +7 -5
- data/lib/rbrainz/data/languagenames.rb +8 -5
- data/lib/rbrainz/data/releasetypenames.rb +34 -0
- data/lib/rbrainz/data/scriptnames.rb +8 -5
- data/lib/rbrainz/model.rb +27 -35
- data/lib/rbrainz/model/alias.rb +31 -7
- data/lib/rbrainz/model/artist.rb +30 -41
- data/lib/rbrainz/model/collection.rb +102 -0
- data/lib/rbrainz/model/default_factory.rb +78 -0
- data/lib/rbrainz/model/disc.rb +45 -8
- data/lib/rbrainz/model/entity.rb +122 -53
- data/lib/rbrainz/model/incomplete_date.rb +31 -47
- data/lib/rbrainz/model/individual.rb +103 -0
- data/lib/rbrainz/model/label.rb +42 -33
- data/lib/rbrainz/model/mbid.rb +111 -40
- data/lib/rbrainz/model/relation.rb +78 -14
- data/lib/rbrainz/model/release.rb +119 -31
- data/lib/rbrainz/model/release_event.rb +38 -9
- data/lib/rbrainz/model/scored_collection.rb +99 -0
- data/lib/rbrainz/model/tag.rb +39 -0
- data/lib/rbrainz/model/track.rb +37 -13
- data/lib/rbrainz/model/user.rb +48 -0
- data/lib/rbrainz/utils.rb +9 -0
- data/lib/rbrainz/utils/data.rb +78 -0
- data/lib/rbrainz/utils/helper.rb +22 -0
- data/lib/rbrainz/version.rb +15 -0
- data/lib/rbrainz/webservice.rb +32 -6
- data/lib/rbrainz/webservice/filter.rb +124 -47
- data/lib/rbrainz/webservice/includes.rb +49 -10
- data/lib/rbrainz/webservice/mbxml.rb +228 -173
- data/lib/rbrainz/webservice/query.rb +312 -25
- data/lib/rbrainz/webservice/webservice.rb +164 -27
- data/test/lib/mock_webservice.rb +53 -0
- data/test/lib/test_entity.rb +27 -8
- data/test/lib/test_factory.rb +47 -0
- data/test/lib/testing_helper.rb +7 -5
- data/test/test-data/invalid/artist/tags_1.xml +6 -0
- data/test/test-data/valid/artist/Tchaikovsky-2.xml +12 -0
- data/test/test-data/valid/label/Atlantic_Records_2.xml +3 -0
- data/test/test-data/valid/label/Atlantic_Records_3.xml +11 -0
- data/test/test-data/valid/release/Highway_61_Revisited_2.xml +12 -0
- data/test/test-data/valid/track/Silent_All_These_Years_6.xml +8 -0
- data/test/test_alias.rb +13 -7
- data/test/test_artist.rb +26 -4
- data/test/test_artist_filter.rb +11 -6
- data/test/test_artist_includes.rb +11 -6
- data/test/test_collection.rb +66 -0
- data/test/test_default_factory.rb +75 -0
- data/test/test_disc.rb +9 -4
- data/test/test_incomplete_date.rb +21 -14
- data/test/test_label.rb +56 -18
- data/test/test_label_filter.rb +10 -5
- data/test/test_label_includes.rb +11 -6
- data/test/test_mbid.rb +34 -19
- data/test/test_mbxml.rb +242 -72
- data/test/test_query.rb +92 -7
- data/test/test_range_equality.rb +144 -0
- data/test/test_relation.rb +18 -7
- data/test/test_release.rb +15 -4
- data/test/test_release_event.rb +16 -4
- data/test/test_release_filter.rb +11 -5
- data/test/test_release_includes.rb +11 -6
- data/test/test_scored_collection.rb +86 -0
- data/test/test_tag.rb +39 -0
- data/test/test_track.rb +15 -4
- data/test/test_track_filter.rb +11 -5
- data/test/test_track_includes.rb +11 -6
- data/test/test_utils.rb +41 -0
- data/test/test_webservice.rb +16 -17
- metadata +93 -57
data/lib/rbrainz/model.rb
CHANGED
@@ -1,9 +1,22 @@
|
|
1
|
-
# $Id: model.rb
|
2
|
-
#
|
3
|
-
#
|
4
|
-
#
|
1
|
+
# $Id: model.rb 143 2007-07-18 11:40:55Z phw $
|
2
|
+
#
|
3
|
+
# Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
|
4
|
+
# Copyright:: Copyright (c) 2007, Nigel Graham, Philipp Wolfer
|
5
|
+
# License:: RBrainz is free software distributed under a BSD style license.
|
6
|
+
# See LICENSE[file:../LICENSE.html] for permissions.
|
5
7
|
|
6
|
-
module MusicBrainz
|
8
|
+
module MusicBrainz # :nodoc:
|
9
|
+
|
10
|
+
# The MusicBrainz domain model.
|
11
|
+
# These classes are part of the MusicBrainz domain model. They may be used
|
12
|
+
# by other modules and don't contain any network or other I/O code. If you
|
13
|
+
# want to request data from the web service, please have a look at
|
14
|
+
# Webservice::Query.
|
15
|
+
#
|
16
|
+
# The most important classes, usually acting as entry points, are
|
17
|
+
# Artist, Release, Track and Label.
|
18
|
+
#
|
19
|
+
# See:: Webservice
|
7
20
|
module Model
|
8
21
|
|
9
22
|
# Namespace for all MusicBrainz metadata.
|
@@ -14,35 +27,14 @@ module MusicBrainz
|
|
14
27
|
|
15
28
|
# Namespace for MusicBrainz extensions.
|
16
29
|
NS_EXT_1 = 'http://musicbrainz.org/ns/ext-1.0#'
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
# The format of a MusicBrainz identifier was wrong.
|
22
|
-
class InvalidMBIDError < Exception
|
23
|
-
end
|
24
|
-
|
25
|
-
# The format of a MusicBrainz UUID was wrong.
|
26
|
-
class InvalidUUIDError < Exception
|
27
|
-
end
|
28
|
-
|
29
|
-
# An unknown entity was encountered.
|
30
|
-
# Valid entities are only :artist, :release, :track and :label.
|
31
|
-
class UnknownEntityError < Exception
|
32
|
-
end
|
33
|
-
|
34
|
-
# The entity type of a MBID didn't match the type of the entity.
|
35
|
-
class EntityTypeNotMatchingError < Exception
|
36
|
-
end
|
30
|
+
|
31
|
+
require 'rbrainz/model/default_factory'
|
32
|
+
require 'rbrainz/utils'
|
33
|
+
require 'rbrainz/core_ext'
|
37
34
|
|
35
|
+
# The ID of the special 'Various Artists' artist. This is an instance of MBID.
|
36
|
+
# See:: http://musicbrainz.org/doc/VariousArtists
|
37
|
+
VARIOUS_ARTISTS_ID = MBID.new('89ad4ac3-39f7-470e-963a-56509c546377', Artist.entity_type)
|
38
|
+
|
38
39
|
end
|
39
|
-
end
|
40
|
-
|
41
|
-
require 'rbrainz/data/countrynames'
|
42
|
-
require 'rbrainz/data/languagenames'
|
43
|
-
require 'rbrainz/data/scriptnames'
|
44
|
-
|
45
|
-
require 'rbrainz/model/artist'
|
46
|
-
require 'rbrainz/model/label'
|
47
|
-
require 'rbrainz/model/release'
|
48
|
-
require 'rbrainz/model/track'
|
40
|
+
end
|
data/lib/rbrainz/model/alias.rb
CHANGED
@@ -1,17 +1,41 @@
|
|
1
|
-
# $Id: alias.rb
|
2
|
-
#
|
3
|
-
#
|
4
|
-
#
|
1
|
+
# $Id: alias.rb 145 2007-07-19 13:11:44Z phw $
|
2
|
+
#
|
3
|
+
# Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
|
4
|
+
# Copyright:: Copyright (c) 2007, Nigel Graham, Philipp Wolfer
|
5
|
+
# License:: RBrainz is free software distributed under a BSD style license.
|
6
|
+
# See LICENSE[file:../LICENSE.html] for permissions.
|
5
7
|
|
6
8
|
module MusicBrainz
|
7
9
|
module Model
|
8
10
|
|
9
|
-
#
|
11
|
+
#
|
12
|
+
# Represents an artist or label alias.
|
13
|
+
#
|
14
|
+
# An alias (the <i>alias name</i>) is a different representation of an
|
15
|
+
# artist's or label's name. This may be a common misspelling or
|
16
|
+
# a transliteration (the <i>alias type</i>).
|
10
17
|
#
|
11
|
-
#
|
18
|
+
# The <i>alias script</i> is interesting mostly for transliterations and
|
19
|
+
# indicates which script is used for the alias value. To represent the
|
20
|
+
# script, ISO-15924 script codes like 'Latn', 'Cyrl', or 'Hebr' are used.
|
21
|
+
#
|
22
|
+
# See:: http://musicbrainz.org/doc/ArtistAlias.
|
12
23
|
class Alias
|
13
24
|
|
14
|
-
|
25
|
+
# The alias name.
|
26
|
+
attr_accessor :name
|
27
|
+
|
28
|
+
# The alias type. An absolute URI or +nil+.
|
29
|
+
attr_accessor :type
|
30
|
+
|
31
|
+
# The alias script. See Utils#get_script_name.
|
32
|
+
attr_accessor :script
|
33
|
+
|
34
|
+
def initialize(name=nil, type=nil, script=nil)
|
35
|
+
self.name = name
|
36
|
+
self.type = type
|
37
|
+
self.script = script
|
38
|
+
end
|
15
39
|
|
16
40
|
def to_s
|
17
41
|
return name.to_s
|
data/lib/rbrainz/model/artist.rb
CHANGED
@@ -1,52 +1,41 @@
|
|
1
|
-
# $Id: artist.rb
|
2
|
-
#
|
3
|
-
#
|
4
|
-
#
|
1
|
+
# $Id: artist.rb 140 2007-07-17 13:27:54Z phw $
|
2
|
+
#
|
3
|
+
# Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
|
4
|
+
# Copyright:: Copyright (c) 2007, Nigel Graham, Philipp Wolfer
|
5
|
+
# License:: RBrainz is free software distributed under a BSD style license.
|
6
|
+
# See LICENSE[file:../LICENSE.html] for permissions.
|
5
7
|
|
6
|
-
require 'rbrainz/model/
|
8
|
+
require 'rbrainz/model/individual'
|
7
9
|
require 'rbrainz/model/alias'
|
8
|
-
require 'rbrainz/model/incomplete_date'
|
9
10
|
|
10
11
|
module MusicBrainz
|
11
12
|
module Model
|
12
13
|
|
14
|
+
#
|
13
15
|
# An artist in the MusicBrainz DB.
|
14
|
-
#
|
15
|
-
#
|
16
|
-
|
16
|
+
#
|
17
|
+
# Artists in MusicBrainz can have a type. Currently, this type can
|
18
|
+
# be either Person or Group for which the following URIs are assigned:
|
19
|
+
#
|
20
|
+
# - http://musicbrainz.org/ns/mmd-1.0#Person
|
21
|
+
# - http://musicbrainz.org/ns/mmd-1.0#Group
|
22
|
+
#
|
23
|
+
# Use the TYPE_PERSON and TYPE_GROUP constants for comparison.
|
24
|
+
#
|
25
|
+
# See:: Individual
|
26
|
+
# See:: http://musicbrainz.org/doc/Artist.
|
27
|
+
class Artist < Individual
|
17
28
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
@releases = Array.new
|
29
|
-
end
|
30
|
-
|
31
|
-
# Set the begin date of this artist.
|
32
|
-
#
|
33
|
-
# Should be an IncompleteDate object or
|
34
|
-
# a date string, which will get converted
|
35
|
-
# into an IncompleteDate.
|
36
|
-
def begin_date=(date)
|
37
|
-
date = IncompleteDate.new date unless date.is_a? IncompleteDate
|
38
|
-
@begin_date = date
|
39
|
-
end
|
40
|
-
|
41
|
-
# Set the end date of this artist.
|
42
|
-
#
|
43
|
-
# Should be an IncompleteDate object or
|
44
|
-
# a date string, which will get converted
|
45
|
-
# into an IncompleteDate.
|
46
|
-
def end_date=(date)
|
47
|
-
date = IncompleteDate.new date unless date.is_a? IncompleteDate
|
48
|
-
@end_date = date
|
49
|
-
end
|
29
|
+
# Used if the type of the artist is unknown.
|
30
|
+
TYPE_UNKNOWN = NS_MMD_1 + 'Unknown'
|
31
|
+
# This indicates an individual person.
|
32
|
+
TYPE_PERSON = NS_MMD_1 + 'Person'
|
33
|
+
# This indicates a group of people that may or may
|
34
|
+
# not have a distinctive name.
|
35
|
+
TYPE_GROUP = NS_MMD_1 + 'Group'
|
36
|
+
|
37
|
+
# See Entity::ENTITY_TYPE.
|
38
|
+
ENTITY_TYPE = :artist # :nodoc:
|
50
39
|
|
51
40
|
end
|
52
41
|
|
@@ -0,0 +1,102 @@
|
|
1
|
+
# $Id: collection.rb 130 2007-07-12 18:55:24Z nigel_graham $
|
2
|
+
#
|
3
|
+
# Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
|
4
|
+
# Copyright:: Copyright (c) 2007, Nigel Graham, Philipp Wolfer
|
5
|
+
# License:: RBrainz is free software distributed under a BSD style license.
|
6
|
+
# See LICENSE[file:../LICENSE.html] for permissions.
|
7
|
+
|
8
|
+
require 'rbrainz/model/entity'
|
9
|
+
|
10
|
+
module MusicBrainz
|
11
|
+
module Model
|
12
|
+
|
13
|
+
# A Collection is a list of models.
|
14
|
+
#
|
15
|
+
# A collection object may only store an extract of the complete data
|
16
|
+
# available on the server. This is especially the case if the limit or
|
17
|
+
# offset filter was used in the query. The collection object makes the
|
18
|
+
# total number of elements on the server and the current offset available
|
19
|
+
# with the +count+ respective the +offset+ parameter.
|
20
|
+
class Collection
|
21
|
+
|
22
|
+
include ::Enumerable
|
23
|
+
|
24
|
+
# Returns the total number of elements for that collection on the server.
|
25
|
+
attr_accessor :count
|
26
|
+
|
27
|
+
# Returns the position at which this collection starts. Used for paging
|
28
|
+
# through more than one page of results.
|
29
|
+
attr_accessor :offset
|
30
|
+
|
31
|
+
# Create a new collection object.
|
32
|
+
#
|
33
|
+
# The count and offset parameters should be set according to the values
|
34
|
+
# returned by the server.
|
35
|
+
def initialize(count=0, offset=0, array=nil)
|
36
|
+
@count = count.to_i
|
37
|
+
@offset = offset.to_i
|
38
|
+
if array
|
39
|
+
@entries = array.to_ary.dup
|
40
|
+
else
|
41
|
+
@entries = Array.new
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# Add a new element to this collection.
|
46
|
+
def <<(entry)
|
47
|
+
@entries << entry
|
48
|
+
end
|
49
|
+
|
50
|
+
# Delete an element from the collection.
|
51
|
+
def delete(entry)
|
52
|
+
@entries.delete(entry)
|
53
|
+
end
|
54
|
+
|
55
|
+
# Iterate over the contents of the collection.
|
56
|
+
def each
|
57
|
+
@entries.each {|e| yield e}
|
58
|
+
end
|
59
|
+
|
60
|
+
# Access a random element in the collection by the element's index.
|
61
|
+
def [](index)
|
62
|
+
@entries[index]
|
63
|
+
end
|
64
|
+
|
65
|
+
# Set a random element in the collection by the element's index.
|
66
|
+
def []=(index, entry)
|
67
|
+
@entries[index] = entry
|
68
|
+
end
|
69
|
+
|
70
|
+
# Create a new collection containing the elements of both collections.
|
71
|
+
# Count and offset will be set to +nil+ in the new collection.
|
72
|
+
def +(other_collection)
|
73
|
+
new_collection = Collection.new
|
74
|
+
(self.to_a + other_collection.to_a).each do |entry|
|
75
|
+
new_collection << entry
|
76
|
+
end
|
77
|
+
return new_collection
|
78
|
+
end
|
79
|
+
|
80
|
+
# The number of elements in the collection.
|
81
|
+
def size
|
82
|
+
@entries.size
|
83
|
+
end
|
84
|
+
|
85
|
+
# Returns true, if the collection contains no elements.
|
86
|
+
def empty?
|
87
|
+
@entries.empty?
|
88
|
+
end
|
89
|
+
|
90
|
+
# Convert the collection into an Array.
|
91
|
+
def to_a
|
92
|
+
@entries.dup
|
93
|
+
end
|
94
|
+
alias to_ary to_a
|
95
|
+
|
96
|
+
def dup
|
97
|
+
Collection.new(self.count, self.offset, @entries)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# $Id: default_factory.rb 143 2007-07-18 11:40:55Z phw $
|
2
|
+
#
|
3
|
+
# Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
|
4
|
+
# Copyright:: Copyright (c) 2007, Nigel Graham, Philipp Wolfer
|
5
|
+
# License:: RBrainz is free software distributed under a BSD style license.
|
6
|
+
# See LICENSE[file:../LICENSE.html] for permissions.
|
7
|
+
|
8
|
+
require 'rbrainz/model/artist'
|
9
|
+
require 'rbrainz/model/label'
|
10
|
+
require 'rbrainz/model/release'
|
11
|
+
require 'rbrainz/model/track'
|
12
|
+
require 'rbrainz/model/user'
|
13
|
+
|
14
|
+
module MusicBrainz
|
15
|
+
module Model
|
16
|
+
|
17
|
+
# A factory to create model classes.
|
18
|
+
class DefaultFactory
|
19
|
+
|
20
|
+
# Creates a new entity for a given entity type (<tt>:artist</tt>,
|
21
|
+
# <tt>:label</tt>, <tt>:release</tt> or <tt>:track</tt>).
|
22
|
+
def new_entity(entity_type)
|
23
|
+
case entity_type
|
24
|
+
when :artist
|
25
|
+
new_artist
|
26
|
+
when :label
|
27
|
+
new_label
|
28
|
+
when :release
|
29
|
+
new_release
|
30
|
+
when :track
|
31
|
+
new_track
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def new_artist
|
36
|
+
Artist.new
|
37
|
+
end
|
38
|
+
|
39
|
+
def new_label
|
40
|
+
Label.new
|
41
|
+
end
|
42
|
+
|
43
|
+
def new_release
|
44
|
+
Release.new
|
45
|
+
end
|
46
|
+
|
47
|
+
def new_track
|
48
|
+
Track.new
|
49
|
+
end
|
50
|
+
|
51
|
+
def new_alias
|
52
|
+
Alias.new
|
53
|
+
end
|
54
|
+
|
55
|
+
def new_disc
|
56
|
+
Disc.new
|
57
|
+
end
|
58
|
+
|
59
|
+
def new_relation
|
60
|
+
Relation.new
|
61
|
+
end
|
62
|
+
|
63
|
+
def new_release_event
|
64
|
+
ReleaseEvent.new
|
65
|
+
end
|
66
|
+
|
67
|
+
def new_tag
|
68
|
+
Tag.new
|
69
|
+
end
|
70
|
+
|
71
|
+
def new_user
|
72
|
+
User.new
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
end
|
data/lib/rbrainz/model/disc.rb
CHANGED
@@ -1,14 +1,16 @@
|
|
1
|
-
# $Id: disc.rb
|
2
|
-
#
|
3
|
-
#
|
4
|
-
#
|
1
|
+
# $Id: disc.rb 141 2007-07-17 14:21:12Z phw $
|
2
|
+
#
|
3
|
+
# Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
|
4
|
+
# Copyright:: Copyright (c) 2007, Nigel Graham, Philipp Wolfer
|
5
|
+
# License:: RBrainz is free software distributed under a BSD style license.
|
6
|
+
# See LICENSE[file:../LICENSE.html] for permissions.
|
5
7
|
|
6
8
|
module MusicBrainz
|
7
9
|
module Model
|
8
10
|
|
9
11
|
# Represents an audio CD.
|
10
12
|
#
|
11
|
-
# A disc has a disc
|
13
|
+
# A disc has a disc ID, which is calculated from the
|
12
14
|
# CD's table of contents (TOC). It also can include
|
13
15
|
# the numbers of sectors on the CD.
|
14
16
|
#
|
@@ -17,12 +19,47 @@ module MusicBrainz
|
|
17
19
|
# id. See Webservice::ReleaseFilter for details on
|
18
20
|
# this.
|
19
21
|
#
|
20
|
-
#
|
22
|
+
# If you need to calculate disc IDs you should install the mb-discid
|
23
|
+
# package. It allows you to calculate the disc ID for an audio CD.
|
21
24
|
#
|
22
|
-
#
|
25
|
+
# Example:
|
26
|
+
# require 'rbrainz'
|
27
|
+
# require 'mb-discid'
|
28
|
+
#
|
29
|
+
# discid = MusicBrainz::DiscID.new
|
30
|
+
# discid.read
|
31
|
+
#
|
32
|
+
# disc = MusicBrainz::Model::Disc.new
|
33
|
+
# disc.id = discid
|
34
|
+
#
|
35
|
+
# See:: http://wiki.musicbrainz.org/DiscID for more information about
|
36
|
+
# MusicBrainz disc IDs.
|
37
|
+
# See:: http://rbrainz.rubyforge.org/mbdiscid/api/
|
23
38
|
class Disc
|
24
39
|
|
25
|
-
|
40
|
+
# Number of sectors on the disc
|
41
|
+
attr_accessor :sectors
|
42
|
+
|
43
|
+
# The MusicBrainz DiscID. A string containing a 28-character DiscID.
|
44
|
+
attr_reader :id
|
45
|
+
|
46
|
+
def initialize(id=nil)
|
47
|
+
self.id = id if id
|
48
|
+
end
|
49
|
+
|
50
|
+
# Set the MusicBrainz disc ID for this disc.
|
51
|
+
#
|
52
|
+
# The disc_id argument can be a string or a MusicBrainz::DiscID object.
|
53
|
+
def id=(disc_id)
|
54
|
+
@id = disc_id.to_s
|
55
|
+
end
|
56
|
+
|
57
|
+
# Convert the Disc into a string.
|
58
|
+
#
|
59
|
+
# Returns #id converted into a string.
|
60
|
+
def to_s
|
61
|
+
id.to_s
|
62
|
+
end
|
26
63
|
|
27
64
|
end
|
28
65
|
|