diff options
| author | Craig Jennings <c@cjennings.net> | 2025-11-12 22:42:31 -0600 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2025-11-12 22:42:31 -0600 |
| commit | bd0ea189aa0751a6c342c7a0b8a6f5265090388e (patch) | |
| tree | 64bfa05b1684fe198dc539367f81b48f7916069c /modules | |
| parent | 5d047bef9277ac29187ea71dda1e7ab649072882 (diff) | |
fix: Write relative paths to M3U playlists instead of absolute
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 <noreply@anthropic.com>
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/music-config.el | 32 |
1 files changed, 18 insertions, 14 deletions
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) |
