3333(require 'tq )
3434(require 'cl-lib )
3535(require 'subr-x )
36+ (require 'seq )
3637
3738
3839; ;; Customization
@@ -171,6 +172,7 @@ message from the server.")
171172 (:constructor libmpdel--album-create)
172173 (:conc-name libmpdel--album-))
173174 (name nil :read-only t )
175+ (date nil :read-only t )
174176 (artist nil :read-only t ))
175177
176178(cl-defstruct (libmpdel-song
@@ -321,9 +323,16 @@ If the SONG's name is nil, return the filename instead."
321323 " Return the track number of SONG within its album."
322324 (or (libmpdel--song-track song) " " ))
323325
324- (defun libmpdel-entity-date (song )
325- " Return the date of SONG."
326- (or (libmpdel--song-date song) " " ))
326+ (cl-defgeneric libmpdel-entity-date (entity)
327+ " Return the date of ENTITY." )
328+
329+ (cl-defmethod libmpdel-entity-date ((album libmpdel-album))
330+ " Return ALBUM's date."
331+ (libmpdel--album-date album))
332+
333+ (cl-defmethod libmpdel-entity-date ((song libmpdel-song))
334+ " Return SONG's date."
335+ (libmpdel--song-date song))
327336
328337(defun libmpdel-song-disc (song )
329338 " Return the disc number of SONG within its album."
@@ -345,9 +354,7 @@ If the SONG's name is nil, return the filename instead."
345354 :name (cdr (assq 'Title song-data))
346355 :track (cdr (assq 'Track song-data))
347356 :file (cdr (assq 'file song-data))
348- :album (libmpdel--album-create
349- :name (cdr (assq 'Album song-data))
350- :artist (libmpdel--artist-create :name (cdr (assq 'Artist song-data))))
357+ :album (libmpdel--create-album-from-data song-data)
351358 :date (cdr (assq 'Date song-data))
352359 :disc (cdr (assq 'Disc song-data))
353360 :id (cdr (assq 'Id song-data))
@@ -357,6 +364,17 @@ If the SONG's name is nil, return the filename instead."
357364 " Return a list of songs from DATA, a server's response."
358365 (mapcar #'libmpdel--create-song-from-data (libmpdel-group-data data)))
359366
367+ (defun libmpdel--create-album-from-data (song-data )
368+ " Return an album from ALBUM-DATA, a server's response."
369+ (libmpdel--album-create
370+ :name (cdr (assq 'Album song-data))
371+ :date (cdr (assq 'Date song-data))
372+ :artist (libmpdel--artist-create :name (cdr (assq 'Artist song-data)))))
373+
374+ (defun libmpdel--create-albums-from-data (data )
375+ " Return a list of albums from DATA, a server's response."
376+ (mapcar #'libmpdel--create-album-from-data (libmpdel-group-data data)))
377+
360378(defun libmpdel-current-playlist-p (entity )
361379 " Return non-nil if ENTITY is the current playlist."
362380 (eq entity 'current-playlist ))
@@ -953,11 +971,9 @@ If HANDLER is nil, ignore response."
953971 " list album"
954972 (lambda (data )
955973 (funcall function
956- (mapcar
957- (lambda (album-name )
958- (libmpdel--album-create :name album-name
959- :artist libmpdel--unknown-artist))
960- (libmpdel-sorted-entries data 'Album ))))))
974+ (seq-uniq
975+ (libmpdel--create-albums-from-data data)
976+ #'libmpdel-equal )))))
961977
962978(cl-defmethod libmpdel-list ((_entity (eql stored-playlists)) function)
963979 " Call FUNCTION with all stored playlists as parameter."
@@ -972,12 +988,12 @@ If HANDLER is nil, ignore response."
972988(cl-defmethod libmpdel-list ((artist libmpdel-artist) function)
973989 " Call FUNCTION with all albums of ARTIST as parameter."
974990 (libmpdel-send-command
975- `(" list album %s " ,(libmpdel-entity-to-criteria artist))
991+ `(" find %s sort AlbumSort " ,(libmpdel-entity-to-criteria artist))
976992 (lambda (data )
977993 (funcall function
978- (mapcar
979- (lambda ( album-name ) ( libmpdel--album- create :name album-name :artist artist) )
980- ( libmpdel-sorted-entries data 'Album ) )))))
994+ (seq-uniq
995+ (libmpdel--create-albums-from-data data )
996+ # ' libmpdel-equal )))))
981997
982998(cl-defgeneric libmpdel-list-songs (entity function)
983999 " Call FUNCTION with all songs of ENTITY."
0 commit comments