Documentation
¶
Overview ¶
Package for reading and writing music playlists in the JSPF format.
JSPF is the JSON representation of XSPF, see https://www.xspf.org/jspf
Index ¶
Examples ¶
Constants ¶
View Source
const ( // The identifier for the MusicBrainz / ListenBrainz JSPF playlist extension MusicBrainzPlaylistExtensionId = "https://musicbrainz.org/doc/jspf#playlist" // The identifier for the MusicBrainz / ListenBrainz JSPF track extension MusicBrainzTrackExtensionId = "https://musicbrainz.org/doc/jspf#track" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Attribution ¶
type JSPF ¶
type JSPF struct {
Playlist Playlist `json:"playlist"`
}
A JSPF playlist
func (*JSPF) Read ¶
Reads the JSPF playlist in JSON format from the given io.Reader
Example ¶
package main import ( "fmt" "log" "os" "go.uploadedlobster.com/scotty/pkg/jspf" ) func main() { file, err := os.Open("testdata/simple.jspf") if err != nil { log.Fatal(err) } defer file.Close() pl := jspf.JSPF{} err = pl.Read(file) if err != nil { log.Fatal(err) } fmt.Printf("Playlist '%v' with %v tracks", pl.Playlist.Title, len(pl.Playlist.Tracks)) }
Output: Playlist 'Two Songs From Thriller' with 2 tracks
func (*JSPF) Write ¶
Writes the JSPF playlist in JSON format to the given io.Writer
Example ¶
package main import ( "bytes" "fmt" "log" "time" "go.uploadedlobster.com/scotty/pkg/jspf" ) func main() { date, _ := time.Parse(time.RFC3339, "2023-11-23T23:56:00Z") pl := jspf.JSPF{ Playlist: jspf.Playlist{ Title: "The Playlist", Creator: "Scotty", Date: date, Tracks: []jspf.Track{ { Title: "The Track", }, }, }, } buf := bytes.NewBuffer(make([]byte, 0, 10)) err := pl.Write(buf) if err != nil { log.Fatal(err) } fmt.Print(buf.String()) }
Output: { "playlist": { "title": "The Playlist", "creator": "Scotty", "date": "2023-11-23T23:56:00Z", "track": [ { "title": "The Track" } ] } }
type MusicBrainzPlaylistExtension ¶
type MusicBrainzPlaylistExtension struct { // The ListenBrainz user who created this playlist. Creator string `json:"added_by,omitempty"` // Which ListenBrainz user was the playlist generated for? This is for music // recommendation bots generating playlists for users. CreatedFor string `json:"created_for,omitempty"` // Who are the ListenBrainz users who have access to edit this playlist? Collaborators []string `json:"collaborators,omitempty"` // This field identifies a playlist, using the identifier syntax, // from which this playlist was copied from. CopiedFrom string `json:"copied_from,omitempty"` // If the source playlist that this playlist has been copied from has been // deleted, this field will be set to true and the copied_from field will not // be returned. CopiedFromDeleted bool `json:"copied_from_deleted,omitempty"` // Indicates if this playlist is public or private. Public bool `json:"public,omitempty"` // The timestamp for when this playlist was last modified. LastModifiedAt time.Time `json:"last_modified_at,omitempty"` // This dict allows a playlist creator to submit additional track metadata // that may be used by playlist generation tools. The content of this field // is defined by the playlist generation tools and is beyond the scope of // this document. AdditionalMetadata map[string]any `json:"additional_metadata,omitempty"` }
MusicBrainz / ListenBrainz JSPF track extension
This extension allows storing additional metadata for playlists.
type MusicBrainzTrackExtension ¶
type MusicBrainzTrackExtension struct { // The timestamp for when this track was added to the playlist. AddedAt time.Time `json:"added_at,omitempty"` // The ListenBrainz user who added this track. AddedBy string `json:"added_by,omitempty"` // The MusicBrainz ID URI for the release that contained this track. ReleaseIdentifier string `json:"release_identifier,omitempty"` // A list of MusicBrainz Artist URIs that identify the artist that are part // of the MusicBrainz artist credit id for this track. ArtistIdentifiers []string `json:"artist_identifiers,omitempty"` // This dict allows a playlist creator to submit additional track metadata // that may be used by playlist generation tools. The content of this field // is defined by the playlist generation tools and is beyond the scope of // this document. AdditionalMetadata map[string]any `json:"additional_metadata,omitempty"` }
MusicBrainz / ListenBrainz JSPF track extension
This extension allows storing additional metadata for tracks.
See "https://musicbrainz.org/doc/jspf#track"
Example ¶
package main import ( "bytes" "fmt" "log" "time" "go.uploadedlobster.com/scotty/pkg/jspf" ) func main() { pl := jspf.JSPF{ Playlist: jspf.Playlist{ Date: time.Date(2023, 11, 24, 07, 47, 50, 0, time.UTC), Tracks: []jspf.Track{ { Title: "Oweynagat", Extension: map[string]any{ jspf.MusicBrainzTrackExtensionId: jspf.MusicBrainzTrackExtension{ AddedAt: time.Date(2023, 11, 24, 07, 47, 50, 0, time.UTC), AddedBy: "scotty", }, }, }, }, }, } buf := bytes.NewBuffer(make([]byte, 0, 10)) err := pl.Write(buf) if err != nil { log.Fatal(err) } fmt.Print(buf.String()) }
Output: { "playlist": { "date": "2023-11-24T07:47:50Z", "track": [ { "title": "Oweynagat", "extension": { "https://musicbrainz.org/doc/jspf#track": { "added_at": "2023-11-24T07:47:50Z", "added_by": "scotty" } } } ] } }
type Playlist ¶
type Playlist struct { Title string `json:"title,omitempty"` Creator string `json:"creator,omitempty"` Annotation string `json:"annotation,omitempty"` Info string `json:"info,omitempty"` Location string `json:"location,omitempty"` Identifier string `json:"identifier,omitempty"` Image string `json:"image,omitempty"` Date time.Time `json:"date,omitempty"` License string `json:"license,omitempty"` Attribution []Attribution `json:"attribution,omitempty"` Links []Link `json:"link,omitempty"` Meta []Meta `json:"meta,omitempty"` Extension map[string]any `json:"extension,omitempty"` Tracks []Track `json:"track"` }
type Track ¶
type Track struct { Location []string `json:"location,omitempty"` Identifier []string `json:"identifier,omitempty"` Title string `json:"title,omitempty"` Creator string `json:"creator,omitempty"` Annotation string `json:"annotation,omitempty"` Info string `json:"info,omitempty"` Album string `json:"album,omitempty"` TrackNum int `json:"trackNum,omitempty"` Duration int `json:"duration,omitempty"` Links []Link `json:"link,omitempty"` Meta []Meta `json:"meta,omitempty"` Extension map[string]any `json:"extension,omitempty"` }
Click to show internal directories.
Click to hide internal directories.