Parse correctly playlist CoverArt ids

This commit is contained in:
Deluan 2022-12-27 17:05:40 -05:00 committed by Deluan Quintão
parent 8f3387a894
commit 501386b11f
4 changed files with 24 additions and 9 deletions

View file

@ -4,6 +4,8 @@ import (
"errors"
"fmt"
"strings"
"golang.org/x/exp/slices"
)
type Kind struct{ prefix string }
@ -11,8 +13,15 @@ type Kind struct{ prefix string }
var (
KindMediaFileArtwork = Kind{"mf"}
KindAlbumArtwork = Kind{"al"}
KindPlaylistArtwork = Kind{"pl"}
)
var artworkKindList = []string{
KindAlbumArtwork.prefix,
KindMediaFileArtwork.prefix,
KindPlaylistArtwork.prefix,
}
type ArtworkID struct {
Kind Kind
ID string
@ -26,11 +35,11 @@ func (id ArtworkID) String() string {
}
func ParseArtworkID(id string) (ArtworkID, error) {
parts := strings.Split(id, "-")
parts := strings.SplitN(id, "-", 2)
if len(parts) != 2 {
return ArtworkID{}, errors.New("invalid artwork id")
}
if parts[0] != KindAlbumArtwork.prefix && parts[0] != KindMediaFileArtwork.prefix {
if !slices.Contains(artworkKindList, parts[0]) {
return ArtworkID{}, errors.New("invalid artwork kind")
}
return ArtworkID{