Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Readme #4

Merged
merged 3 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 95 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,98 @@ MP3/MP4/FLAC/OGG tag reader and writer for go
[![Go Reference](https://pkg.go.dev/badge/github.com/gcottom/audiometa/v2.svg)](https://pkg.go.dev/github.com/gcottom/audiometa/v2) [![Go Report Card](https://goreportcard.com/badge/github.com/gcottom/audiometa/v2)](https://goreportcard.com/report/github.com/gcottom/audiometa/v2) [![Coverage Status](https://coveralls.io/repos/github/gcottom/audiometa/badge.svg?branch=main)](https://coveralls.io/github/gcottom/audiometa?branch=main)


This package allows you to parse and write ID tags for mp3, mp4 (m4a, m4b, m4p), FLAC, and ogg (Vorbis, OPUS) files.

This is the only package available in Go that uses native Go to allow writing of ogg vorbis metadata. As an added bonus I've added support for ogg OPUS as well.

You can access all of the fields of the IDTag through the accessor functions.

v2 massively improves memory management and speed. Several sections have been rewritten.


Fields that can be parsed:

MP3: Artist, AlbumArtist, Album, AlbumArt, Comments, Composer, Genre, Title, Year, BPM, ContentType, CopyrightMessage, Date, EncodedBy, Lyricist, FileType, Language, Length, PartOfSet, and Publisher

MP4: Artist, AlbumArtist, Album, AlbumArt, Comments, Composer, Genre, Title, Year, EncodedBy, and CopyrightMessage

FLAC: Artist, Album, AlbumArt, Date, Genre Title

OGG: Artist, AlbumArtist, Album, AlbumArt, Comment, Date, Genre, Title, Copyright, Publisher, Composer, and has extended support for all other custom or unmapped fields


Fields that can be written:

MP3: Artist, AlbumArtist, Album, AlbumArt, Comments, Composer, Genre, Title, Year, BPM, ContentType, CopyrightMessage, Date, EncodedBy, Lyricist, FileType, Language, Length, PartOfSet, and Publisher

MP4: Artist, AlbumArtist, Album, AlbumArt, Comments, Composer, Genre, Title, Year, and CopyrightMessage

FLAC: Artist, Album, AlbumArt, Genre, Title

OGG: Artist, AlbumArtist, Album, AlbumArt, Comment, Date, Genre, Title, Copyright, Publisher, Composer, and has extended support to allow for passthrough of unknown fields and adding any custom or unmapped field
This package enables parsing and writing of ID tags for mp3, mp4 (m4a, m4b, m4p), FLAC, and ogg (Vorbis, OPUS) files.

All fields can be accessed via the provided accessor methods. Only supported fields per file type will return non zero data. The exception to this is that ogg files support a passthrough map.
By setting kv pairs in the passthrough map, non-standard vorbis comment tags can be written to both ogg Vorbis and ogg OPUS files.


# Parsable Fields Per FileType

## MP3
Artist, AlbumArtist, Album, AlbumArt, BPM, ContentType, Comments, Composer, CopyrightMessage, Date, EncodedBy, FileType, Genre, Language, Length, Lyricist, PartOfSet, Publisher, Title, Year

## MP4 & MP4 Types (m4a, m4b, m4p, mp4)
Artist, AlbumArtist, Album, AlbumArt, Comments, Composer, CopyrightMessage, EncodedBy, Genre, Title, Year

## FLAC
Artist, Album, AlbumArt, Date, Genre, Title

## OGG (Vorbis and OPUS within an ogg container)
Artist, AlbumArtist, Album, AlbumArt, Comment, Composer, Copyright, Date, Genre, Title, Publisher, (extended support for custom fields via passthrough map)


# Writable Fields Per FileType

## MP3
Artist, AlbumArtist, Album, AlbumArt, BPM, ContentType, Comments, Composer, CopyrightMessage, Date, EncodedBy, FileType, Genre, Language, Length, Lyricist, PartOfSet, Publisher, Title, Year

## MP4 & MP4 Types (m4a, m4b, m4p, mp4)
Artist, AlbumArtist, Album, Comments, CopyrightMessage, Composer, Genre, Title, Year (AlbumArt is currently not writeable)

## FLAC
Artist, Album, AlbumArt, Date, Genre, Title

## OGG (Vorbis and OPUS within an ogg container)
Artist, AlbumArtist, Album, AlbumArt, Comment, Composer, Copyright, Date, Genre, Title, Publisher, (extended support for custom fields via passthrough map)

# Usage

## Open Tag For Reading From Path
```
tag, err := audiometa.OpenTagFromPath("./my-audio-file.mp3")
if err != nil{
panic(err)
}

artist := tag.Artist()
album := tag.Album()
title := tag.Title()
```

## Open Tag For Reading From io.ReadSeeker
```
f, err := os.Open("./my-audio-file.mp3")
tag, err := audiometa.Open(f, audiometa.ParseOptions{Format: audiometa.MP3}) //ParseOptions is only required if the file does not have an extension
if err != nil{
panic(err)
}

artist := tag.Artist()
album := tag.Album()
title := tag.Title()
```

## Update Tag
```
f, err := os.Open("./my-audio-file.mp3")
if err != nil{
panic(err)
}
tag, err := audiometa.Open(f)
if err != nil{
panic(err)
}
tag.SetArtist("Beyonce")
err = tag.Save(f)
if err != nil{
panic(err)
}
```

## Clear All Tags And Save
```
f, err := os.Open("./my-audio-file.mp3")
if err != nil{
panic(err)
}
tag, err := audiometa.Open(f)
if err != nil{
panic(err)
}
tag.ClearAllTags()
err = tag.Save(f)
if err != nil{
panic(err)
}
```
7 changes: 1 addition & 6 deletions mp4_decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ var atoms = atomNames(map[string]string{
"disk": "disc",
})

// Detect PNG image if "implicit" class is used
var pngHeader = []byte{137, 80, 78, 71, 13, 10, 26, 10}

type atomNames map[string]string

func (f atomNames) name(n string) []string {
Expand Down Expand Up @@ -164,9 +161,7 @@ func (m metadataMP4) readAtomData(r io.ReadSeeker, name string, size uint32, pro

if contentType == "implicit" {
if name == "covr" {
if bytes.HasPrefix(b, pngHeader) {
contentType = "png"
}
contentType = "png"
}
}

Expand Down
Loading
Loading