Skip to content

Commit 3bc15d7

Browse files
authored
Merge pull request #18 from pinoaffe/add-date
Add date field to albums
2 parents 6fc9855 + 1fe7a6b commit 3bc15d7

File tree

3 files changed

+35
-16
lines changed

3 files changed

+35
-16
lines changed

README.org

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ The library is implemented around a set of entities.
4343
| *Name* | *Type* | *Fields* | *Description* |
4444
|------------------+-----------+----------------------+---------------------------------------------------------|
4545
| song | structure | name, album, file, … | |
46-
| album | structure | name, artist | |
46+
| album | structure | name, date, artist | |
4747
| artist | structure | name | |
4848
| genre | structure | name | |
4949
| directory | structure | name, path | |

libmpdel.el

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
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."

test/libmpdel-test.el

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@
116116
(let ((song (libmpdel--create-song-from-data
117117
'((Title . "The song")
118118
(file . "foo/song.ogg")
119+
(Date . "1952-08-29")
119120
(Album . "The Album")
120121
(Performer . "The Violinist")
121122
(Performer . "The Pianist")
@@ -125,6 +126,8 @@
125126
(should (equal "The song" (libmpdel-entity-name song)))
126127
(should (equal "foo/song.ogg" (libmpdel-song-file song)))
127128
(should (equal (list "The Genre") (mapcar #'libmpdel-entity-name (libmpdel-genres song))))
129+
(should (equal "1952-08-29" (libmpdel-entity-date song)))
130+
(should (equal "1952-08-29" (libmpdel-entity-date (libmpdel-album song))))
128131
(should (equal "The Album" (libmpdel-entity-name (libmpdel-album song))))
129132
(should (equal (list "The Violinist" "The Pianist" "The Singer")
130133
(mapcar #'libmpdel-entity-name (libmpdel-performers song))))

0 commit comments

Comments
 (0)