-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
1,164 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package audiometa | ||
|
||
import "errors" | ||
|
||
var ( | ||
ErrFLACParse = errors.New("error parsing flac stream") | ||
ErrFLACCmtParse = errors.New("error parsing flac comment") | ||
|
||
ErrMP4AtomOutOfBounds = errors.New("mp4 atom out of bounds") | ||
ErrMP4InvalidAtomSize = errors.New("mp4 atom has invalid size") | ||
ErrMP4InvalidEncoding = errors.New("invalid encoding: got wrong number of bytes") | ||
ErrMP4IlstAtomMissing = errors.New("ilst atom is missing") | ||
ErrMP4InvalidCntntType = errors.New("invalid content type") | ||
|
||
ErrOggInvalidSgmtTblSz = errors.New("invalid segment table size") | ||
ErrOggInvalidHeader = errors.New("invalid ogg header") | ||
ErrOggInvalidCRC = errors.New("invalid CRC") | ||
ErrOggMissingCOP = errors.New("missing ogg COP packet") | ||
ErrOggImgConfigFail = errors.New("failed to get image config") | ||
ErrOggCodecNotSpprtd = errors.New("unsupported codec for ogg") | ||
|
||
ErrMP3ParseFail = errors.New("error parsing mp3") | ||
|
||
ErrNoMethodAvlble = errors.New("no method available for this filetype") | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module github.com/gcottom/audiometa/v3 | ||
|
||
go 1.18 | ||
|
||
require ( | ||
github.com/aler9/writerseeker v1.1.0 | ||
github.com/bogem/id3v2/v2 v2.1.4 | ||
) | ||
|
||
require golang.org/x/text v0.14.0 // indirect |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
github.com/aler9/writerseeker v1.1.0 h1:t+Sm3tjp8scNlqyoa8obpeqwciMNOvdvsxjxEb3Sx3g= | ||
github.com/aler9/writerseeker v1.1.0/go.mod h1:QNCcjSKnLsYoTfMmXkEEfgbz6nNXWxKSaBY+hGJGWDA= | ||
github.com/bogem/id3v2/v2 v2.1.4 h1:CEwe+lS2p6dd9UZRlPc1zbFNIha2mb2qzT1cCEoNWoI= | ||
github.com/bogem/id3v2/v2 v2.1.4/go.mod h1:l+gR8MZ6rc9ryPTPkX77smS5Me/36gxkMgDayZ9G1vY= | ||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= | ||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= | ||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= | ||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= | ||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= | ||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= | ||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= | ||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= | ||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= | ||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= | ||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= | ||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= | ||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= | ||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= | ||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= | ||
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= | ||
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= | ||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= | ||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= | ||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= | ||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= | ||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module github.com/gcottom/audiometa/mp3/v3 | ||
|
||
go 1.18 | ||
|
||
require ( | ||
github.com/aler9/writerseeker v1.1.0 | ||
github.com/bogem/id3v2/v2 v2.1.4 | ||
) | ||
|
||
require golang.org/x/text v0.3.8 // indirect |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
github.com/aler9/writerseeker v1.1.0 h1:t+Sm3tjp8scNlqyoa8obpeqwciMNOvdvsxjxEb3Sx3g= | ||
github.com/aler9/writerseeker v1.1.0/go.mod h1:QNCcjSKnLsYoTfMmXkEEfgbz6nNXWxKSaBY+hGJGWDA= | ||
github.com/bogem/id3v2/v2 v2.1.4 h1:CEwe+lS2p6dd9UZRlPc1zbFNIha2mb2qzT1cCEoNWoI= | ||
github.com/bogem/id3v2/v2 v2.1.4/go.mod h1:l+gR8MZ6rc9ryPTPkX77smS5Me/36gxkMgDayZ9G1vY= | ||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= | ||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= | ||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= | ||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= | ||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= | ||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= | ||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= | ||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= | ||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= | ||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= | ||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= | ||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= | ||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= | ||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= | ||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= | ||
golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY= | ||
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= | ||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= | ||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= | ||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= | ||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,204 @@ | ||
package mp3 | ||
|
||
import ( | ||
"fmt" | ||
"image" | ||
"io" | ||
"strconv" | ||
) | ||
|
||
var mp3TextFrames = map[string]string{ | ||
"Artist": "TPE1", | ||
"Title": "TIT2", | ||
"Album": "TALB", | ||
"BPM": "TBPM", | ||
"Genre": "TCON", | ||
"Year": "TYER", | ||
"AlbumArtist": "TPE2", | ||
"Composer": "TCOM", | ||
"Copyright": "TCOP", | ||
"Date": "TDRC", | ||
"EncodedBy": "TENC", | ||
"Lyricist": "TEXT", | ||
"Language": "TLAN", | ||
"Length": "TLEN", | ||
"DiscNumberString": "TPOS", | ||
"Publisher": "TPUB", | ||
"SubTitle": "TIT3", | ||
"ISRC": "TSRC", | ||
"TrackNumberString": "TRCK", | ||
} | ||
|
||
type MP3Tag struct { | ||
Album string | ||
AlbumArt *image.Image | ||
AlbumArtist string | ||
Artist string | ||
BPM string | ||
Composer string //multiple seperated by / | ||
Copyright string //must begin with year yyyy and a space | ||
Date string //limit 4 char DDMM | ||
DiscNumber int //TPOS | ||
DiscNumberString string | ||
DiscTotal int | ||
EncodedBy string | ||
Genre string | ||
ISRC string | ||
Language string | ||
Length string //length in millisecs | ||
Lyricist string //multiple seperated by / | ||
Title string | ||
TrackNumber int | ||
TrackNumberString string | ||
TrackTotal int | ||
Publisher string | ||
SubTitle string | ||
Year string | ||
|
||
reader io.ReadSeeker | ||
} | ||
|
||
func (t *MP3Tag) GetAlbum() string { | ||
return t.Album | ||
} | ||
func (t *MP3Tag) GetCoverArt() *image.Image { | ||
return t.AlbumArt | ||
} | ||
func (t *MP3Tag) GetAlbumArtist() string { | ||
return t.AlbumArtist | ||
} | ||
func (t *MP3Tag) GetArtist() string { | ||
return t.Artist | ||
} | ||
func (t *MP3Tag) GetBPM() int { | ||
bpm, err := strconv.Atoi(t.BPM) | ||
if err != nil { | ||
return 0 | ||
} | ||
return bpm | ||
} | ||
func (t *MP3Tag) GetComposer() string { | ||
return t.Composer | ||
} | ||
func (t *MP3Tag) GetCopyright() string { | ||
return t.Copyright | ||
} | ||
func (t *MP3Tag) GetDate() string { | ||
return t.Date | ||
} | ||
func (t *MP3Tag) GetDiscNumber() int { | ||
return t.DiscNumber | ||
} | ||
func (t *MP3Tag) GetDiscTotal() int { | ||
return t.DiscTotal | ||
} | ||
func (t *MP3Tag) GetEncoder() string { | ||
return t.EncodedBy | ||
} | ||
func (t *MP3Tag) GetGenre() string { | ||
return t.Genre | ||
} | ||
func (t *MP3Tag) GetISRC() string { | ||
return t.ISRC | ||
} | ||
func (t *MP3Tag) GetLanguage() string { | ||
return t.Language | ||
} | ||
func (t *MP3Tag) GetLength() string { | ||
return t.Length | ||
} | ||
func (t *MP3Tag) GetLyricist() string { | ||
return t.Lyricist | ||
} | ||
func (t *MP3Tag) GetTitle() string { | ||
return t.Title | ||
} | ||
func (t *MP3Tag) GetTrackNumber() int { | ||
return t.TrackNumber | ||
} | ||
func (t *MP3Tag) GetTrackTotal() int { | ||
return t.TrackTotal | ||
} | ||
func (t *MP3Tag) GetPublisher() string { | ||
return t.Publisher | ||
} | ||
func (t *MP3Tag) GetSubTitle() string { | ||
return t.SubTitle | ||
} | ||
func (t *MP3Tag) GetYear() int { | ||
year, err := strconv.Atoi(t.Year) | ||
if err != nil { | ||
return 0 | ||
} | ||
return year | ||
} | ||
|
||
func (t *MP3Tag) SetAlbum(album string) { | ||
t.Album = album | ||
} | ||
func (t *MP3Tag) SetCoverArt(coverArt *image.Image) { | ||
t.AlbumArt = coverArt | ||
} | ||
func (t *MP3Tag) SetAlbumArtist(albumArtist string) { | ||
t.AlbumArtist = albumArtist | ||
} | ||
func (t *MP3Tag) SetArtist(artist string) { | ||
t.Artist = artist | ||
} | ||
func (t *MP3Tag) SetBPM(bpm int) { | ||
t.BPM = fmt.Sprint(bpm) | ||
} | ||
func (t *MP3Tag) SetComposer(composer string) { | ||
t.Composer = composer | ||
} | ||
func (t *MP3Tag) SetCopyright(copyright string) { | ||
t.Copyright = copyright | ||
} | ||
func (t *MP3Tag) SetDate(date string) { | ||
t.Date = date | ||
} | ||
func (t *MP3Tag) SetDiscNumber(discNumber int) { | ||
t.DiscNumber = discNumber | ||
} | ||
func (t *MP3Tag) SetDiscTotal(discTotal int) { | ||
t.DiscTotal = discTotal | ||
} | ||
func (t *MP3Tag) SetEncoder(encoder string) { | ||
t.EncodedBy = encoder | ||
} | ||
func (t *MP3Tag) SetGenre(genre string) { | ||
t.Genre = genre | ||
} | ||
func (t *MP3Tag) SetISRC(isrc string) { | ||
t.ISRC = isrc | ||
} | ||
func (t *MP3Tag) SetLanguage(language string) { | ||
t.Language = language | ||
} | ||
func (t *MP3Tag) SetLength(length string) { | ||
t.Length = length | ||
} | ||
func (t *MP3Tag) SetLyricist(lyricist string) { | ||
t.Lyricist = lyricist | ||
} | ||
func (t *MP3Tag) SetTitle(title string) { | ||
t.Title = title | ||
} | ||
func (t *MP3Tag) SetTrackNumber(trackNumber int) { | ||
t.TrackNumber = trackNumber | ||
} | ||
func (t *MP3Tag) SetTrackTotal(trackTotal int) { | ||
t.TrackTotal = trackTotal | ||
} | ||
func (t *MP3Tag) SetPublisher(publisher string) { | ||
t.Publisher = publisher | ||
} | ||
func (t *MP3Tag) SetSubTitle(subTitle string) { | ||
t.SubTitle = subTitle | ||
} | ||
func (t *MP3Tag) SetYear(year int) { | ||
t.Year = fmt.Sprint(year) | ||
} | ||
func (t *MP3Tag) Save(w io.Writer) error { | ||
return SaveMP3(t, w) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package mp3 | ||
|
||
import ( | ||
"bytes" | ||
"errors" | ||
"image" | ||
"io" | ||
"reflect" | ||
|
||
mp3TagLib "github.com/bogem/id3v2/v2" | ||
) | ||
|
||
func ParseMP3(r io.ReadSeeker) (*MP3Tag, error) { | ||
resultTag := MP3Tag{} | ||
resultTag.reader = r | ||
tag, err := mp3TagLib.ParseReader(r, mp3TagLib.Options{Parse: true}) | ||
if err != nil { | ||
return nil, errors.New("error parsing mp3") | ||
} | ||
rtPtr := reflect.ValueOf(&resultTag).Elem() | ||
for k, v := range mp3TextFrames { | ||
framer := tag.GetTextFrame(v) | ||
if framer.Text == "" { | ||
continue | ||
} | ||
rtPtr.FieldByName(k) | ||
} | ||
if pictures := tag.GetFrames("APIC"); len(pictures) > 0 { | ||
pic := pictures[0].(mp3TagLib.PictureFrame) | ||
if img, _, err := image.Decode(bytes.NewReader(pic.Picture)); err == nil { | ||
resultTag.AlbumArt = &img | ||
} | ||
} | ||
return &resultTag, nil | ||
} |
Oops, something went wrong.