Adding slightly tested support for OGG, using VorbisComment parsing from flac.go

This commit is contained in:
Simon L 2015-05-19 21:56:05 +02:00
parent e5ad564af4
commit 109d54c374
2 changed files with 104 additions and 0 deletions

101
ogg.go Normal file
View File

@ -0,0 +1,101 @@
// Copyright 2015, David Howden
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package tag
import (
"errors"
"io"
"os"
)
// ReadOGGTags reads OGG metadata from the io.ReadSeeker, returning the resulting
// metadata in a Metadata implementation, or non-nil error if there was a problem.
// TODO: Needs a more generic return type than "metadataFLAC" and the "FLAC" format is not as obvious as "Vorbis comment"
func ReadOGGTags(r io.ReadSeeker) (Metadata, error) {
_, err := r.Seek(0, os.SEEK_SET)
if err != nil {
return nil, err
}
oggs, err := readString(r, 4)
if err != nil {
return nil, err
}
if oggs != "OggS" {
return nil, errors.New("expected 'OggS'")
}
_, err = r.Seek(22, os.SEEK_CUR)
if err != nil {
return nil, err
}
nS, err := readInt(r, 1)
if err != nil {
return nil, err
}
_, err = r.Seek(int64(nS), os.SEEK_CUR)
if err != nil {
return nil, err
}
idComment, err := readInt(r, 1)
if err != nil {
return nil, err
}
if idComment != 1 {
return nil, errors.New("expected 'vorbis' identification type 1")
}
_, err = r.Seek(29, os.SEEK_CUR)
if err != nil {
return nil, err
}
oggs, err = readString(r, 4)
if err != nil {
return nil, err
}
if oggs != "OggS" {
return nil, errors.New("expected 'OggS'")
}
_, err = r.Seek(22, os.SEEK_CUR)
if err != nil {
return nil, err
}
nS, err = readInt(r, 1)
if err != nil {
return nil, err
}
_, err = r.Seek(int64(nS), os.SEEK_CUR)
if err != nil {
return nil, err
}
typeComment, err := readInt(r, 1)
if err != nil {
return nil, err
}
if typeComment != 3 {
return nil, errors.New("expected 'vorbis' comment type 3")
}
_, err = r.Seek(6, os.SEEK_CUR)
if err != nil {
return nil, err
}
m := &metadataFLAC{
c: make(map[string]string),
}
err = m.readVorbisComment(r)
return m, err
}

3
tag.go
View File

@ -29,6 +29,9 @@ func ReadFrom(r io.ReadSeeker) (Metadata, error) {
case string(b[0:4]) == "fLaC":
return ReadFLACTags(r)
case string(b[0:4]) == "OggS":
return ReadOGGTags(r)
case string(b[4:11]) == "ftypM4A":
return ReadAtoms(r)