Fix JSONID type conversions for yandex-music-api-go v0.0.0-20261018072517-d0173f795d2a
CI/CD / test (push) Successful in 48s
CI/CD / build (push) Successful in 54s
CI/CD / docker (push) Successful in 2m31s

The new library version uses models.JSONID (custom string type) for ID
fields instead of plain string. Convert to string where IDs are passed
to functions expecting string or compared with string values.

Affected: client.go (GetTrackInfoWithPosition), downloader.go
(track.ID usage), monitor.go (track.ID, album.ID usage), storage.go
(album/track ID assignment).
This commit is contained in:
Mrixs committed 2026-10-18 10:39:43 +03:00
1 parent 5d32daad07
commit 4e6bef40e3
6 files changed
+23 -21

No files matched your search

+9 -9
View File
@@ -157,21 +157,21 @@ func (d *Downloader) DownloadAlbum(ctx context.Context, albumID string) []Downlo
for i, volume := range album.Volumes {
for j := range volume {
track := &volume[j]
if track.ID == "" || !track.Available {
if string(track.ID) == "" || !track.Available {
continue
}
// Get download URL (handles XML parsing and URL signing)
downloadURL, err := d.yandexClient.GetTrackDownloadURL(ctx, track.ID)
downloadURL, err := d.yandexClient.GetTrackDownloadURL(ctx, string(track.ID))
if err != nil {
results = append(results, DownloadResult{TrackID: track.ID, Success: false, Error: fmt.Errorf("get download URL: %w", err)})
results = append(results, DownloadResult{TrackID: string(track.ID), Success: false, Error: fmt.Errorf("get download URL: %w", err)})
continue
}
// Get download info for metadata
downloadInfos, err := d.yandexClient.GetTrackDownloadInfo(ctx, track.ID)
downloadInfos, err := d.yandexClient.GetTrackDownloadInfo(ctx, string(track.ID))
if err != nil {
results = append(results, DownloadResult{TrackID: track.ID, Success: false, Error: fmt.Errorf("get download info: %w", err)})
results = append(results, DownloadResult{TrackID: string(track.ID), Success: false, Error: fmt.Errorf("get download info: %w", err)})
continue
}
@@ -202,19 +202,19 @@ func (d *Downloader) DownloadAlbum(ctx context.Context, albumID string) []Downlo
// Download audio
audioData, err := d.downloadFile(ctx, downloadURL)
if err != nil {
results = append(results, DownloadResult{TrackID: track.ID, Success: false, Error: fmt.Errorf("download audio: %w", err)})
results = append(results, DownloadResult{TrackID: string(track.ID), Success: false, Error: fmt.Errorf("download audio: %w", err)})
continue
}
// Save track
if err := d.storage.SaveTrack(trackMeta, audioData, coverData); err != nil {
results = append(results, DownloadResult{TrackID: track.ID, Success: false, Error: fmt.Errorf("save track: %w", err)})
results = append(results, DownloadResult{TrackID: string(track.ID), Success: false, Error: fmt.Errorf("save track: %w", err)})
continue
}
savedMeta, _ := d.storage.GetTrackMeta(track.ID)
savedMeta, _ := d.storage.GetTrackMeta(string(track.ID))
results = append(results, DownloadResult{
TrackID: track.ID,
TrackID: string(track.ID),
AlbumID: albumID,
Success: true,
TrackMeta: savedMeta,
+5 -5
View File
@@ -152,9 +152,9 @@ func (m *Monitor) checkArtistTracks(ctx context.Context, artistID int, artistNam
newTracks := 0
for _, track := range tracks {
if !m.storage.IsTrackDownloaded(track.ID) {
m.logger.Info("new track found", "track_id", track.ID, "artist", artistName)
result := m.downloader.DownloadTrack(ctx, track.ID)
if !m.storage.IsTrackDownloaded(string(track.ID)) {
m.logger.Info("new track found", "track_id", string(track.ID), "artist", artistName)
result := m.downloader.DownloadTrack(ctx, string(track.ID))
if result.Success {
newTracks++
} else {
@@ -190,10 +190,10 @@ func (m *Monitor) checkArtistAlbums(ctx context.Context, artistID int, artistNam
newAlbums := 0
for _, album := range albums {
albumIDStr := album.ID
albumIDStr := string(album.ID)
if !m.isAlbumDownloaded(albumIDStr, album.TrackCount) {
m.logger.Info("new album found", "album_id", albumIDStr, "title", album.Title, "artist", artistName)
results := m.downloader.DownloadAlbum(ctx, album.ID)
results := m.downloader.DownloadAlbum(ctx, string(album.ID))
success := false
for _, r := range results {
if r.Success {
+4 -4
View File
@@ -536,7 +536,7 @@ func BuildTrackMetaFromYandex(track *yandexmusic.Track, album *yandexmusic.Album
var albumGenre, albumLabel, albumDesc, albumReleaseDate, albumCopyright string
if album != nil {
albumTitle = album.Title
albumID = album.ID
albumID = string(album.ID)
year = album.Year
albumGenre = album.Genre
albumLabel = album.Label
@@ -547,7 +547,7 @@ func BuildTrackMetaFromYandex(track *yandexmusic.Track, album *yandexmusic.Album
}
} else if len(track.Albums) > 0 {
albumTitle = track.Albums[0].Title
albumID = track.Albums[0].ID
albumID = string(track.Albums[0].ID)
year = track.Albums[0].Year
}
@@ -590,7 +590,7 @@ func BuildTrackMetaFromYandex(track *yandexmusic.Track, album *yandexmusic.Album
}
return TrackMeta{
TrackID: track.ID,
TrackID: string(track.ID),
AlbumID: albumID,
ArtistID: artistID,
Title: track.Title,
@@ -630,7 +630,7 @@ func BuildAlbumMetaFromYandex(album *yandexmusic.Album, tracks []TrackMeta) Albu
}
return AlbumMeta{
AlbumID: album.ID,
AlbumID: string(album.ID),
ArtistID: artistID,
Title: album.Title,
ArtistName: artistName,
+2 -2
View File
@@ -123,14 +123,14 @@ func (c *YandexClient) GetTrackInfoWithPosition(ctx context.Context, trackID str
// Extract track position from first album
var position *TrackPosition
if len(track.Albums) > 0 {
albumID := track.Albums[0].ID
albumID := string(track.Albums[0].ID)
albums, err := c.client.GetAlbumsWithTracks(ctx, []string{albumID})
if err == nil && len(albums) > 0 {
album := albums[0]
// Find track in album.Volumes and get position
for volIdx, volume := range album.Volumes {
for trackIdx, t := range volume {
if t.ID == trackID {
if string(t.ID) == trackID {
position = &TrackPosition{
Volume: volIdx + 1,
Index: trackIdx + 1,