From bd0ea189aa0751a6c342c7a0b8a6f5265090388e Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Wed, 12 Nov 2025 22:42:31 -0600 Subject: fix: Write relative paths to M3U playlists instead of absolute MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changed cj/music--append-track-to-m3u-file to convert absolute paths to relative paths from cj/music-root before writing to M3U files. This fixes playlist loading in Mopidy, which expects relative paths in M3U files based on the configured base_dir. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- modules/music-config.el | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'modules') diff --git a/modules/music-config.el b/modules/music-config.el index 2e9b3252..cdbe56e0 100644 --- a/modules/music-config.el +++ b/modules/music-config.el @@ -201,21 +201,25 @@ M3U-FILE should be an existing, writable M3U file path." (unless (file-writable-p m3u-file) (error "M3U file is not writable: %s" m3u-file)) - ;; Determine if we need a leading newline - (let ((needs-prefix-newline nil) - (file-size (file-attribute-size (file-attributes m3u-file)))) - (when (> file-size 0) - ;; Read the last character of the file to check if it ends with newline + ;; Convert absolute path to relative path from music root + (let ((relative-path (if (file-name-absolute-p track-path) + (file-relative-name track-path cj/music-root) + track-path))) + ;; Determine if we need a leading newline + (let ((needs-prefix-newline nil) + (file-size (file-attribute-size (file-attributes m3u-file)))) + (when (> file-size 0) + ;; Read the last character of the file to check if it ends with newline + (with-temp-buffer + (insert-file-contents m3u-file nil (max 0 (1- file-size)) file-size) + (setq needs-prefix-newline (not (= (char-after (point-min)) ?\n))))) + + ;; Append the track with proper newline handling (with-temp-buffer - (insert-file-contents m3u-file nil (max 0 (1- file-size)) file-size) - (setq needs-prefix-newline (not (= (char-after (point-min)) ?\n))))) - - ;; Append the track with proper newline handling - (with-temp-buffer - (when needs-prefix-newline - (insert "\n")) - (insert track-path "\n") - (write-region (point-min) (point-max) m3u-file t 0))) + (when needs-prefix-newline + (insert "\n")) + (insert relative-path "\n") + (write-region (point-min) (point-max) m3u-file t 0)))) t) -- cgit v1.2.3