rbrainz 0.4.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +13 -1
- data/LICENSE +1 -1
- data/README +2 -2
- data/Rakefile +2 -2
- data/TODO +9 -2
- data/doc/README.rdoc +5 -5
- data/examples/getartist.rb +3 -2
- data/examples/getlabel.rb +3 -2
- data/examples/getrelease.rb +5 -2
- data/examples/getreleasegroup.rb +53 -0
- data/examples/gettrack.rb +3 -2
- data/examples/getuser.rb +2 -1
- data/examples/rate.rb +44 -0
- data/examples/searchartists.rb +3 -2
- data/examples/searchcdstubs.rb +41 -0
- data/examples/searchlabels.rb +3 -2
- data/examples/searchreleasegroups.rb +36 -0
- data/examples/searchreleases.rb +6 -4
- data/examples/searchtracks.rb +3 -2
- data/examples/submit_isrcs.rb +52 -0
- data/examples/tag.rb +3 -2
- data/lib/rbrainz.rb +2 -1
- data/lib/rbrainz/core_ext.rb +2 -1
- data/lib/rbrainz/core_ext/mbid.rb +2 -1
- data/lib/rbrainz/core_ext/net_http_digest.rb +3 -2
- data/lib/rbrainz/core_ext/range.rb +3 -2
- data/lib/rbrainz/core_ext/range/equality.rb +2 -1
- data/lib/rbrainz/data/countrynames.rb +6 -3
- data/lib/rbrainz/data/languagenames.rb +3 -2
- data/lib/rbrainz/data/releasetypenames.rb +3 -2
- data/lib/rbrainz/data/scriptnames.rb +3 -2
- data/lib/rbrainz/model.rb +3 -2
- data/lib/rbrainz/model/alias.rb +3 -2
- data/lib/rbrainz/model/artist.rb +11 -3
- data/lib/rbrainz/model/collection.rb +3 -2
- data/lib/rbrainz/model/default_factory.rb +18 -6
- data/lib/rbrainz/model/disc.rb +3 -2
- data/lib/rbrainz/model/entity.rb +2 -102
- data/lib/rbrainz/model/incomplete_date.rb +3 -2
- data/lib/rbrainz/model/individual.rb +11 -2
- data/lib/rbrainz/model/isrc.rb +100 -0
- data/lib/rbrainz/model/label.rb +5 -2
- data/lib/rbrainz/model/mbid.rb +28 -9
- data/lib/rbrainz/model/rateable.rb +34 -0
- data/lib/rbrainz/model/rating.rb +56 -0
- data/lib/rbrainz/model/relateable.rb +118 -0
- data/lib/rbrainz/model/relation.rb +2 -1
- data/lib/rbrainz/model/release.rb +17 -3
- data/lib/rbrainz/model/release_event.rb +3 -2
- data/lib/rbrainz/model/release_group.rb +97 -0
- data/lib/rbrainz/model/scored_collection.rb +3 -2
- data/lib/rbrainz/model/tag.rb +5 -4
- data/lib/rbrainz/model/taggable.rb +27 -0
- data/lib/rbrainz/model/track.rb +15 -2
- data/lib/rbrainz/model/user.rb +3 -2
- data/lib/rbrainz/utils.rb +2 -1
- data/lib/rbrainz/utils/data.rb +3 -2
- data/lib/rbrainz/utils/helper.rb +8 -2
- data/lib/rbrainz/version.rb +3 -2
- data/lib/rbrainz/webservice.rb +12 -7
- data/lib/rbrainz/webservice/filter.rb +53 -4
- data/lib/rbrainz/webservice/includes.rb +72 -11
- data/lib/rbrainz/webservice/mbxml.rb +129 -67
- data/lib/rbrainz/webservice/query.rb +156 -16
- data/lib/rbrainz/webservice/webservice.rb +104 -116
- data/test/lib/mock_webservice.rb +9 -2
- data/test/lib/test_entity.rb +2 -97
- data/test/lib/test_factory.rb +9 -1
- data/test/lib/test_rateable.rb +31 -0
- data/test/lib/test_relateable.rb +103 -0
- data/test/lib/test_taggable.rb +36 -0
- data/test/lib/testing_helper.rb +17 -2
- data/test/test-data/invalid/artist/ratings_1.xml +6 -0
- data/test/test-data/invalid/artist/ratings_2.xml +6 -0
- data/test/test-data/valid/artist/Tchaikovsky-2.xml +6 -0
- data/test/test-data/valid/label/Atlantic_Records_3.xml +6 -0
- data/test/test-data/valid/release-group/The_Cure_1.xml +36 -0
- data/test/test-data/valid/release/Highway_61_Revisited_2.xml +6 -0
- data/test/test-data/valid/track/Silent_All_These_Years_4.xml +3 -0
- data/test/test-data/valid/track/Silent_All_These_Years_6.xml +8 -0
- data/test/test_alias.rb +2 -1
- data/test/test_artist.rb +24 -2
- data/test/test_artist_filter.rb +2 -1
- data/test/test_artist_includes.rb +13 -3
- data/test/test_collection.rb +3 -2
- data/test/test_default_factory.rb +8 -1
- data/test/test_disc.rb +2 -1
- data/test/test_incomplete_date.rb +2 -1
- data/test/test_isrc.rb +87 -0
- data/test/test_label.rb +8 -1
- data/test/test_label_filter.rb +2 -1
- data/test/test_label_includes.rb +10 -3
- data/test/test_mbid.rb +2 -1
- data/test/test_mbxml.rb +93 -2
- data/test/test_query.rb +68 -5
- data/test/test_range_equality.rb +2 -1
- data/test/test_rating.rb +46 -0
- data/test/test_relation.rb +2 -1
- data/test/test_release.rb +37 -2
- data/test/test_release_event.rb +2 -1
- data/test/test_release_filter.rb +15 -2
- data/test/test_release_group.rb +104 -0
- data/test/test_release_group_filter.rb +61 -0
- data/test/test_release_group_includes.rb +46 -0
- data/test/test_release_includes.rb +16 -3
- data/test/test_scored_collection.rb +3 -2
- data/test/test_tag.rb +2 -1
- data/test/test_track.rb +28 -1
- data/test/test_track_filter.rb +2 -1
- data/test/test_track_includes.rb +13 -3
- data/test/test_utils.rb +2 -1
- data/test/test_webservice.rb +11 -1
- metadata +38 -20
- data/debian/changelog +0 -11
- data/debian/compat +0 -1
- data/debian/control +0 -13
- data/debian/copyright +0 -25
- data/debian/rules +0 -48
data/examples/searchtracks.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# -*- coding: utf-8 -*-
|
2
3
|
#
|
3
4
|
# Example script which searches the database for
|
4
5
|
# tracks and displays the track data.
|
5
6
|
#
|
6
|
-
# $Id: searchtracks.rb
|
7
|
+
# $Id: searchtracks.rb 254 2009-05-13 20:04:36Z phw $
|
7
8
|
|
8
9
|
# Just make sure we can run this example from the command
|
9
10
|
# line even if RBrainz is not yet installed properly.
|
@@ -32,4 +33,4 @@ tracks = query.get_tracks(track_filter)
|
|
32
33
|
# indicates how good the track matches the search parameters.
|
33
34
|
tracks.each do |entry|
|
34
35
|
print "%s: \"%s\" (%i%%)\r\n" % [entry.entity.artist, entry.entity.title, entry.score]
|
35
|
-
end
|
36
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
#
|
4
|
+
# Example for submitting ISRCs to MusicBrainz.
|
5
|
+
# This script will submit the ISRCs for the release Clayman by In Flames
|
6
|
+
# (http://musicbrainz.org/album/1de625a1-55a5-4f8a-96f9-6d0a2a37ddcd.html).
|
7
|
+
# The ISRCs were taken from the GEMA database at
|
8
|
+
# http://mgonline.gema.de/soundcarrier/searchTracks.do?id=370495&seq=1&title=CLAYMAN
|
9
|
+
#
|
10
|
+
# $Id: submit_isrcs.rb 273 2009-05-24 22:29:04Z phw $
|
11
|
+
|
12
|
+
# Just make sure we can run this example from the command
|
13
|
+
# line even if RBrainz is not yet installed properly.
|
14
|
+
$: << 'lib/' << '../lib/'
|
15
|
+
|
16
|
+
# Load RBrainz and include the MusicBrainz namespace.
|
17
|
+
require 'rbrainz'
|
18
|
+
include MusicBrainz
|
19
|
+
|
20
|
+
# Get the username and password
|
21
|
+
print 'Username: ' unless ARGV[0]
|
22
|
+
username = ARGV[0] ? ARGV[0] : STDIN.gets.strip
|
23
|
+
print 'Password: ' unless ARGV[1]
|
24
|
+
password = ARGV[1] ? ARGV[1] : STDIN.gets.strip
|
25
|
+
|
26
|
+
# Set the authentication for the webservice.
|
27
|
+
ws = Webservice::Webservice.new(
|
28
|
+
:host => 'musicbrainz.org',
|
29
|
+
:username => username,
|
30
|
+
:password => password
|
31
|
+
)
|
32
|
+
|
33
|
+
# Create a new Query object which will provide
|
34
|
+
# us an interface to the MusicBrainz web service.
|
35
|
+
query = Webservice::Query.new(ws, :client_id => 'RBrainz test ' + RBRAINZ_VERSION)
|
36
|
+
|
37
|
+
# Submit the ISRCs for some tracks.
|
38
|
+
query.submit_isrcs([
|
39
|
+
['7f574ec1-344c-4ae1-970d-3c757f9a717e', 'DED830049301'],
|
40
|
+
['1393122c-364c-4fb6-9a4b-17eddce90152', 'DED830049302'],
|
41
|
+
['2634965c-5299-4958-b0dc-47b166bb6898', 'DED830049303'],
|
42
|
+
['dad6b8a4-0412-4a80-9123-3e0ebddaf82d', 'DED830049304'],
|
43
|
+
['e1f7e805-33f3-4663-b294-3805b82405f9', 'DED830049305'],
|
44
|
+
['d9f932ad-de0d-44ca-bf35-ae8184f63909', 'DED830049306'],
|
45
|
+
['c983b62d-f528-433f-a402-a6317ce3d2d8', 'DED830049307'],
|
46
|
+
['9d50b06a-4136-427f-8d11-b2efb0141da6', 'DED830049308'],
|
47
|
+
['f2af3e3f-3f9f-4f8d-8b60-1d1b709aaf69', 'DED830049309'],
|
48
|
+
['059384bc-fb45-445e-ab77-950d6ccf587a', 'DED830049310'],
|
49
|
+
['2f4d7b47-a4ba-495a-b447-60b8287ed9c9', 'DED830049311'],
|
50
|
+
])
|
51
|
+
|
52
|
+
puts "ISRCs submitted."
|
data/examples/tag.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# -*- coding: utf-8 -*-
|
2
3
|
#
|
3
4
|
# Example script showing the use of folksonomy tagging with RBrainz.
|
4
5
|
# It asks the user for his username and password and a MBID and queries the
|
5
6
|
# MusicBrainz server for the tags, the user has applied to the entitity with
|
6
7
|
# the given MBID. Afterwards the user can submit new tags.
|
7
8
|
#
|
8
|
-
# $Id:
|
9
|
+
# $Id: tag.rb 273 2009-05-24 22:29:04Z phw $
|
9
10
|
|
10
11
|
# Just make sure we can run this example from the command
|
11
12
|
# line even if RBrainz is not yet installed properly.
|
@@ -40,4 +41,4 @@ puts tags.to_a.join(', ')
|
|
40
41
|
# Ask the user for new tags and submit them
|
41
42
|
print 'Enter new tags: '
|
42
43
|
new_tags = STDIN.gets.strip
|
43
|
-
query.submit_user_tags(mbid, new_tags)
|
44
|
+
query.submit_user_tags(mbid, new_tags)
|
data/lib/rbrainz.rb
CHANGED
data/lib/rbrainz/core_ext.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
#
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# $Id: net_http_digest.rb 254 2009-05-13 20:04:36Z phw $
|
2
3
|
#
|
3
4
|
# Author:: Nigel Graham (mailto:nigel_graham@rubyforge.org)
|
4
5
|
# Copyright:: Copyright (c) 2007, Nigel Graham, Philipp Wolfer
|
@@ -86,4 +87,4 @@ module Net # :nodoc:
|
|
86
87
|
return header
|
87
88
|
end
|
88
89
|
end
|
89
|
-
end
|
90
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
|
-
#
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# $Id: range.rb 254 2009-05-13 20:04:36Z phw $
|
2
3
|
#
|
3
4
|
# Author:: Nigel Graham (mailto:nigel_graham@rubyforge.org)
|
4
5
|
# Copyright:: Copyright (c) 2007, Nigel Graham, Philipp Wolfer
|
@@ -12,4 +13,4 @@ class Range #:nodoc:
|
|
12
13
|
# Extend Range with additional comparison operations.
|
13
14
|
include MusicBrainz::CoreExtensions::Range::Equality
|
14
15
|
|
15
|
-
end
|
16
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
|
-
#
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# $Id: countrynames.rb 259 2009-05-17 17:44:00Z phw $
|
2
3
|
#
|
3
4
|
# Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
|
4
5
|
# Copyright:: Copyright (c) 2007, Nigel Graham, Philipp Wolfer
|
@@ -242,7 +243,9 @@ module MusicBrainz
|
|
242
243
|
'MZ' => 'Mozambique',
|
243
244
|
'BA' => 'Bosnia and Herzegovina',
|
244
245
|
'CD' => 'Congo, The Democratic Republic of the',
|
245
|
-
'CS' => 'Serbia and Montenegro',
|
246
|
+
'CS' => 'Serbia and Montenegro (historical, 2003-2006)',
|
247
|
+
'RS' => 'Serbia',
|
248
|
+
'ME' => 'Montenegro',
|
246
249
|
'HR' => 'Croatia',
|
247
250
|
'KP' => 'Korea (North), Democratic People\'s Republic of',
|
248
251
|
'KR' => 'Korea (South), Republic of',
|
@@ -258,4 +261,4 @@ module MusicBrainz
|
|
258
261
|
}
|
259
262
|
|
260
263
|
end
|
261
|
-
end
|
264
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
|
-
#
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# $Id: languagenames.rb 254 2009-05-13 20:04:36Z phw $
|
2
3
|
#
|
3
4
|
# Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
|
4
5
|
# Copyright:: Copyright (c) 2007, Nigel Graham, Philipp Wolfer
|
@@ -404,4 +405,4 @@ module MusicBrainz
|
|
404
405
|
'SQI' => 'Albanian',
|
405
406
|
}
|
406
407
|
end
|
407
|
-
end
|
408
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
|
-
#
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# $Id: releasetypenames.rb 273 2009-05-24 22:29:04Z phw $
|
2
3
|
#
|
3
4
|
# Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
|
4
5
|
# Copyright:: Copyright (c) 2007, Nigel Graham, Philipp Wolfer
|
@@ -31,4 +32,4 @@ module MusicBrainz
|
|
31
32
|
}
|
32
33
|
|
33
34
|
end
|
34
|
-
end
|
35
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
|
-
#
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# $Id: scriptnames.rb 254 2009-05-13 20:04:36Z phw $
|
2
3
|
#
|
3
4
|
# Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
|
4
5
|
# Copyright:: Copyright (c) 2007, Nigel Graham, Philipp Wolfer
|
@@ -64,4 +65,4 @@ module MusicBrainz
|
|
64
65
|
}
|
65
66
|
|
66
67
|
end
|
67
|
-
end
|
68
|
+
end
|
data/lib/rbrainz/model.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
#
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# $Id: model.rb 254 2009-05-13 20:04:36Z phw $
|
2
3
|
#
|
3
4
|
# Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
|
4
5
|
# Copyright:: Copyright (c) 2007, Nigel Graham, Philipp Wolfer
|
@@ -37,4 +38,4 @@ module MusicBrainz # :nodoc:
|
|
37
38
|
VARIOUS_ARTISTS_ID = MBID.new('89ad4ac3-39f7-470e-963a-56509c546377', Artist.entity_type)
|
38
39
|
|
39
40
|
end
|
40
|
-
end
|
41
|
+
end
|
data/lib/rbrainz/model/alias.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
#
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# $Id: alias.rb 254 2009-05-13 20:04:36Z phw $
|
2
3
|
#
|
3
4
|
# Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
|
4
5
|
# Copyright:: Copyright (c) 2007, Nigel Graham, Philipp Wolfer
|
@@ -44,4 +45,4 @@ module MusicBrainz
|
|
44
45
|
end
|
45
46
|
|
46
47
|
end
|
47
|
-
end
|
48
|
+
end
|
data/lib/rbrainz/model/artist.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
#
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# $Id: artist.rb 258 2009-05-17 17:43:58Z phw $
|
2
3
|
#
|
3
4
|
# Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
|
4
5
|
# Copyright:: Copyright (c) 2007, Nigel Graham, Philipp Wolfer
|
@@ -6,7 +7,6 @@
|
|
6
7
|
# See LICENSE[file:../LICENSE.html] for permissions.
|
7
8
|
|
8
9
|
require 'rbrainz/model/individual'
|
9
|
-
require 'rbrainz/model/alias'
|
10
10
|
|
11
11
|
module MusicBrainz
|
12
12
|
module Model
|
@@ -37,7 +37,15 @@ module MusicBrainz
|
|
37
37
|
# See Entity::ENTITY_TYPE.
|
38
38
|
ENTITY_TYPE = :artist # :nodoc:
|
39
39
|
|
40
|
+
# A Collection of release groups of this artist.
|
41
|
+
attr_reader :release_groups
|
42
|
+
|
43
|
+
def initialize(id=nil, type=nil, name=nil, sort_name=nil)
|
44
|
+
super id, type, name, sort_name
|
45
|
+
@release_groups = Collection.new
|
46
|
+
end
|
47
|
+
|
40
48
|
end
|
41
49
|
|
42
50
|
end
|
43
|
-
end
|
51
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
|
-
#
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# $Id: collection.rb 254 2009-05-13 20:04:36Z phw $
|
2
3
|
#
|
3
4
|
# Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
|
4
5
|
# Copyright:: Copyright (c) 2007, Nigel Graham, Philipp Wolfer
|
@@ -101,4 +102,4 @@ module MusicBrainz
|
|
101
102
|
end
|
102
103
|
|
103
104
|
end
|
104
|
-
end
|
105
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
|
-
#
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# $Id: default_factory.rb 273 2009-05-24 22:29:04Z phw $
|
2
3
|
#
|
3
4
|
# Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
|
4
5
|
# Copyright:: Copyright (c) 2007, Nigel Graham, Philipp Wolfer
|
@@ -7,6 +8,7 @@
|
|
7
8
|
|
8
9
|
require 'rbrainz/model/artist'
|
9
10
|
require 'rbrainz/model/label'
|
11
|
+
require 'rbrainz/model/release_group'
|
10
12
|
require 'rbrainz/model/release'
|
11
13
|
require 'rbrainz/model/track'
|
12
14
|
require 'rbrainz/model/user'
|
@@ -21,13 +23,15 @@ module MusicBrainz
|
|
21
23
|
# <tt>:label</tt>, <tt>:release</tt> or <tt>:track</tt>).
|
22
24
|
def new_entity(entity_type)
|
23
25
|
case entity_type
|
24
|
-
when
|
26
|
+
when Artist.entity_type
|
25
27
|
new_artist
|
26
|
-
when
|
28
|
+
when Label.entity_type
|
27
29
|
new_label
|
28
|
-
when
|
30
|
+
when ReleaseGroup.entity_type
|
31
|
+
new_release_group
|
32
|
+
when Release.entity_type
|
29
33
|
new_release
|
30
|
-
when
|
34
|
+
when Track.entity_type
|
31
35
|
new_track
|
32
36
|
end
|
33
37
|
end
|
@@ -40,6 +44,10 @@ module MusicBrainz
|
|
40
44
|
Label.new
|
41
45
|
end
|
42
46
|
|
47
|
+
def new_release_group
|
48
|
+
ReleaseGroup.new
|
49
|
+
end
|
50
|
+
|
43
51
|
def new_release
|
44
52
|
Release.new
|
45
53
|
end
|
@@ -68,6 +76,10 @@ module MusicBrainz
|
|
68
76
|
Tag.new
|
69
77
|
end
|
70
78
|
|
79
|
+
def new_rating
|
80
|
+
Rating.new
|
81
|
+
end
|
82
|
+
|
71
83
|
def new_user
|
72
84
|
User.new
|
73
85
|
end
|
@@ -75,4 +87,4 @@ module MusicBrainz
|
|
75
87
|
end
|
76
88
|
|
77
89
|
end
|
78
|
-
end
|
90
|
+
end
|
data/lib/rbrainz/model/disc.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
#
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# $Id: disc.rb 254 2009-05-13 20:04:36Z phw $
|
2
3
|
#
|
3
4
|
# Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
|
4
5
|
# Copyright:: Copyright (c) 2007, Nigel Graham, Philipp Wolfer
|
@@ -64,4 +65,4 @@ module MusicBrainz
|
|
64
65
|
end
|
65
66
|
|
66
67
|
end
|
67
|
-
end
|
68
|
+
end
|
data/lib/rbrainz/model/entity.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
#
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# $Id: entity.rb 254 2009-05-13 20:04:36Z phw $
|
2
3
|
#
|
3
4
|
# Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
|
4
5
|
# Copyright:: Copyright (c) 2007, Nigel Graham, Philipp Wolfer
|
@@ -6,10 +7,6 @@
|
|
6
7
|
# See LICENSE[file:../LICENSE.html] for permissions.
|
7
8
|
|
8
9
|
require 'rbrainz/model/mbid'
|
9
|
-
require 'rbrainz/model/relation'
|
10
|
-
require 'rbrainz/model/collection'
|
11
|
-
require 'rbrainz/model/tag'
|
12
|
-
require 'set'
|
13
10
|
|
14
11
|
module MusicBrainz
|
15
12
|
module Model
|
@@ -45,21 +42,10 @@ module MusicBrainz
|
|
45
42
|
# The MusicBrainz ID. A MBID containing an absolute URI.
|
46
43
|
attr_reader :id
|
47
44
|
|
48
|
-
# A Collection of Tag objects assigned to this entity.
|
49
|
-
attr_reader :tags
|
50
|
-
|
51
45
|
# Create a new Entity. You can assign a MusicBrainz identifier to the
|
52
46
|
# created entity with the parameter _mbid_ (see id=).
|
53
47
|
def initialize(mbid=nil)
|
54
48
|
self.id = mbid
|
55
|
-
@tags = Collection.new
|
56
|
-
@relations = {
|
57
|
-
Relation::TO_ARTIST => Collection.new,
|
58
|
-
Relation::TO_RELEASE => Collection.new,
|
59
|
-
Relation::TO_TRACK => Collection.new,
|
60
|
-
Relation::TO_LABEL => Collection.new,
|
61
|
-
Relation::TO_URL => Collection.new,
|
62
|
-
}
|
63
49
|
end
|
64
50
|
|
65
51
|
# Set the MBID.
|
@@ -97,92 +83,6 @@ module MusicBrainz
|
|
97
83
|
self.class.entity_type
|
98
84
|
end
|
99
85
|
|
100
|
-
#
|
101
|
-
# Adds a relation.
|
102
|
-
#
|
103
|
-
# This method adds _relation_ to the list of relations. The
|
104
|
-
# given relation has to be initialized, at least the target
|
105
|
-
# type has to be set.
|
106
|
-
#
|
107
|
-
def add_relation(relation)
|
108
|
-
@relations[relation.target_type] << relation
|
109
|
-
end
|
110
|
-
|
111
|
-
#
|
112
|
-
# Returns a list of relations.
|
113
|
-
#
|
114
|
-
# If _target_type_ is given, only relations of that target
|
115
|
-
# type are returned. For MusicBrainz, the following target
|
116
|
-
# types are defined:
|
117
|
-
# - Relation::TO_ARTIST
|
118
|
-
# - Relation::TO_RELEASE
|
119
|
-
# - Relation::TO_TRACK
|
120
|
-
# - Relation::TO_URL
|
121
|
-
#
|
122
|
-
# If _target_type_ is Relation::TO_ARTIST, for example,
|
123
|
-
# this method returns all relations between this Entity and
|
124
|
-
# artists.
|
125
|
-
#
|
126
|
-
# You may use the _relation_type_ parameter to further restrict
|
127
|
-
# the selection. If it is set, only relations with the given
|
128
|
-
# relation type are returned. The _required_attributes_ sequence
|
129
|
-
# lists attributes that have to be part of all returned relations.
|
130
|
-
#
|
131
|
-
# If _direction_ is set, only relations with the given reading
|
132
|
-
# direction are returned. You can use the Relation::DIR_FORWARD,
|
133
|
-
# Relation::DIR_BACKWARD, and Relation::DIR_BOTH constants
|
134
|
-
# for this.
|
135
|
-
#
|
136
|
-
def get_relations(options = {:target_type => nil, :relation_type => nil,
|
137
|
-
:required_attributes => [], :direction => nil})
|
138
|
-
Utils.check_options options,
|
139
|
-
:target_type, :relation_type, :required_attributes, :direction
|
140
|
-
|
141
|
-
target_type = Utils.add_namespace(options[:target_type], NS_REL_1)
|
142
|
-
relation_type = Utils.add_namespace(options[:relation_type], NS_REL_1)
|
143
|
-
required_attributes =
|
144
|
-
options[:required_attributes] ? options[:required_attributes] : []
|
145
|
-
direction = options[:direction]
|
146
|
-
|
147
|
-
# Select all relevant relations depending on the requested target type
|
148
|
-
if target_type
|
149
|
-
result = @relations[target_type].to_a
|
150
|
-
else
|
151
|
-
result = @relations.values.flatten
|
152
|
-
end
|
153
|
-
|
154
|
-
# Filter for direction
|
155
|
-
#
|
156
|
-
result = result.find_all { |r| r.direction == direction } if direction
|
157
|
-
|
158
|
-
# Filter for relation type
|
159
|
-
#
|
160
|
-
result = result.find_all{ |r| r.type == relation_type } if relation_type
|
161
|
-
|
162
|
-
# Filter for attributes
|
163
|
-
#
|
164
|
-
required = required_attributes.map{|a| Utils.add_namespace(a, NS_REL_1)}.to_set
|
165
|
-
result.find_all do |r|
|
166
|
-
required.subset?( r.attributes.to_set )
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
#
|
171
|
-
# Returns a list of target types available for this entity.
|
172
|
-
#
|
173
|
-
# Use this to find out to which types of targets this entity
|
174
|
-
# has relations. If the entity only has relations to tracks and
|
175
|
-
# artists, for example, then a list containg the strings
|
176
|
-
# Relation::TO_TRACK and Relation::TO_ARTIST is returned.
|
177
|
-
#
|
178
|
-
def relation_target_types
|
179
|
-
result = []
|
180
|
-
@relations.each_pair {|type, relations|
|
181
|
-
result << type unless relations.empty?
|
182
|
-
}
|
183
|
-
return result
|
184
|
-
end
|
185
|
-
|
186
86
|
end
|
187
87
|
|
188
88
|
end
|