feat(playlist): use relative paths in m3u playlists

write playlist item paths relative to the playlist file directory, an resolve relative paths back to absolute on read

closes #537
closes #529
This commit is contained in:
sentriz
2026-04-26 03:00:53 +02:00
committed by yaemiku
parent fb3fb745f8
commit 13098660d2
2 changed files with 9 additions and 3 deletions

No files matched your search

+6
View File
@@ -134,6 +134,9 @@ func (s *Store) Read(relPath string) (*Playlist, error) {
if strings.HasPrefix(line, "#") {
continue
}
if !filepath.IsAbs(line) {
line = filepath.Join(filepath.Dir(absPath), line)
}
playlist.Items = append(playlist.Items, line)
}
@@ -186,6 +189,9 @@ func (s *Store) Write(relPath string, playlist *Playlist) error {
fmt.Fprintln(file, encodeAttr(attrCommment, playlist.Comment))
fmt.Fprintln(file, encodeAttr(attrIsPublic, fmt.Sprint(playlist.IsPublic)))
for _, line := range playlist.Items {
if rel, err := filepath.Rel(filepath.Dir(absPath), line); err == nil {
line = rel
}
fmt.Fprintln(file, line)
}
+3 -3
View File
@@ -32,9 +32,9 @@ Example comment
It has multiple lines 👍
`,
Items: []string{
"item 1.flac",
"item 2.flac",
"item 3.flac",
"/music/item 1.flac",
"/music/item 2.flac",
"/music/item 3.flac",
},
IsPublic: true,
}