Documentation
¶
Overview ¶
Package tag describes audio metadata, including normalized fields, native tags, embedded artwork, and snapshots delivered during playback.
Index ¶
- Variables
- type Artwork
- type ArtworkRole
- type Key
- type Metadata
- func (m Metadata) Album() string
- func (m Metadata) AlbumArtists() []string
- func (m Metadata) Artists() []string
- func (m Metadata) Artwork() []Artwork
- func (m Metadata) Date() string
- func (m Metadata) DiscNumber() string
- func (m Metadata) First(key Key) string
- func (m Metadata) Genres() []string
- func (m Metadata) SourceTags() []SourceTag
- func (m Metadata) Title() string
- func (m Metadata) TrackNumber() string
- func (m Metadata) Values(key Key) []string
- type Scope
- type SourceTag
- type Update
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNilContext = errors.New("tag: nil context")
ErrNilContext reports that opening artwork requires a non-nil context.
Functions ¶
This section is empty.
Types ¶
type Artwork ¶
type Artwork struct {
MIMEType string
Role ArtworkRole
Description string
Size int64 // Encoded byte count, or -1 when unknown.
// contains filtered or unexported fields
}
Artwork gives access to an original encoded image.
func NewArtwork ¶
func NewArtwork(mime string, role ArtworkRole, description string, size int64, open func(context.Context) (io.ReadCloser, error)) Artwork
NewArtwork describes an encoded image. The open function must return a fresh reader positioned at the start of the same image on each call.
func (Artwork) Open ¶
Open returns a reader positioned at the start of the original encoded image. Each call has its own cursor. Close the reader after use. A nil context returns ErrNilContext.
Artwork retained by a forward-only decoder stays readable after the decoder and its input close. For file-backed artwork, keep the input open until the returned reader is closed.
Example ¶
// A stream decoder keeps the encoded image after reading its tag.
image := []byte{0xff, 0xd8, 0xff, 0xd9}
cover := NewArtwork(
"image/jpeg",
ArtworkFront,
"Front cover",
int64(len(image)),
func(context.Context) (io.ReadCloser, error) {
return io.NopCloser(bytes.NewReader(image)), nil
},
)
reader, err := cover.Open(context.Background())
if err != nil {
panic(err)
}
defer func() { _ = reader.Close() }()
encoded, err := io.ReadAll(reader)
if err != nil {
panic(err)
}
fmt.Printf("%s %x\n", cover.MIMEType, encoded)
Output: image/jpeg ffd8ffd9
type ArtworkRole ¶
type ArtworkRole uint8
ArtworkRole identifies how the source classified an image.
const ( ArtworkOther ArtworkRole = iota // Unspecified or different role. ArtworkFront // Front cover. ArtworkBack // Back cover. )
type Key ¶
type Key int
Key identifies a normalized metadata field.
const ( Unknown Key = iota // Native field without a canonical mapping. Title // Selected recording title. Artists // Performers credited on the recording. Album // Album containing the recording. AlbumArtists // Performers credited for the album. NowPlaying // Current title supplied by a live stream. Station // Station or service carrying the stream. Genres // Musical styles listed for the recording. Date // Release or recording date supplied by the source. TrackNumber // Positive decimal position within a disc or release. DiscNumber // Positive decimal position within a multi-disc release. )
type Metadata ¶
type Metadata struct {
// contains filtered or unexported fields
}
Metadata is a snapshot of the tags and artwork associated with audio. Its zero value represents an audio source with no reported metadata.
Example ¶
// A decoder supplies source fields with their canonical keys.
fields := []SourceTag{
{
Namespace: "vorbis",
Name: "TITLE",
Key: Title,
Values: []string{"Night Flight"},
},
}
metadata := NewMetadata(fields, nil)
fmt.Println(metadata.Title())
fmt.Println(metadata.SourceTags()[0].Name)
Output: Night Flight TITLE
func NewMetadata ¶
NewMetadata builds a snapshot from the decoder's fields and artwork.
func (Metadata) AlbumArtists ¶
AlbumArtists returns the credited album artists in source order.
func (Metadata) DiscNumber ¶
DiscNumber returns the positive decimal disc number, or an empty string.
func (Metadata) SourceTags ¶
SourceTags returns copies of all parsed text tags, including empty values.
func (Metadata) TrackNumber ¶
TrackNumber returns the positive decimal track number, or an empty string.
type SourceTag ¶
type SourceTag struct {
Namespace string
Name string
Qualifier string
Values []string
Language string
Locale uint32 // Native locale indicator, if present.
Scope Scope
Key Key // Canonical field, or Unknown.
Normalized []string // Decoded values when they differ from Values.
}
SourceTag retains a text value in its native namespace.