Skip to content

Commit

Permalink
pkg metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
sayem314 committed Sep 27, 2024
1 parent fe873d9 commit 8d2f0cb
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions pkg/metadata/metadata.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package metadata

import (
"bytes"
"strings"

"golang.org/x/text/cases"
"golang.org/x/text/language"

"github.com/d-fi/GoFi/pkg/api"
"github.com/d-fi/GoFi/pkg/types"
)

// AddTrackTags adds metadata to the track buffer (MP3 or FLAC) based on track and album information.
func AddTrackTags(trackBuffer []byte, track types.TrackType, albumCoverSize int) ([]byte, error) {
cover, coverErr := DownloadAlbumCover(track.ALB_PICTURE, albumCoverSize)
if coverErr != nil {
return nil, coverErr
}

var lyrics types.LyricsType
if track.LYRICS_ID > 0 {
var lyricsErr error
lyrics, lyricsErr = api.GetLyrics(track.SNG_ID)
if lyricsErr == nil {
track.LYRICS = &lyrics
}
}

album, albumErr := api.GetAlbumInfoPublicApi(track.ALB_ID)
if albumErr != nil {
return nil, albumErr
}

if strings.ToLower(track.ART_NAME) == "various" {
track.ART_NAME = "Various Artists"
}

if album.RecordType != "" {
caser := cases.Title(language.English)
if strings.ToLower(album.RecordType) == "ep" {
album.RecordType = "EP"
} else {
album.RecordType = caser.String(album.RecordType)
}
}

isFlac := bytes.HasPrefix(trackBuffer, []byte("fLaC"))
if isFlac {
return WriteMetadataFlac(trackBuffer, track, &album, albumCoverSize, cover)
}

return WriteMetadataMp3(trackBuffer, track, &album, cover)
}

0 comments on commit 8d2f0cb

Please sign in to comment.