-
Notifications
You must be signed in to change notification settings - Fork 6
Add date field to albums #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,7 @@ | |
| (require 'tq) | ||
| (require 'cl-lib) | ||
| (require 'subr-x) | ||
| (require 'seq) | ||
|
|
||
|
|
||
| ;;; Customization | ||
|
|
@@ -171,6 +172,7 @@ message from the server.") | |
| (:constructor libmpdel--album-create) | ||
| (:conc-name libmpdel--album-)) | ||
| (name nil :read-only t) | ||
| (date nil :read-only t) | ||
| (artist nil :read-only t)) | ||
|
|
||
| (cl-defstruct (libmpdel-song | ||
|
|
@@ -352,9 +354,16 @@ If the SONG's name is nil, return the filename instead." | |
| "Return the track number of SONG within its album." | ||
| (or (libmpdel--song-track song) "")) | ||
|
|
||
| (defun libmpdel-entity-date (song) | ||
| "Return the date of SONG." | ||
| (or (libmpdel--song-date song) "")) | ||
| (cl-defgeneric libmpdel-entity-date (entity) | ||
| "Return the date of ENTITY.") | ||
|
|
||
| (cl-defmethod libmpdel-entity-date ((album libmpdel-album)) | ||
| "Return ALBUM's date." | ||
| (libmpdel--album-date album)) | ||
|
|
||
| (cl-defmethod libmpdel-entity-date ((song libmpdel-song)) | ||
| "Return SONG's date." | ||
| (libmpdel--song-date song)) | ||
|
|
||
| (defun libmpdel-song-disc (song) | ||
| "Return the disc number of SONG within its album." | ||
|
|
@@ -390,9 +399,7 @@ If the SONG's name is nil, return the filename instead." | |
| :file (cdr (assq 'file song-data)) | ||
| :performers (libmpdel--artists-create (libmpdel-entries song-data 'Performer)) | ||
| :genres (libmpdel--genres-create (libmpdel-entries song-data 'Genre)) | ||
| :album (libmpdel--album-create | ||
| :name (cdr (assq 'Album song-data)) | ||
| :artist (libmpdel--artist-create :name (cdr (assq 'Artist song-data)))) | ||
| :album (libmpdel--create-album-from-data song-data) | ||
| :date (cdr (assq 'Date song-data)) | ||
| :disc (cdr (assq 'Disc song-data)) | ||
| :id (cdr (assq 'Id song-data)) | ||
|
|
@@ -402,6 +409,17 @@ If the SONG's name is nil, return the filename instead." | |
| "Return a list of songs from DATA, a server's response." | ||
| (mapcar #'libmpdel--create-song-from-data (libmpdel-group-data data))) | ||
|
|
||
| (defun libmpdel--create-album-from-data (song-data) | ||
| "Return an album from SONG-DATA, a server's response." | ||
| (libmpdel--album-create | ||
| :name (cdr (assq 'Album song-data)) | ||
| :date (cdr (assq 'Date song-data)) | ||
| :artist (libmpdel--artist-create :name (cdr (assq 'Artist song-data))))) | ||
|
|
||
| (defun libmpdel--create-albums-from-data (data) | ||
| "Return a list of albums from DATA, a server's response." | ||
| (mapcar #'libmpdel--create-album-from-data (libmpdel-group-data data))) | ||
|
|
||
| (defun libmpdel-current-playlist-p (entity) | ||
| "Return non-nil if ENTITY is the current playlist." | ||
| (eq entity 'current-playlist)) | ||
|
|
@@ -1003,11 +1021,9 @@ If HANDLER is nil, ignore response." | |
| "list album" | ||
| (lambda (data) | ||
| (funcall function | ||
| (mapcar | ||
| (lambda (album-name) | ||
| (libmpdel--album-create :name album-name | ||
| :artist libmpdel--unknown-artist)) | ||
| (libmpdel-sorted-entries data 'Album)))))) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. before we merge this PR, it would be good to have a PR ready to be merged that introduce sorting back into the UI.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. based on my tests, the output of |
||
| (seq-uniq | ||
DamienCassou marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| (libmpdel--create-albums-from-data data) | ||
| #'libmpdel-equal))))) | ||
|
|
||
| (cl-defmethod libmpdel-list ((_entity (eql genres)) function) | ||
| "Call FUNCTION with all genres as parameter." | ||
|
|
@@ -1033,12 +1049,12 @@ If HANDLER is nil, ignore response." | |
| (cl-defmethod libmpdel-list ((artist libmpdel-artist) function) | ||
| "Call FUNCTION with all albums of ARTIST as parameter." | ||
| (libmpdel-send-command | ||
| `("list album %s" ,(libmpdel-entity-to-criteria artist)) | ||
| `("find %s sort AlbumSort" ,(libmpdel-entity-to-criteria artist)) | ||
DamienCassou marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| (lambda (data) | ||
| (funcall function | ||
| (mapcar | ||
| (lambda (album-name) (libmpdel--album-create :name album-name :artist artist)) | ||
| (libmpdel-sorted-entries data 'Album)))))) | ||
| (seq-uniq | ||
| (libmpdel--create-albums-from-data data) | ||
| #'libmpdel-equal))))) | ||
|
|
||
| (cl-defgeneric libmpdel-list-songs (entity function) | ||
| "Call FUNCTION with all songs of ENTITY." | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems unrelated to "Add date field to albums". Can we keep that for another PR? I will better understand the goal this way and we can merge this one sooner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is technically unrelated to the field itself, but imo intimately related to the code: adding date fields to albums (and populating those fields with dates) means that the exact same album-creation-code would have to be duplicated in three separate places, to prevent that I factored said code into a function
(especially since in the next PR I'll add even more code to
libmpdel--create-album-from-data, which would otherwise also have to be copied identically to three different places)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand, thank you