refactor: unify logic to export to M3U8

Signed-off-by: Deluan <deluan@navidrome.org>
This commit is contained in:
Deluan
2025-05-27 12:37:57 -04:00
parent 85a7268192
commit 71851b076c
5 changed files with 96 additions and 27 deletions
+2 -11
View File
@@ -2,7 +2,6 @@ package model
import (
"cmp"
"fmt"
"strings"
"time"
@@ -50,17 +49,9 @@ func (s Share) CoverArtID() ArtworkID {
type Shares []Share
// ToM3U8 exports the playlist to the Extended M3U8 format, as specified in
// https://docs.fileformat.com/audio/m3u/#extended-m3u
// ToM3U8 exports the share to the Extended M3U8 format.
func (s Share) ToM3U8() string {
buf := strings.Builder{}
buf.WriteString("#EXTM3U\n")
buf.WriteString(fmt.Sprintf("#PLAYLIST:%s\n", cmp.Or(s.Description, s.ID)))
for _, t := range s.Tracks {
buf.WriteString(fmt.Sprintf("#EXTINF:%.f,%s - %s\n", t.Duration, t.Artist, t.Title))
buf.WriteString(t.Path + "\n")
}
return buf.String()
return s.Tracks.ToM3U8(cmp.Or(s.Description, s.ID), false)
}
type ShareRepository interface {