mirror of
https://git.sr.ht/~phw/scotty
synced 2025-05-10 02:07:05 +02:00
JSPF: Implemented export as loves and listens
This commit is contained in:
parent
cfc3cd522d
commit
a645ec5c78
6 changed files with 225 additions and 42 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright © 2023 Philipp Wolfer <phw@uploadedlobster.com>
|
||||
Copyright © 2023-2025 Philipp Wolfer <phw@uploadedlobster.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -22,7 +22,28 @@ THE SOFTWARE.
|
|||
|
||||
package jspf
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Represents a JSPF extension
|
||||
type Extension any
|
||||
|
||||
// A map of JSPF extensions
|
||||
type ExtensionMap map[string]Extension
|
||||
|
||||
// Parses the extension with the given ID and unmarshals it into "v".
|
||||
// If the extensions is not found or the data cannot be unmarshalled,
|
||||
// an error is returned.
|
||||
func (e ExtensionMap) Get(id string, v any) error {
|
||||
ext, ok := e[id]
|
||||
if !ok {
|
||||
return fmt.Errorf("extension %q not found", id)
|
||||
}
|
||||
return unmarshalExtension(ext, v)
|
||||
}
|
||||
|
||||
const (
|
||||
// The identifier for the MusicBrainz / ListenBrainz JSPF playlist extension
|
||||
|
@ -83,3 +104,11 @@ type MusicBrainzTrackExtension struct {
|
|||
// this document.
|
||||
AdditionalMetadata map[string]any `json:"additional_metadata,omitempty"`
|
||||
}
|
||||
|
||||
func unmarshalExtension(ext Extension, v any) error {
|
||||
asJson, err := json.Marshal(ext)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return json.Unmarshal(asJson, v)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue