diff options
| author | Physick <96335032+DegustatorPonos@users.noreply.github.com> | 2025-12-13 12:32:15 +0500 |
|---|---|---|
| committer | Physick <96335032+DegustatorPonos@users.noreply.github.com> | 2025-12-13 12:32:15 +0500 |
| commit | ae11ed555cb350ea4c11fc1625f4a56229969ddd (patch) | |
| tree | 1d02b84131b713a2eed9a332ffac51997b0ec285 /Audio/Meta.go | |
| parent | 4b8ef84059e772ef7636c451356680ec5b0983c4 (diff) | |
Tracks meta
Diffstat (limited to 'Audio/Meta.go')
| -rw-r--r-- | Audio/Meta.go | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/Audio/Meta.go b/Audio/Meta.go index 9e288f3..6b8343c 100644 --- a/Audio/Meta.go +++ b/Audio/Meta.go @@ -1,13 +1,44 @@ package audio import ( + "fmt" "io" "os" "time" + "github.com/dhowden/tag" "github.com/tcolgate/mp3" + settings "physick.ru/culture_exam/Settings" ) +type TrackMeta struct { + Name string + Author string + Album string + Location string + Duration time.Duration +} + +func GenerateMetadata(fileName string) (TrackMeta, error) { + var fullPath = fmt.Sprintf("%s/%s", settings.Current.SongsLocation, fileName) + var duration, error = GetSongDuration(fullPath) + // If file doesn't exist that will be caught there + if error != nil { + return TrackMeta{}, error + } + var Artist, Title, Album, metaErr = GetInfo(fullPath) + if metaErr != nil { + return TrackMeta{}, metaErr + } + return TrackMeta { + Name: Title, + Author: Artist, + Album: Album, + Location: fullPath, + Duration: duration, + }, nil +} + func GetSongDuration(path string) (time.Duration, error) { var file, fopenErr = os.Open(path) if fopenErr != nil { @@ -33,3 +64,17 @@ func GetSongDuration(path string) (time.Duration, error) { } return duration, nil } + +// Author - name - album +func GetInfo (filePath string) (string, string, string, error) { + f, err := os.Open(filePath) + if err != nil { + return "", "", "", err + } + defer f.Close() + m, err := tag.ReadFrom(f) + if err != nil { + return "", "", "", err + } + return m.Artist(), m.Title(), m.Album(), nil +} |
