Data models
These immutable data models are used for all data transfer inbetween the backend, core, and frontend layers, as described in the architecture.
Relationships
---
config:
class:
hideEmptyMembersBox: true
---
classDiagram
direction TB
class Ref
class Album
class Artist
class Directory
class Image
class Playlist
class TlTrack
class Track
class SearchResult
Ref ..> "0..1" Directory
Ref ..> "0..1" Artist
Ref ..> "0..1" Track
Ref ..> "0..1" Album
Ref ..> "0..1" Playlist
Album --> "0..*" Artist
Album --> "0..*" Track
Playlist --> "0..*" Track
Track --> "0..1" Album
Track --> "0..*" Artist
TlTrack --> "1" Track
SearchResult --> "*" Track
SearchResult --> "*" Artist
SearchResult --> "*" Album
Immutability
All fields are type checked and immutable. In other words, they can only be set through the class constructor during instance creation.
If you want to modify a model, use the model.replace() method to
create a copy of the model with the desired modifications. It accepts keyword
arguments for the parts of the model you want to change, and copies the rest of
the data from the model you call it on. Example:
>>> from mopidy.models import Track
>>> track1 = Track(uri='an-uri', name='Christmas Carol', length=171)
>>> track1
Track(uri='an-uri', name='Christmas Carol', artists=frozenset(), album=None,
composers=frozenset(), performers=frozenset(), genre=None, track_no=None,
disc_no=None, date=None, length=171, bitrate=None, comment=None,
musicbrainz_id=None, last_modified=None)
>>> track2 = track1.replace(length=37)
>>> track2
Track(uri='an-uri', name='Christmas Carol', artists=frozenset(), album=None,
composers=frozenset(), performers=frozenset(), genre=None, track_no=None,
disc_no=None, date=None, length=37, bitrate=None, comment=None,
musicbrainz_id=None, last_modified=None)
mopidy.models
Classes:
-
Album–An album.
-
Artist–An artist.
-
Image–An image with a URI and dimensions.
-
ModelType–Enumeration of model types.
-
Playlist–A playlist.
-
Ref–Model to represent URI references with a human friendly name and type.
-
SearchResult–A search result.
-
TlTrack–A tracklist track. Wraps a regular track and it's tracklist ID.
-
Track–An audio track.
Album
Bases: BaseModel
An album.
Methods:
Attributes:
-
artists(frozenset[Artist]) –A set of album artists.
-
date(DateOrYear | None) –The album release date. A string formatted as "YYYY" or "YYYY-MM-DD".
-
musicbrainz_id(UUID | None) –The MusicBrainz ID of the album.
-
name(str | None) –The album name.
-
num_discs(NonNegativeInt | None) –The number of discs in the album.
-
num_tracks(NonNegativeInt | None) –The number of tracks in the album.
-
uri(Uri | None) –The album URI.
artists
class-attribute
instance-attribute
A set of album artists.
date
class-attribute
instance-attribute
date: DateOrYear | None = Field(
default=None, pattern="^\\d{4}(-\\d{2}-\\d{2})?$"
)
The album release date. A string formatted as "YYYY" or "YYYY-MM-DD".
musicbrainz_id
class-attribute
instance-attribute
musicbrainz_id: UUID | None = None
The MusicBrainz ID of the album.
num_discs
class-attribute
instance-attribute
num_discs: NonNegativeInt | None = None
The number of discs in the album.
num_tracks
class-attribute
instance-attribute
num_tracks: NonNegativeInt | None = None
The number of tracks in the album.
Artist
Bases: BaseModel
An artist.
Methods:
Attributes:
Image
Bases: BaseModel
An image with a URI and dimensions.
Methods:
Attributes:
-
height(NonNegativeInt | None) –Height of the image in pixels.
-
uri(Uri) –The image URI.
-
width(NonNegativeInt | None) –Width of the image in pixels.
height
class-attribute
instance-attribute
height: NonNegativeInt | None = None
Height of the image in pixels.
width
class-attribute
instance-attribute
width: NonNegativeInt | None = None
Width of the image in pixels.
ModelType
Bases: StrEnum
Enumeration of model types.
Attributes:
-
ALBUM–An album.
-
ARTIST–An artist.
-
DIRECTORY–A directory.
-
PLAYLIST–A playlist.
-
TRACK–A track.
ALBUM
class-attribute
instance-attribute
ALBUM = 'album'
An album.
ARTIST
class-attribute
instance-attribute
ARTIST = 'artist'
An artist.
DIRECTORY
class-attribute
instance-attribute
DIRECTORY = 'directory'
A directory.
PLAYLIST
class-attribute
instance-attribute
PLAYLIST = 'playlist'
A playlist.
TRACK
class-attribute
instance-attribute
TRACK = 'track'
A track.
Playlist
Bases: BaseModel
A playlist.
Methods:
Attributes:
-
last_modified(NonNegativeInt | None) –The playlist modification time in milliseconds since Unix epoch.
-
length(NonNegativeInt) –The number of tracks in the playlist.
-
name(str | None) –The playlist name.
-
tracks(tuple[Track, ...]) –The playlist's tracks.
-
uri(Uri) –The playlist URI.
last_modified
class-attribute
instance-attribute
last_modified: NonNegativeInt | None = None
The playlist modification time in milliseconds since Unix epoch.
length
property
length: NonNegativeInt
The number of tracks in the playlist.
Ref
Bases: BaseModel
Model to represent URI references with a human friendly name and type.
This is intended for use a lightweight object "free" of metadata that can be passed around instead of using full blown models.
Methods:
-
album–Create a Ref with type ALBUM.
-
artist–Create a Ref with type ARTIST.
-
directory–Create a Ref with type DIRECTORY.
-
playlist–Create a Ref with type PLAYLIST.
-
replace–Return a new instance with updated fields.
-
serialize–Serialize the model to a dict.
-
track–Create a Ref with type TRACK.
Attributes:
SearchResult
Bases: BaseModel
A search result.
Methods:
Attributes:
-
albums(tuple[Album, ...]) –The albums matching the search query.
-
artists(tuple[Artist, ...]) –The artists matching the search query.
-
tracks(tuple[Track, ...]) –The tracks matching the search query.
-
uri(Uri | None) –The search result URI.
albums
class-attribute
instance-attribute
The albums matching the search query.
artists
class-attribute
instance-attribute
The artists matching the search query.
tracks
class-attribute
instance-attribute
The tracks matching the search query.
TlTrack
TlTrack(tlid: TracklistId, track: Track, **_: Any)
Bases: BaseModel
A tracklist track. Wraps a regular track and it's tracklist ID.
The use of TlTrack allows the same track to appear multiple times in the tracklist.
This class also accepts it's parameters as positional arguments. Both arguments must be provided, and they must appear in the order they are listed here.
This class also supports iteration, so you can extract its values like this:
(tlid, track) = tl_track
Methods:
Attributes:
-
tlid(TracklistId) –The tracklist ID.
-
track(Track) –The track.
Track
Bases: BaseModel
An audio track.
Methods:
Attributes:
-
album(Album | None) –The track album.
-
artists(frozenset[Artist]) –A set of track artists.
-
bitrate(NonNegativeInt | None) –The track's bitrate in kbit/s.
-
comment(str | None) –The track comment.
-
composers(frozenset[Artist]) –A set of track composers.
-
date(DateOrYear | None) –The track release date. A string formatted as "YYYY" or "YYYY-MM-DD".
-
disc_no(NonNegativeInt | None) –The disc number in the album.
-
genre(str | None) –The track genre.
-
last_modified(NonNegativeInt | None) –Integer representing when the track was last modified.
-
length(DurationMs | None) –The track length in milliseconds.
-
musicbrainz_id(UUID | None) –The MusicBrainz ID of the track.
-
name(str | None) –The track name.
-
performers(frozenset[Artist]) –A set of track performers.
-
track_no(NonNegativeInt | None) –The track number in the album.
-
uri(Uri) –The track URI.
artists
class-attribute
instance-attribute
A set of track artists.
bitrate
class-attribute
instance-attribute
bitrate: NonNegativeInt | None = None
The track's bitrate in kbit/s.
composers
class-attribute
instance-attribute
A set of track composers.
date
class-attribute
instance-attribute
date: DateOrYear | None = Field(
default=None, pattern="^\\d{4}(-\\d{2}-\\d{2})?$"
)
The track release date. A string formatted as "YYYY" or "YYYY-MM-DD".
disc_no
class-attribute
instance-attribute
disc_no: NonNegativeInt | None = None
The disc number in the album.
last_modified
class-attribute
instance-attribute
last_modified: NonNegativeInt | None = None
Integer representing when the track was last modified.
Exact meaning depends on source of track. For local files this is the modification time in milliseconds since Unix epoch. For other backends it could be an equivalent timestamp or simply a version counter.
length
class-attribute
instance-attribute
length: DurationMs | None = None
The track length in milliseconds.
musicbrainz_id
class-attribute
instance-attribute
musicbrainz_id: UUID | None = None
The MusicBrainz ID of the track.
performers
class-attribute
instance-attribute
A set of track performers.
track_no
class-attribute
instance-attribute
track_no: NonNegativeInt | None = None
The track number in the album.