Skip to content

Commit

Permalink
Review remarks
Browse files Browse the repository at this point in the history
  • Loading branch information
JojiiOfficial committed Feb 5, 2025
1 parent 29b0477 commit 1eaa779
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions backend/lrclib.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@ import (
"strings"
"time"

"github.com/20after4/configdir"
"github.com/dweymouth/supersonic/backend/mediaprovider"
)

const CACHE_LYRICS_FOLDER = "lyrics"

func FetchLrcLibLyricsCached(name, artist, album string, durationSecs int, cacheDir string) (*mediaprovider.Lyrics, error) {
hash := makeTrackIdHash(name, artist, album)
cacheFilePath := filepath.Join(cacheDir, fmt.Sprintf("%s_lyrics.txt", hash))
hash := makeTrackIdHash(name, artist, album, durationSecs)
cachePath := filepath.Join(cacheDir, CACHE_LYRICS_FOLDER)
configdir.MakePath(cachePath)
cacheFilePath := filepath.Join(cachePath, fmt.Sprintf("%s_lyrics.txt", hash))

// File is cached. Try to use it
if _, err := os.Stat(cacheFilePath); err == nil {
Expand Down Expand Up @@ -179,9 +184,9 @@ func readCachedLyrics(cacheFile string) (*mediaprovider.Lyrics, error) {
}

// Create a "unique" hash for a song to identify it.
func makeTrackIdHash(name, artist, album string) string {
func makeTrackIdHash(name, artist, album string, durationSecs int) string {
hasher := md5.New()
identifier := fmt.Sprintf("%s;%s;%s", name, artist, album)
identifier := fmt.Sprintf("%s;%s;%s;%d", name, artist, album, durationSecs)
hasher.Write([]byte(identifier))
return hex.EncodeToString(hasher.Sum(nil))
}

0 comments on commit 1eaa779

Please sign in to comment.