emms-help
[Top][All Lists]
Advanced

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

Re: Default info methods


From: Petteri Hintsanen
Subject: Re: Default info methods
Date: Thu, 11 Mar 2021 21:09:55 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)

"Fran Burstall (Gmail)" <fran.burstall@gmail.com> writes:

> The manual should also explain how to recompute info when a new info method
> is introduced (thus 'emms-cache-rest' followed by
> 'emms-add-directory-tree').  This came up recently on Emacs StackExchange...

Would the attached patch do the job?  It adds a prefix argument to
emms-cache-sync which queues all tracks in the cache for update:

  (emms-cache-sync 1)

It won't clean any info cruft from the cache though, except removed
files.  emms-cache-reset would obviously do that.

Maybe we can later provide a function that would go through
emms-source-file-default-directory and do the right thing: add new
files, remove deleted files and update modified files in the cache.

Another thing is browser refresh.  EMMS playlists get their infos
automatically refreshed (which is nice), but the browser must be
refreshed manually by rebuilding it eg. after emms-cache-sync.

-- 
Petteri

>From 3aaf60567ebefc5aee111e72ee869b16a4c0a713 Mon Sep 17 00:00:00 2001
From: Petteri Hintsanen <petterih@iki.fi>
Date: Thu, 11 Mar 2021 20:53:11 +0200
Subject: [PATCH] Make it possible to force-update Emms cache

Add a prefix argument to emms-cache-sync that will unconditionally
update all tracks in Emms cache.
---
 emms-cache.el | 17 ++++++++---------
 emms-info.el  | 14 +++++++++-----
 2 files changed, 17 insertions(+), 14 deletions(-)

diff --git a/emms-cache.el b/emms-cache.el
index 9b5deb8..8c5e8b3 100644
--- a/emms-cache.el
+++ b/emms-cache.el
@@ -155,12 +155,12 @@ This is used to cache over emacs sessions.")
   (load emms-cache-file t nil t)
   (setq emms-cache-dirty nil))
 
-(defun emms-cache-sync ()
+(defun emms-cache-sync (arg)
   "Sync the cache with the data on disc.
 Remove non-existent files, and update data for files which have
-been modified."
-  (interactive)
-  (message "Syncing emms track cache...")
+been modified.  With prefix argument, update data for all files
+regardless of whether they have been modified or not."
+  (interactive "P")
   (let (removed)
     (maphash (lambda (path track)
                (when (eq (emms-track-get track 'type) 'file)
@@ -172,13 +172,12 @@ been modified."
                    (let ((file-mtime (emms-info-track-file-mtime track))
                          (info-mtime (emms-track-get track 'info-mtime)))
                      (when (or (not info-mtime)
-                               (emms-time-less-p
-                                info-mtime file-mtime))
-                       (run-hook-with-args 'emms-info-functions track))))))
+                               (emms-time-less-p info-mtime file-mtime)
+                               arg)
+                       (emms-info-initialize-track track arg))))))
              emms-cache-db)
     (when removed
-      (setq emms-cache-dirty t)))
-  (message "Syncing emms track cache...done"))
+      (setq emms-cache-dirty t))))
 
 (defun emms-cache-reset ()
   "Reset the cache."
diff --git a/emms-info.el b/emms-info.el
index 9a49a5c..308b2a2 100644
--- a/emms-info.el
+++ b/emms-info.el
@@ -79,15 +79,18 @@ Each is called with a track as argument."
 (defvar emms-info-asynchronous-tracks 0
   "Number of tracks we're waiting for to be done.")
 
-(defun emms-info-initialize-track (track)
+(defun emms-info-initialize-track (track &optional force)
   "Initialize TRACK with emms-info information.
+Update TRACK information if it is new or has been modified since
+last update, or if FORCE is non-nil.
+
 This is a suitable value for `emms-track-initialize-functions'."
   (if (not emms-info-asynchronously)
-      (emms-info-really-initialize-track track)
+      (emms-info-really-initialize-track track force)
     (setq emms-info-asynchronous-tracks (1+ emms-info-asynchronous-tracks))
-    (emms-later-do 'emms-info-really-initialize-track track)))
+    (emms-later-do 'emms-info-really-initialize-track track force)))
 
-(defun emms-info-really-initialize-track (track)
+(defun emms-info-really-initialize-track (track &optional force)
   "Really initialize TRACK.
 Return t when the track got changed."
   (let ((file-mtime (when emms-info-auto-update
@@ -97,7 +100,8 @@ Return t when the track got changed."
     ;; if the file's been modified or is new
     (when (or (not file-mtime)
               (not info-mtime)
-              (emms-time-less-p info-mtime file-mtime))
+              (emms-time-less-p info-mtime file-mtime)
+              force)
       (run-hook-with-args 'emms-info-functions track)
       ;; not set by info functions
       (when file-mtime
-- 
2.20.1


reply via email to

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