Fix R128 and remaining ID fields to accept both JSON types

- Track.R128 and TrackShort.R128: float64 → JSONR128 (accepts both JSON number and object)
- All remaining primary ID fields: string → JSONID (accepts both JSON string and number)
  Fixed in: account, artist, clip, concert, feed, label, landing, metatag,
  music_history, pin, queue, radio, search, settings, supplement
This commit is contained in:
Mrixs committed 2026-10-18 11:01:26 +03:00
1 parent d0173f795d
commit dbb823ade3
18 files changed
+75 -44

No files matched your search

+31
View File
@@ -110,3 +110,34 @@ func (id *JSONID) UnmarshalJSON(data []byte) error {
func (id JSONID) String() string {
return string(id)
}
// JSONR128 is a flexible R128 loudness normalization value that accepts both JSON numbers and objects.
// The Yandex Music API sometimes returns r128 as a number (e.g., -23.5) and sometimes
// as an object (e.g., {"value": -23.5}). JSONR128 accepts both and stores as float64.
type JSONR128 float64
// UnmarshalJSON implements json.Unmarshaler, accepting both JSON numbers and objects.
func (r *JSONR128) UnmarshalJSON(data []byte) error {
// Try float64 first
var f float64
if err := json.Unmarshal(data, &f); err == nil {
*r = JSONR128(f)
return nil
}
// Try object with "value" key
var obj struct {
Value float64 `json:"value"`
}
if err := json.Unmarshal(data, &obj); err == nil {
*r = JSONR128(obj.Value)
return nil
}
// Default to 0 if neither format works
*r = 0
return nil
}
// Float64 returns the R128 value as a float64.
func (r JSONR128) Float64() float64 {
return float64(r)
}