emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/listen 2cf52c87fe 16/16: Add: (listen-queue-deduplicate


From: ELPA Syncer
Subject: [elpa] externals/listen 2cf52c87fe 16/16: Add: (listen-queue-deduplicate)
Date: Thu, 29 Feb 2024 06:58:31 -0500 (EST)

branch: externals/listen
commit 2cf52c87fe5d1b68f987c8ad8af810b948f01a82
Author: Adam Porter <adam@alphapapa.net>
Commit: Adam Porter <adam@alphapapa.net>

    Add: (listen-queue-deduplicate)
---
 README.org      |  3 ++-
 listen-queue.el | 28 ++++++++++++++++++++++++++++
 listen.el       |  2 ++
 3 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/README.org b/README.org
index 8a7de82136..2d408c52e5 100644
--- a/README.org
+++ b/README.org
@@ -67,7 +67,8 @@ Use the command ~listen~ to show the Transient menu.  From 
there, it is--hopeful
 
 ** v0.4-pre
 
-Nothing new yet.
+*Additions*
++ Command ~listen-queue-deduplicate~ removes duplicate tracks from a queue (by 
comparing artist, album, and title metadata case-insensitively).
 
 ** v0.3
 
diff --git a/listen-queue.el b/listen-queue.el
index bfcf20fc53..6313ae94f0 100644
--- a/listen-queue.el
+++ b/listen-queue.el
@@ -390,6 +390,34 @@ buffer, if any)."
     (setf (listen-queue-tracks queue) tracks))
   (listen-queue--update-buffer queue))
 
+(cl-defun listen-queue-deduplicate (queue)
+  "Remove duplicate tracks from QUEUE.
+Tracks that appear to have the same metadata (artist, album, and
+title, compared case-insensitively) are deduplicated."
+  (interactive (list (listen-queue-complete)))
+  (setf (listen-queue-tracks queue)
+        (cl-remove-duplicates
+         (listen-queue-tracks queue)
+         :test (lambda (a b)
+                 (pcase-let ((( cl-struct listen-track
+                                (artist a-artist) (album a-album) (title 
a-title)) a)
+                             (( cl-struct listen-track
+                                (artist b-artist) (album b-album) (title 
b-title)) b))
+                   (and (or (and a-artist b-artist)
+                            (and a-album b-album)
+                            (and a-title b-title))
+                        ;; Tracks have at least one common metadata field: 
compare them.
+                        (if (and a-artist b-artist)
+                            (string-equal-ignore-case a-artist b-artist)
+                          t)
+                        (if (and a-album b-album)
+                            (string-equal-ignore-case a-album b-album)
+                          t)
+                        (if (and a-title b-title)
+                            (string-equal-ignore-case a-title b-title)
+                          t))))))
+  (listen-queue--update-buffer queue))
+
 (defun listen-queue-next (queue)
   "Play next track in QUEUE."
   (interactive (list (listen-queue-complete)))
diff --git a/listen.el b/listen.el
index b563dd4d9a..0b67a85ef0 100755
--- a/listen.el
+++ b/listen.el
@@ -348,6 +348,8 @@ TIME is a string like \"SS\", \"MM:SS\", or \"HH:MM:SS\"."
                          (let ((current-prefix-arg '(4)))
                            (call-interactively #'listen-queue-play)))
      :transient t)
+    ("qd" "Deduplicate" listen-queue-deduplicate
+     :transient t)
     ("qs" "Shuffle" (lambda ()
                       "Shuffle queue."
                       (interactive)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]