diff options
author | JSDurand <mmemmew@gmail.com> | 2021-09-02 15:35:18 +0800 |
---|---|---|
committer | JSDurand <mmemmew@gmail.com> | 2021-09-02 15:35:18 +0800 |
commit | ad509f2fc3dbbe7303887a55d9a69140a8887857 (patch) | |
tree | 28f01620d205e87a13074eba203862b1bcd513a8 /bongo.el | |
parent | b516b2c4ba117e259f2eace4e38edaf35eb1df3a (diff) |
bongo: bulk replace song names in playlists
* bongo.el (durand-bongo-replace-name-in-playlist-files): When I moved
some songs to sub-directories, I would like to quickly change the song
names in the playlist files quickly, otherwise when playing songs from
the playlists, they will become broken links. This function provides
exactly this functionality. For the usage see the documentation of
this function.
Diffstat (limited to 'bongo.el')
-rw-r--r-- | bongo.el | 59 |
1 files changed, 39 insertions, 20 deletions
@@ -186,26 +186,7 @@ Adapted from Protesilaos' dotemacs by Durand." (playlist (directory-files path t dotless))) (with-bongo-playlist-buffer (bongo-insert-playlist-contents - (completing-read "Select playlist: " playlist nil t path)) - ;; (ivy-read "Choose a playlist file: " playlist - ;; :require-match t - ;; :caller 'durand-bongo-insert-delete-playlist - ;; :action '(1 - ;; ("i" bongo-insert-playlist-contents "insert playlist") - ;; ("d" (lambda (file) - ;; (delete-file file) - ;; (setf (ivy-state-collection ivy-last) - ;; (directory-files - ;; (file-name-as-directory - ;; (expand-file-name - ;; "playlists" - ;; bongo-default-directory)) - ;; t directory-files-no-dot-files-regexp)) - ;; (ivy--reset-state ivy-last)) - ;; "delete playlist") - ;; ("e" find-file "edit"))) - ;; (prot/bongo-play-random) - ))) + (completing-read "Select playlist: " playlist nil t path))))) ;;;###autoload ;; (defun durand-bongo-dired-ivy-find-to-add () @@ -714,6 +695,44 @@ Afterwards just stop the annoying timer." 'mpv)) (durand-bongo-seek-start-timer bongo-player))))) +;;; replace names in playlist files + +(defun durand-bongo-replace-name-in-playlist-files (old new) + "Replace names in the playlist files containing OLD by the name in \ +NEW subdirectory. +If one moves songs containing the string NAME to the subdirectory +NAME in its original directory, where NAME is the name of the +singer, then running this function with parameters both equal to NAME +will do the right renaming." + (interactive "sOld name: \nsNew name: ") + (let ((files (directory-files + (expand-file-name + "playlists" bongo-default-directory) + nil "m3u$" t))) + (mapc + (lambda (file) + (with-temp-buffer + (insert-file-contents file) + (goto-char (point-min)) + (cond + ((save-excursion (re-search-forward old nil t)) + (while (re-search-forward old nil t) + (let* ((file-name + (buffer-substring-no-properties + (line-beginning-position) (line-end-position))) + (expanded + (expand-file-name + (file-name-nondirectory file-name) + (expand-file-name + new (file-name-directory file-name)))) + (po (line-beginning-position))) + (delete-region (line-beginning-position) (line-end-position)) + (goto-char po) + (insert expanded) + (goto-char (+ po (length expanded))))) + (write-region nil nil file))))) + files))) + ;; Normally we should do this, but I override the function by my ;; custom function, so I can just call this function there. |