From ad3a9a846887463769e6062e91c955167b05e6e0 Mon Sep 17 00:00:00 2001 From: pinoaffe Date: Fri, 30 May 2025 09:10:26 +0200 Subject: [PATCH] Add performers field to songs --- libmpdel.el | 12 ++++++++++++ test/libmpdel-test.el | 5 +++++ 2 files changed, 17 insertions(+) diff --git a/libmpdel.el b/libmpdel.el index 5db54ba..f2601fb 100644 --- a/libmpdel.el +++ b/libmpdel.el @@ -180,6 +180,7 @@ message from the server.") (track nil :read-only t) (file nil :read-only t) (album nil :read-only t) + (performers nil :read-only t) (disc nil :read-only t) (date nil :read-only t) (id nil :read-only t) @@ -235,6 +236,10 @@ message from the server.") "Return SONG's album." (libmpdel--song-album song)) +(cl-defmethod libmpdel-performers ((song libmpdel-song)) + "Return SONG's performers." + (libmpdel--song-performers song)) + (cl-defgeneric libmpdel-entity-name (entity) "Return the name of ENTITY.") @@ -339,12 +344,19 @@ If the SONG's name is nil, return the filename instead." (when (and (stringp pos) (not (string= pos ""))) (string-to-number pos)))) +(defun libmpdel--artists-create (artist-names) + "Return a list of artists whose names are ARTIST-NAMES." + (mapcar (lambda (name) + (libmpdel--artist-create :name name)) + artist-names)) + (defun libmpdel--create-song-from-data (song-data) "Return a song from SONG-DATA, a server's response." (libmpdel--song-create :name (cdr (assq 'Title song-data)) :track (cdr (assq 'Track song-data)) :file (cdr (assq 'file song-data)) + :performers (libmpdel--artists-create (libmpdel-entries song-data 'Performer)) :album (libmpdel--album-create :name (cdr (assq 'Album song-data)) :artist (libmpdel--artist-create :name (cdr (assq 'Artist song-data)))) diff --git a/test/libmpdel-test.el b/test/libmpdel-test.el index 0edad04..4f23b0a 100644 --- a/test/libmpdel-test.el +++ b/test/libmpdel-test.el @@ -117,10 +117,15 @@ '((Title . "The song") (file . "foo/song.ogg") (Album . "The Album") + (Performer . "The Violinist") + (Performer . "The Pianist") + (Performer . "The Singer") (Artist . "The Artist"))))) (should (equal "The song" (libmpdel-entity-name song))) (should (equal "foo/song.ogg" (libmpdel-song-file song))) (should (equal "The Album" (libmpdel-entity-name (libmpdel-album song)))) + (should (equal (list "The Violinist" "The Pianist" "The Singer") + (mapcar #'libmpdel-entity-name (libmpdel-performers song)))) (should (equal "The Artist" (libmpdel-entity-name (libmpdel-artist (libmpdel-album song))))))) (ert-deftest libmpdel-test-current-playlist-p ()