From fe0d80007f00bdd6af49e05e51f9ea3b5d634109 Mon Sep 17 00:00:00 2001 From: partisan Date: Sun, 15 Jun 2025 07:31:17 +0200 Subject: [PATCH] Fix time indicator for soundcloud music --- music-soundcloud.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/music-soundcloud.go b/music-soundcloud.go index f8a7221..2aa9f46 100644 --- a/music-soundcloud.go +++ b/music-soundcloud.go @@ -84,6 +84,19 @@ func convertSoundCloudResults(tracks []SoundCloudTrack) []MusicResult { track.Permalink, ) + // Convert ms to hh:mm:ss + totalSeconds := track.Duration / 1000 + hours := totalSeconds / 3600 + minutes := (totalSeconds % 3600) / 60 + seconds := totalSeconds % 60 + + var durationStr string + if hours > 0 { + durationStr = fmt.Sprintf("%d:%02d:%02d", hours, minutes, seconds) + } else { + durationStr = fmt.Sprintf("%d:%02d", minutes, seconds) + } + results = append(results, MusicResult{ Title: track.Title, Artist: track.User.Username, @@ -91,7 +104,7 @@ func convertSoundCloudResults(tracks []SoundCloudTrack) []MusicResult { Thumbnail: thumbnail, //AudioURL: track.Streams.HTTPMP3128URL, Source: "SoundCloud", - Duration: fmt.Sprintf("%d", track.Duration/1000), + Duration: durationStr, }) } return results