Skip to content

Commit

Permalink
Add model for artists
Browse files Browse the repository at this point in the history
Refs: #124
  • Loading branch information
orontee committed May 1, 2023
1 parent 3a4bada commit 6444629
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
11 changes: 10 additions & 1 deletion argos/controllers/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions argos/model/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -17,6 +18,7 @@

__all__ = (
"AlbumModel",
"ArtistModel",
"DirectoryModel",
"LibraryModel",
"MixerModel",
Expand Down
43 changes: 43 additions & 0 deletions argos/model/artist.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 6444629

Please sign in to comment.