diff --git a/go_backend/download_comment_test.go b/go_backend/download_comment_test.go index f156d5df..6b7232b1 100644 --- a/go_backend/download_comment_test.go +++ b/go_backend/download_comment_test.go @@ -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) } } diff --git a/go_backend/exports_download.go b/go_backend/exports_download.go index c2acd7e8..abe7a56b 100644 --- a/go_backend/exports_download.go +++ b/go_backend/exports_download.go @@ -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( diff --git a/go_backend/extension_fallback_metadata_test.go b/go_backend/extension_fallback_metadata_test.go index 4f2780be..7b978c25 100644 --- a/go_backend/extension_fallback_metadata_test.go +++ b/go_backend/extension_fallback_metadata_test.go @@ -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) } }