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" import "testing"
func TestBuildDownloadedFileCommentKeepsSourceLinkAndAddsCredit(t *testing.T) { func TestBuildDownloadedFileCommentKeepsSourceComment(t *testing.T) {
const source = "https://music.apple.com/us/album/example/123" const source = "https://music.apple.com/us/album/example/123"
got := buildDownloadedFileComment(source, "https://music.amazon.com/albums/example") got := buildDownloadedFileComment(source, "https://music.amazon.com/albums/example")
want := source + "\n" + downloadCommentCredit if got != source {
if got != want { t.Fatalf("comment = %q, want %q", got, source)
t.Fatalf("comment = %q, want %q", got, want)
} }
} }
func TestBuildDownloadedFileCommentUsesProviderCommentWhenSourceIsEmpty(t *testing.T) { func TestBuildDownloadedFileCommentUsesProviderCommentWhenSourceIsEmpty(t *testing.T) {
const provider = "https://music.amazon.com/albums/example" const provider = "https://music.amazon.com/albums/example"
got := buildDownloadedFileComment("", provider) got := buildDownloadedFileComment("", provider)
want := provider + "\n" + downloadCommentCredit if got != provider {
if got != want { t.Fatalf("comment = %q, want %q", got, provider)
t.Fatalf("comment = %q, want %q", got, want)
} }
} }
func TestBuildDownloadedFileCommentAddsCreditWithoutLink(t *testing.T) { func TestBuildDownloadedFileCommentStaysEmptyWithoutProviderComment(t *testing.T) {
if got := buildDownloadedFileComment("", ""); got != downloadCommentCredit { if got := buildDownloadedFileComment("", ""); got != "" {
t.Fatalf("comment = %q, want credit only", got) t.Fatalf("comment = %q, want empty", got)
} }
} }
func TestBuildDownloadedFileCommentDoesNotDuplicateCredit(t *testing.T) { func TestBuildDownloadedFileCommentTrimsWhitespace(t *testing.T) {
original := "https://example.test/album/1\n" + downloadCommentCredit const original = "https://example.test/album/1"
if got := buildDownloadedFileComment(original, ""); got != original { if got := buildDownloadedFileComment(" "+original+"\r\n", ""); got != original {
t.Fatalf("credit was duplicated: %q", got) t.Fatalf("comment = %q, want %q", got, original)
} }
} }
+3 -13
View File
@@ -133,22 +133,12 @@ type DownloadResult struct {
RequiresContainerConversion bool RequiresContainerConversion bool
} }
const downloadCommentCredit = "Downloaded with SpotiFLAC Mobile. Enjoy your music!"
func buildDownloadedFileComment(sourceComment, providerComment string) string { func buildDownloadedFileComment(sourceComment, providerComment string) string {
comment := strings.TrimSpace(sourceComment) comment := strings.TrimSpace(sourceComment)
if comment == "" { if comment != "" {
comment = strings.TrimSpace(providerComment) return comment
} }
for _, line := range strings.Split(strings.ReplaceAll(comment, "\r\n", "\n"), "\n") { return strings.TrimSpace(providerComment)
if strings.EqualFold(strings.TrimSpace(line), downloadCommentCredit) {
return comment
}
}
if comment == "" {
return downloadCommentCredit
}
return comment + "\n" + downloadCommentCredit
} }
func buildDownloadSuccessResponse( func buildDownloadSuccessResponse(
@@ -34,9 +34,8 @@ func TestOverlayExtensionReleaseMetadataFillsMissingRequestFields(t *testing.T)
"song.m4a", "song.m4a",
false, false,
) )
expectedComment := track.Comment + "\n" + downloadCommentCredit
if response.UPC != track.UPC || response.AlbumType != "single" || 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) t.Fatalf("enriched metadata was lost in download response: %#v", response)
} }
} }