fix(metadata): remove forced download attribution

This commit is contained in:
zarzet
2026-08-26 18:31:39 +07:00
parent 832214043d
commit 5f8e0da148
3 changed files with 16 additions and 29 deletions
+12 -14
View File
@@ -2,33 +2,31 @@ package gobackend
import "testing"
func TestBuildDownloadedFileCommentKeepsSourceLinkAndAddsCredit(t *testing.T) {
func TestBuildDownloadedFileCommentKeepsSourceComment(t *testing.T) {
const source = "https://music.apple.com/us/album/example/123"
got := buildDownloadedFileComment(source, "https://music.amazon.com/albums/example")
want := source + "\n" + downloadCommentCredit
if got != want {
t.Fatalf("comment = %q, want %q", got, want)
if got != source {
t.Fatalf("comment = %q, want %q", got, source)
}
}
func TestBuildDownloadedFileCommentUsesProviderCommentWhenSourceIsEmpty(t *testing.T) {
const provider = "https://music.amazon.com/albums/example"
got := buildDownloadedFileComment("", provider)
want := provider + "\n" + downloadCommentCredit
if got != want {
t.Fatalf("comment = %q, want %q", got, want)
if got != provider {
t.Fatalf("comment = %q, want %q", got, provider)
}
}
func TestBuildDownloadedFileCommentAddsCreditWithoutLink(t *testing.T) {
if got := buildDownloadedFileComment("", ""); got != downloadCommentCredit {
t.Fatalf("comment = %q, want credit only", got)
func TestBuildDownloadedFileCommentStaysEmptyWithoutProviderComment(t *testing.T) {
if got := buildDownloadedFileComment("", ""); got != "" {
t.Fatalf("comment = %q, want empty", got)
}
}
func TestBuildDownloadedFileCommentDoesNotDuplicateCredit(t *testing.T) {
original := "https://example.test/album/1\n" + downloadCommentCredit
if got := buildDownloadedFileComment(original, ""); got != original {
t.Fatalf("credit was duplicated: %q", got)
func TestBuildDownloadedFileCommentTrimsWhitespace(t *testing.T) {
const original = "https://example.test/album/1"
if got := buildDownloadedFileComment(" "+original+"\r\n", ""); got != original {
t.Fatalf("comment = %q, want %q", got, original)
}
}
+3 -13
View File
@@ -133,22 +133,12 @@ type DownloadResult struct {
RequiresContainerConversion bool
}
const downloadCommentCredit = "Downloaded with SpotiFLAC Mobile. Enjoy your music!"
func buildDownloadedFileComment(sourceComment, providerComment string) string {
comment := strings.TrimSpace(sourceComment)
if comment == "" {
comment = strings.TrimSpace(providerComment)
if comment != "" {
return comment
}
for _, line := range strings.Split(strings.ReplaceAll(comment, "\r\n", "\n"), "\n") {
if strings.EqualFold(strings.TrimSpace(line), downloadCommentCredit) {
return comment
}
}
if comment == "" {
return downloadCommentCredit
}
return comment + "\n" + downloadCommentCredit
return strings.TrimSpace(providerComment)
}
func buildDownloadSuccessResponse(
@@ -34,9 +34,8 @@ func TestOverlayExtensionReleaseMetadataFillsMissingRequestFields(t *testing.T)
"song.m4a",
false,
)
expectedComment := track.Comment + "\n" + downloadCommentCredit
if response.UPC != track.UPC || response.AlbumType != "single" ||
!response.Explicit || response.Comment != expectedComment {
!response.Explicit || response.Comment != track.Comment {
t.Fatalf("enriched metadata was lost in download response: %#v", response)
}
}