Skip to content

Commit

Permalink
Add model for artists
Browse files Browse the repository at this point in the history
Refs: #143
  • Loading branch information
orontee committed Jul 12, 2023
1 parent ab9a13e commit a84c802
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 2 deletions.
24 changes: 22 additions & 2 deletions argos/controllers/helper.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from collections import defaultdict
from typing import Callable, Dict, List, Mapping, Optional, Sequence

from argos.dto import ArtistDTO, TlTrackDTO, TrackDTO
from argos.model import TracklistTrackModel, TrackModel
from argos.dto import AlbumDTO, ArtistDTO, TlTrackDTO, TrackDTO
from argos.model import AlbumModel, ArtistModel, TracklistTrackModel, TrackModel


class ModelHelper:
Expand All @@ -12,6 +12,26 @@ class ModelHelper:
"""

def convert_album(self, album_dto: AlbumDTO) -> AlbumModel:
album = AlbumModel(
uri=album_dto.uri,
name=album_dto.name,
num_tracks=album_dto.num_tracks,
num_discs=album_dto.num_discs,
date=album_dto.date,
)
# TODO album dto has artists
return album

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 a84c802

Please sign in to comment.