From 64446299aa25fc3faab1655c1a474959d529031f Mon Sep 17 00:00:00 2001 From: Matthias Meulien Date: Mon, 1 May 2023 22:11:27 +0200 Subject: [PATCH] Add model for artists Refs: #124 --- argos/controllers/helper.py | 11 +++++++++- argos/model/__init__.py | 2 ++ argos/model/artist.py | 43 +++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 argos/model/artist.py diff --git a/argos/controllers/helper.py b/argos/controllers/helper.py index f7a234c..440769e 100644 --- a/argos/controllers/helper.py +++ b/argos/controllers/helper.py @@ -2,7 +2,7 @@ from typing import Callable, Dict, List, Mapping, Optional, Sequence from argos.dto import ArtistDTO, TlTrackDTO, TrackDTO -from argos.model import TracklistTrackModel, TrackModel +from argos.model import ArtistModel, TracklistTrackModel, TrackModel class ModelHelper: @@ -12,6 +12,15 @@ class ModelHelper: """ + def convert_artist(self, artist_dto: ArtistDTO) -> ArtistModel: + artist = ArtistModel( + uri=artist_dto.uri, + name=artist_dto.name, + sortname=artist_dto.name, + artist_mbid=artist_dto.musicbrainz_id, + ) + return artist + def convert_track(self, track_dto: TrackDTO) -> TrackModel: track = TrackModel( uri=track_dto.uri, diff --git a/argos/model/__init__.py b/argos/model/__init__.py index 2d9db3a..ccae710 100644 --- a/argos/model/__init__.py +++ b/argos/model/__init__.py @@ -1,4 +1,5 @@ from argos.model.album import AlbumModel +from argos.model.artist import ArtistModel from argos.model.backends import MopidyBackend from argos.model.directory import DirectoryModel from argos.model.library import LibraryModel @@ -17,6 +18,7 @@ __all__ = ( "AlbumModel", + "ArtistModel", "DirectoryModel", "LibraryModel", "MixerModel", diff --git a/argos/model/artist.py b/argos/model/artist.py new file mode 100644 index 0000000..3961433 --- /dev/null +++ b/argos/model/artist.py @@ -0,0 +1,43 @@ +import locale + +from gi.repository import GObject + + +def compare_artist_by_name_func( + a: "ArtistModel", + b: "ArtistModel", + user_data: None, +) -> int: + names_comp = locale.strcoll(a.sortname, b.sortname) + if names_comp != 0: + return names_comp + + names_comp = locale.strcoll(a.name, b.name) + if names_comp != 0: + return names_comp + + if a.uri < b.uri: + return -1 + elif a.uri > b.uri: + return 1 + + return 0 + + +class ArtistInformationModel(GObject.Object): + """Model for artist information.""" + + abstract = GObject.Property(type=str) + last_modified = GObject.Property(type=GObject.TYPE_DOUBLE, default=-1) + + +class ArtistModel(GObject.Object): + """Model for an artist.""" + + uri = GObject.Property(type=str) + name = GObject.Property(type=str) + sortname = GObject.Property(type=str) + image_path = GObject.Property(type=str) + image_uri = GObject.Property(type=str) + artist_mbid = GObject.Property(type=str) + information = GObject.Property(type=ArtistInformationModel)