diff options
| author | Physick <96335032+DegustatorPonos@users.noreply.github.com> | 2025-12-06 12:05:43 +0500 |
|---|---|---|
| committer | Physick <96335032+DegustatorPonos@users.noreply.github.com> | 2025-12-06 12:05:43 +0500 |
| commit | 5fd81183f54662fdf08549c0d635e80166c62fe9 (patch) | |
| tree | 0b730dd4f19c7446fabcc2ee7cc7313e94e67fe3 /Audio | |
initial endpoints
Diffstat (limited to 'Audio')
| -rw-r--r-- | Audio/Meta.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/Audio/Meta.go b/Audio/Meta.go new file mode 100644 index 0000000..9e288f3 --- /dev/null +++ b/Audio/Meta.go @@ -0,0 +1,35 @@ +package audio + +import ( + "io" + "os" + "time" + + "github.com/tcolgate/mp3" +) + +func GetSongDuration(path string) (time.Duration, error) { + var file, fopenErr = os.Open(path) + if fopenErr != nil { + return time.Duration(0), fopenErr + } + defer file.Close() + + var track = mp3.NewDecoder(file) + var duration time.Duration + var frame mp3.Frame + var skipped = 0 + + for { + var err = track.Decode(&frame, &skipped) + if err != nil { + if err == io.EOF { + break + } + return time.Duration(0), err + } + + duration += frame.Duration() + } + return duration, nil +} |
