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

add: fn{parse, acceptedFileTypes}; #99

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
40 changes: 34 additions & 6 deletions tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,52 @@
// parsing and artwork extraction.
//
// Detect and parse tag metadata from an io.ReadSeeker (i.e. an *os.File):
// m, err := tag.ReadFrom(f)
// if err != nil {
// log.Fatal(err)
// }
// log.Print(m.Format()) // The detected format.
// log.Print(m.Title()) // The title of the track (see Metadata interface for more details).
//
// m, err := tag.ReadFrom(f)
// if err != nil {
// log.Fatal(err)
// }
// log.Print(m.Format()) // The detected format.
// log.Print(m.Title()) // The title of the track (see Metadata interface for more details).
package tag

import (
"errors"
"fmt"
"io"
"os"
"strings"
)

// ErrNoTagsFound is the error returned by ReadFrom when the metadata format
// cannot be identified.
var ErrNoTagsFound = errors.New("no tags found")

// Supported file types.
func AcceptedFileTypes() []FileType {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SupportedFileTypes would seem like a better name here.

return []FileType{
FileType(strings.ToLower(string(MP3))),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The FileType type is constructing an enumeration of the possible values (as far as Go can do with enums!), this should just return the values as-is without transforming them.

FileType(strings.ToLower(string(M4A))),
FileType(strings.ToLower(string(M4B))),
FileType(strings.ToLower(string(M4P))),
FileType(strings.ToLower(string(ALAC))),
FileType(strings.ToLower(string(FLAC))),
FileType(strings.ToLower(string(OGG))),
FileType(strings.ToLower(string(DSF))),
}
}

// Parse metadata from the file at the given path
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would replicate the doc from ReadFrom, adding that it's reading from a file.

// for readonly operations
func Parse(path string) (Metadata, error) {
f, err := os.Open(path)
if err == nil {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Convention here is to check for err != nil and handle that first.

defer f.Close()
return ReadFrom(f)
}
return nil, err
}

// ReadFrom detects and parses audio file metadata tags (currently supports ID3v1,2.{2,3,4}, MP4, FLAC/OGG).
// Returns non-nil error if the format of the given data could not be determined, or if there was a problem
// parsing the data.
Expand Down