Package musicbrainz2 :: Module model :: Class Entity
[frames] | no frames]

Class Entity

source code

object --+
         |
        Entity
Known Subclasses:

A first-level MusicBrainz class.

All entities in MusicBrainz have unique IDs (which are absolute URIs) as well as any number of relations to other entities and free text tags. This class is abstract and should not be instantiated.

Relations are differentiated by their target type, that means, where they link to. MusicBrainz currently supports four target types (artists, releases, tracks, and URLs) each identified using a URI. To get all relations with a specific target type, you can use getRelations and pass one of the following constants as the parameter:


See Also: Relation

Instance Methods
 
__init__(self, id_=None)
Constructor.
source code
 
getId(self)
Returns a MusicBrainz ID.
source code
 
setId(self, value)
Sets a MusicBrainz ID.
source code
 
getRelations(self, targetType=None, relationType=None, requiredAttributes=(), direction=None)
Returns a list of relations.
source code
 
getRelationTargets(self, targetType=None, relationType=None, requiredAttributes=(), direction=None)
Returns a list of relation targets.
source code
 
addRelation(self, relation)
Adds a relation.
source code
 
getRelationTargetTypes(self)
Returns a list of target types available for this entity.
source code
 
getTag(self, value)
Return the tag with the given value (aka the tag's name).
source code
 
getTags(self)
Return all tags attached to this Entity.
source code
 
addTag(self, tag)
Add a new tag.
source code
 
getRating(self)
Return the rating of this Entity.
source code
 
setRating(self, value) source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties
  id
The MusicBrainz ID.
  tags
The tags for this entity.
  rating
The rating for this entity.

Inherited from object: __class__

Method Details

__init__(self, id_=None)
(Constructor)

source code 

Constructor.

This should only used by derived classes.

Parameters:
  • id_ - a string containing an absolute URI
Overrides: object.__init__

getId(self)

source code 

Returns a MusicBrainz ID.

Returns:
a string containing a URI, or None

setId(self, value)

source code 

Sets a MusicBrainz ID.

Parameters:
  • value - a string containing an absolute URI

getRelations(self, targetType=None, relationType=None, requiredAttributes=(), direction=None)

source code 

Returns a list of relations.

If targetType is given, only relations of that target type are returned. For MusicBrainz, the following target types are defined:

If targetType is Relation.TO_ARTIST, for example, this method returns all relations between this Entity and artists.

You may use the relationType parameter to further restrict the selection. If it is set, only relations with the given relation type are returned. The requiredAttributes sequence lists attributes that have to be part of all returned relations.

If direction is set, only relations with the given reading direction are returned. You can use the Relation.DIR_FORWARD, Relation.DIR_BACKWARD, and Relation.DIR_NONE constants for this.

Parameters:
  • targetType - a string containing an absolute URI, or None
  • relationType - a string containing an absolute URI, or None
  • requiredAttributes - a sequence containing absolute URIs
  • direction - one of Relation's direction constants
Returns:
a list of Relation objects

See Also: Entity

getRelationTargets(self, targetType=None, relationType=None, requiredAttributes=(), direction=None)

source code 

Returns a list of relation targets.

The arguments work exactly like in getRelations, but instead of Relation objects, the matching relation targets are returned. This can be Artist, Release, or Track objects, depending on the relations.

As a special case, URL strings are returned if the target is an URL.

Parameters:
  • targetType - a string containing an absolute URI, or None
  • relationType - a string containing an absolute URI, or None
  • requiredAttributes - a sequence containing absolute URIs
  • direction - one of Relation's direction constants
Returns:
a list of objects, depending on the relation

See Also: getRelations

addRelation(self, relation)

source code 

Adds a relation.

This method adds relation to the list of relations. The given relation has to be initialized, at least the target type has to be set.

Parameters:

See Also: Entity

getRelationTargetTypes(self)

source code 

Returns a list of target types available for this entity.

Use this to find out to which types of targets this entity has relations. If the entity only has relations to tracks and artists, for example, then a list containg the strings Relation.TO_TRACK and Relation.TO_ARTIST is returned.

Returns:
a list of strings containing URIs

See Also: getRelations

getTag(self, value)

source code 

Return the tag with the given value (aka the tag's name).

Returns:
the Tag with the given name or raises a KeyError

getTags(self)

source code 

Return all tags attached to this Entity.

Returns:
a list of Tag objects

addTag(self, tag)

source code 

Add a new tag.

This merges an existing tag with the same name.

Parameters:
  • tag - the Tag object to add

See Also: getTags

getRating(self)

source code 

Return the rating of this Entity. 0 = Unrated 1 - 5 = Rating

Returns:
rating

Property Details

id

The MusicBrainz ID.

Get Method:
getId(self) - Returns a MusicBrainz ID.
Set Method:
setId(self, value) - Sets a MusicBrainz ID.

tags

The tags for this entity.

Get Method:
getTags(self) - Return all tags attached to this Entity.

rating

The rating for this entity.

Get Method:
getRating(self) - Return the rating of this Entity.