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
@@ -352,9 +354,16 @@ If the SONG's name is nil, return the filename instead."
352354 " Return the track number of SONG within its album."
353355 (or (libmpdel--song-track song) " " ))
354356
355- (defun libmpdel-entity-date (song )
356- " Return the date of SONG."
357- (or (libmpdel--song-date song) " " ))
357+ (cl-defgeneric libmpdel-entity-date (entity)
358+ " Return the date of ENTITY." )
359+
360+ (cl-defmethod libmpdel-entity-date ((album libmpdel-album))
361+ " Return ALBUM's date."
362+ (libmpdel--album-date album))
363+
364+ (cl-defmethod libmpdel-entity-date ((song libmpdel-song))
365+ " Return SONG's date."
366+ (libmpdel--song-date song))
358367
359368(defun libmpdel-song-disc (song )
360369 " Return the disc number of SONG within its album."
@@ -390,9 +399,7 @@ If the SONG's name is nil, return the filename instead."
390399 :file (cdr (assq 'file song-data))
391400 :performers (libmpdel--artists-create (libmpdel-entries song-data 'Performer ))
392401 :genres (libmpdel--genres-create (libmpdel-entries song-data 'Genre ))
393- :album (libmpdel--album-create
394- :name (cdr (assq 'Album song-data))
395- :artist (libmpdel--artist-create :name (cdr (assq 'Artist song-data))))
402+ :album (libmpdel--create-album-from-data song-data)
396403 :date (cdr (assq 'Date song-data))
397404 :disc (cdr (assq 'Disc song-data))
398405 :id (cdr (assq 'Id song-data))
@@ -402,6 +409,17 @@ If the SONG's name is nil, return the filename instead."
402409 " Return a list of songs from DATA, a server's response."
403410 (mapcar #'libmpdel--create-song-from-data (libmpdel-group-data data)))
404411
412+ (defun libmpdel--create-album-from-data (song-data )
413+ " Return an album from SONG-DATA, a server's response."
414+ (libmpdel--album-create
415+ :name (cdr (assq 'Album song-data))
416+ :date (cdr (assq 'Date song-data))
417+ :artist (libmpdel--artist-create :name (cdr (assq 'Artist song-data)))))
418+
419+ (defun libmpdel--create-albums-from-data (data )
420+ " Return a list of albums from DATA, a server's response."
421+ (mapcar #'libmpdel--create-album-from-data (libmpdel-group-data data)))
422+
405423(defun libmpdel-current-playlist-p (entity )
406424 " Return non-nil if ENTITY is the current playlist."
407425 (eq entity 'current-playlist ))
@@ -1003,11 +1021,9 @@ If HANDLER is nil, ignore response."
10031021 " list album"
10041022 (lambda (data )
10051023 (funcall function
1006- (mapcar
1007- (lambda (album-name )
1008- (libmpdel--album-create :name album-name
1009- :artist libmpdel--unknown-artist))
1010- (libmpdel-sorted-entries data 'Album ))))))
1024+ (seq-uniq
1025+ (libmpdel--create-albums-from-data data)
1026+ #'libmpdel-equal )))))
10111027
10121028(cl-defmethod libmpdel-list ((_entity (eql genres)) function)
10131029 " Call FUNCTION with all genres as parameter."
@@ -1033,12 +1049,12 @@ If HANDLER is nil, ignore response."
10331049(cl-defmethod libmpdel-list ((artist libmpdel-artist) function)
10341050 " Call FUNCTION with all albums of ARTIST as parameter."
10351051 (libmpdel-send-command
1036- `(" list album %s " ,(libmpdel-entity-to-criteria artist))
1052+ `(" find %s sort AlbumSort " ,(libmpdel-entity-to-criteria artist))
10371053 (lambda (data )
10381054 (funcall function
1039- (mapcar
1040- (lambda ( album-name ) ( libmpdel--album- create :name album-name :artist artist) )
1041- ( libmpdel-sorted-entries data 'Album ) )))))
1055+ (seq-uniq
1056+ (libmpdel--create-albums-from-data data )
1057+ # ' libmpdel-equal )))))
10421058
10431059(cl-defgeneric libmpdel-list-songs (entity function)
10441060 " Call FUNCTION with all songs of ENTITY."
0 commit comments