This repository has been archived by the owner on Apr 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
artist_credit.go
64 lines (59 loc) · 1.97 KB
/
artist_credit.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright 2022 Daniel Erat.
// All rights reserved.
package seed
import (
"fmt"
"net/url"
)
// ArtistCredit holds detailed information about a credited artist.
type ArtistCredit struct {
// MBID contains the artist entity's MBID, if known.
// This annoyingly doesn't seem to work for the /recording/create form,
// so ID should be set instead in that case (see the db package).
MBID string
// ID contains the artist's database ID (i.e. the 'id' column from the 'artist' table).
// This is only needed for the /recording/create form, I think.
ID int32
// Name contains the artist's name for pre-filling the search field.
// This is unneeded if MBID or ID is set.
Name string
// NameAsCredited contains the name under which the artist was credited.
// This is only needed if it's different than MBID or Name.
// TODO: Actually, it seems like Name is maybe ignored in favor of NameAsCredited
// when seeding the standalone recording form? Investigate further.
NameAsCredited string
// JoinPhrase contains text for joining this artist's name with the next one's, e.g. " & ".
JoinPhrase string
}
// setParams sets query parameters in vals corresponding to non-empty fields in ac.
// The supplied prefix (e.g. "artist_credit.names.0.") is prepended before each parameter name.
func (ac *ArtistCredit) setParams(vals url.Values, prefix string) {
var id string
if ac.ID > 0 {
id = fmt.Sprint(ac.ID)
}
setParams(vals, map[string]string{
"artist.id": id,
"mbid": ac.MBID,
"artist.name": ac.Name,
"name": ac.NameAsCredited,
"join_phrase": ac.JoinPhrase,
}, prefix)
}
// artistCreditsDesc summarizes acs for Edit.Description implementations.
func artistCreditsDesc(acs []ArtistCredit) string {
var s string
for _, ac := range acs {
if ac.NameAsCredited != "" {
s += ac.NameAsCredited
} else if ac.Name != "" {
s += ac.Name
} else if ac.MBID != "" {
s += truncate(ac.MBID, mbidPrefixLen, false)
} else {
continue
}
s += ac.JoinPhrase
}
return s
}