feat: git init
This commit is contained in:
56
pkg/audio/audio.go
Normal file
56
pkg/audio/audio.go
Normal file
@@ -0,0 +1,56 @@
|
||||
package audio
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// SupportedAudioFormats lists the audio formats that can be processed
|
||||
type SupportedAudioFormats []string
|
||||
|
||||
var DefaultSupportedFormats = SupportedAudioFormats{
|
||||
".mp3",
|
||||
".wav",
|
||||
".flac",
|
||||
".m4a",
|
||||
".ogg",
|
||||
".opus",
|
||||
}
|
||||
|
||||
// IsSupported checks if a file has a supported audio format
|
||||
type AudioFile struct {
|
||||
Path string
|
||||
Format string
|
||||
Size int64
|
||||
}
|
||||
|
||||
func NewAudioFile(path string) (*AudioFile, error) {
|
||||
fileInfo, err := os.Stat(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ext := filepath.Ext(path)
|
||||
if !IsSupported(ext) {
|
||||
return nil, errors.New("unsupported audio format: " + ext)
|
||||
}
|
||||
|
||||
return &AudioFile{
|
||||
Path: path,
|
||||
Format: ext,
|
||||
Size: fileInfo.Size(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// IsSupported checks if the given extension is in supported formats
|
||||
func IsSupported(ext string) bool {
|
||||
ext = strings.ToLower(ext)
|
||||
for _, format := range DefaultSupportedFormats {
|
||||
if ext == format {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
Reference in New Issue
Block a user