-
Notifications
You must be signed in to change notification settings - Fork 77
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
return []FileType{ | ||
FileType(strings.ToLower(string(MP3))), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Convention here is to check for |
||
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. | ||
|
There was a problem hiding this comment.
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.