fix: address code review findings
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"golang.org/x/time/rate"
|
||||
@@ -93,13 +94,27 @@ type mbArtistCredit struct {
|
||||
|
||||
// mbReleaseGroup represents the XML structure of a single release-group
|
||||
// in the MusicBrainz release-group list response.
|
||||
//
|
||||
// Note: release groups do NOT carry a "status" attribute in ws/2 (status
|
||||
// belongs to individual releases, not release groups), so it is intentionally
|
||||
// absent here. Type classification is read from the authoritative
|
||||
// <primary-type> / <secondary-type-list> elements rather than the legacy
|
||||
// "type" attribute, which only reflects the primary type and cannot detect
|
||||
// e.g. a compilation whose primary type is Album.
|
||||
type mbReleaseGroup struct {
|
||||
ID string `xml:"id,attr"`
|
||||
Title string `xml:"title"`
|
||||
Type string `xml:"type,attr"`
|
||||
Status string `xml:"status,attr"`
|
||||
ArtistCredit mbArtistCredit `xml:"artist-credit"`
|
||||
ReleaseDate string `xml:"first-release-date"`
|
||||
ID string `xml:"id,attr"`
|
||||
Title string `xml:"title"`
|
||||
TypeAttr string `xml:"type,attr"`
|
||||
PrimaryType string `xml:"primary-type"`
|
||||
Secondary mbSecondaryTypes `xml:"secondary-type-list"`
|
||||
ArtistCredit mbArtistCredit `xml:"artist-credit"`
|
||||
ReleaseDate string `xml:"first-release-date"`
|
||||
}
|
||||
|
||||
// mbSecondaryTypes captures the <secondary-type-list> element, which holds
|
||||
// zero or more <secondary-type> children (e.g. Live, Compilation, Remix).
|
||||
type mbSecondaryTypes struct {
|
||||
Types []string `xml:"secondary-type"`
|
||||
}
|
||||
|
||||
// mbReleaseGroupListXML wraps the release-group-list element to properly
|
||||
@@ -127,14 +142,22 @@ func ParseReleaseGroups(data []byte) (*ParsedReleaseGroups, error) {
|
||||
Count: list.ReleaseGroupList.Count,
|
||||
}
|
||||
for _, rg := range list.ReleaseGroupList.ReleaseGroups {
|
||||
// Prefer the authoritative <primary-type> element; fall back to the
|
||||
// legacy "type" attribute (which reflects the primary type) when the
|
||||
// element is absent. The attribute is space-separated primary+secondary,
|
||||
// so take the first token as the primary type.
|
||||
primary := rg.PrimaryType
|
||||
if primary == "" && rg.TypeAttr != "" {
|
||||
primary = strings.Fields(rg.TypeAttr)[0]
|
||||
}
|
||||
result.ReleaseGroups = append(result.ReleaseGroups, ReleaseGroup{
|
||||
ID: rg.ID,
|
||||
Title: rg.Title,
|
||||
Type: rg.Type,
|
||||
Status: rg.Status,
|
||||
ArtistID: rg.ArtistCredit.NameCredit.Artist.ID,
|
||||
ArtistName: rg.ArtistCredit.NameCredit.Artist.Name,
|
||||
ReleaseDate: rg.ReleaseDate,
|
||||
ID: rg.ID,
|
||||
Title: rg.Title,
|
||||
Type: primary,
|
||||
SecondaryTypes: rg.Secondary.Types,
|
||||
ArtistID: rg.ArtistCredit.NameCredit.Artist.ID,
|
||||
ArtistName: rg.ArtistCredit.NameCredit.Artist.Name,
|
||||
ReleaseDate: rg.ReleaseDate,
|
||||
})
|
||||
}
|
||||
return result, nil
|
||||
|
||||
Reference in New Issue
Block a user