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:
No files matched your search
@@ -134,6 +134,9 @@ func (s *Store) Read(relPath string) (*Playlist, error) {
|
|||||||
if strings.HasPrefix(line, "#") {
|
if strings.HasPrefix(line, "#") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if !filepath.IsAbs(line) {
|
||||||
|
line = filepath.Join(filepath.Dir(absPath), line)
|
||||||
|
}
|
||||||
playlist.Items = append(playlist.Items, 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(attrCommment, playlist.Comment))
|
||||||
fmt.Fprintln(file, encodeAttr(attrIsPublic, fmt.Sprint(playlist.IsPublic)))
|
fmt.Fprintln(file, encodeAttr(attrIsPublic, fmt.Sprint(playlist.IsPublic)))
|
||||||
for _, line := range playlist.Items {
|
for _, line := range playlist.Items {
|
||||||
|
if rel, err := filepath.Rel(filepath.Dir(absPath), line); err == nil {
|
||||||
|
line = rel
|
||||||
|
}
|
||||||
fmt.Fprintln(file, line)
|
fmt.Fprintln(file, line)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,9 +32,9 @@ Example comment
|
|||||||
It has multiple lines 👍
|
It has multiple lines 👍
|
||||||
`,
|
`,
|
||||||
Items: []string{
|
Items: []string{
|
||||||
"item 1.flac",
|
"/music/item 1.flac",
|
||||||
"item 2.flac",
|
"/music/item 2.flac",
|
||||||
"item 3.flac",
|
"/music/item 3.flac",
|
||||||
},
|
},
|
||||||
IsPublic: true,
|
IsPublic: true,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user