36 lines
729 B
Go
36 lines
729 B
Go
package audio
|
|
|
|
import (
|
|
"fmt"
|
|
"path/filepath"
|
|
"strings"
|
|
)
|
|
|
|
type TrackInfo struct {
|
|
Format string
|
|
BitDepth int
|
|
SampleRate int
|
|
Channels int
|
|
DurationMs int
|
|
BitrateKbps int
|
|
IsLossless bool
|
|
}
|
|
|
|
func Analyze(filePath string) (*TrackInfo, error) {
|
|
ext := strings.ToLower(filepath.Ext(filePath))
|
|
|
|
switch ext {
|
|
case ".flac":
|
|
return analyzeFLAC(filePath)
|
|
case ".mp3":
|
|
return analyzeMP3(filePath)
|
|
case ".aac", ".m4a", ".ogg", ".wav", ".ape", ".wv", ".alac":
|
|
return &TrackInfo{
|
|
Format: strings.ToUpper(strings.TrimPrefix(ext, ".")),
|
|
IsLossless: ext == ".wav" || ext == ".ape" || ext == ".wv" || ext == ".alac",
|
|
}, nil
|
|
default:
|
|
return nil, fmt.Errorf("unsupported audio format: %s", ext)
|
|
}
|
|
}
|