Fix JSONID type conversions for yandex-music-api-go v0.0.0-20261018072517-d0173f795d2a
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:
1 parent
5d32daad07
commit
4e6bef40e3
6 files changed
+23
-21
No files matched your search
@@ -3,7 +3,7 @@ module ym-dl
|
|||||||
go 1.27.2
|
go 1.27.2
|
||||||
|
|
||||||
require (
|
require (
|
||||||
gitea.mrixs.me/Mrixs/yandex-music-api-go v0.0.0-20261018055743-0456ca0665a6
|
gitea.mrixs.me/Mrixs/yandex-music-api-go v0.0.0-20261018072517-d0173f795d2a
|
||||||
github.com/bogem/id3v2 v1.2.0
|
github.com/bogem/id3v2 v1.2.0
|
||||||
gopkg.in/yaml.v3 v3.0.1
|
gopkg.in/yaml.v3 v3.0.1
|
||||||
modernc.org/sqlite v1.60.1
|
modernc.org/sqlite v1.60.1
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ gitea.mrixs.me/Mrixs/yandex-music-api-go v0.0.0-20261014200451-02a6dabcfbea h1:J
|
|||||||
gitea.mrixs.me/Mrixs/yandex-music-api-go v0.0.0-20261014200451-02a6dabcfbea/go.mod h1:L+GcqPRZiu0Srq6+YxfdLztltXV8DcxKjNUOXWJvR9o=
|
gitea.mrixs.me/Mrixs/yandex-music-api-go v0.0.0-20261014200451-02a6dabcfbea/go.mod h1:L+GcqPRZiu0Srq6+YxfdLztltXV8DcxKjNUOXWJvR9o=
|
||||||
gitea.mrixs.me/Mrixs/yandex-music-api-go v0.0.0-20261018055743-0456ca0665a6 h1:3LRfiTAVWsFG6lzkQV7VhUx+uOie/AYk8uPJQISotaQ=
|
gitea.mrixs.me/Mrixs/yandex-music-api-go v0.0.0-20261018055743-0456ca0665a6 h1:3LRfiTAVWsFG6lzkQV7VhUx+uOie/AYk8uPJQISotaQ=
|
||||||
gitea.mrixs.me/Mrixs/yandex-music-api-go v0.0.0-20261018055743-0456ca0665a6/go.mod h1:L+GcqPRZiu0Srq6+YxfdLztltXV8DcxKjNUOXWJvR9o=
|
gitea.mrixs.me/Mrixs/yandex-music-api-go v0.0.0-20261018055743-0456ca0665a6/go.mod h1:L+GcqPRZiu0Srq6+YxfdLztltXV8DcxKjNUOXWJvR9o=
|
||||||
|
gitea.mrixs.me/Mrixs/yandex-music-api-go v0.0.0-20261018072517-d0173f795d2a h1:y+XHpnxtn2xiXx735itwB83X82dOPfwbzCqZ5/WlBs4=
|
||||||
|
gitea.mrixs.me/Mrixs/yandex-music-api-go v0.0.0-20261018072517-d0173f795d2a/go.mod h1:L+GcqPRZiu0Srq6+YxfdLztltXV8DcxKjNUOXWJvR9o=
|
||||||
github.com/bogem/id3v2 v1.2.0 h1:hKDF+F1gOgQ5r1QmBCEZUk4MveJbKxCeIDSBU7CQ4oI=
|
github.com/bogem/id3v2 v1.2.0 h1:hKDF+F1gOgQ5r1QmBCEZUk4MveJbKxCeIDSBU7CQ4oI=
|
||||||
github.com/bogem/id3v2 v1.2.0/go.mod h1:t78PK5AQ56Q47kizpYiV6gtjj3jfxlz87oFpty8DYs8=
|
github.com/bogem/id3v2 v1.2.0/go.mod h1:t78PK5AQ56Q47kizpYiV6gtjj3jfxlz87oFpty8DYs8=
|
||||||
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
|
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
|
||||||
|
|||||||
@@ -157,21 +157,21 @@ func (d *Downloader) DownloadAlbum(ctx context.Context, albumID string) []Downlo
|
|||||||
for i, volume := range album.Volumes {
|
for i, volume := range album.Volumes {
|
||||||
for j := range volume {
|
for j := range volume {
|
||||||
track := &volume[j]
|
track := &volume[j]
|
||||||
if track.ID == "" || !track.Available {
|
if string(track.ID) == "" || !track.Available {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get download URL (handles XML parsing and URL signing)
|
// 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 {
|
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
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get download info for metadata
|
// 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 {
|
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
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -202,19 +202,19 @@ func (d *Downloader) DownloadAlbum(ctx context.Context, albumID string) []Downlo
|
|||||||
// Download audio
|
// Download audio
|
||||||
audioData, err := d.downloadFile(ctx, downloadURL)
|
audioData, err := d.downloadFile(ctx, downloadURL)
|
||||||
if err != nil {
|
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
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save track
|
// Save track
|
||||||
if err := d.storage.SaveTrack(trackMeta, audioData, coverData); err != nil {
|
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
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
savedMeta, _ := d.storage.GetTrackMeta(track.ID)
|
savedMeta, _ := d.storage.GetTrackMeta(string(track.ID))
|
||||||
results = append(results, DownloadResult{
|
results = append(results, DownloadResult{
|
||||||
TrackID: track.ID,
|
TrackID: string(track.ID),
|
||||||
AlbumID: albumID,
|
AlbumID: albumID,
|
||||||
Success: true,
|
Success: true,
|
||||||
TrackMeta: savedMeta,
|
TrackMeta: savedMeta,
|
||||||
|
|||||||
@@ -152,9 +152,9 @@ func (m *Monitor) checkArtistTracks(ctx context.Context, artistID int, artistNam
|
|||||||
|
|
||||||
newTracks := 0
|
newTracks := 0
|
||||||
for _, track := range tracks {
|
for _, track := range tracks {
|
||||||
if !m.storage.IsTrackDownloaded(track.ID) {
|
if !m.storage.IsTrackDownloaded(string(track.ID)) {
|
||||||
m.logger.Info("new track found", "track_id", track.ID, "artist", artistName)
|
m.logger.Info("new track found", "track_id", string(track.ID), "artist", artistName)
|
||||||
result := m.downloader.DownloadTrack(ctx, track.ID)
|
result := m.downloader.DownloadTrack(ctx, string(track.ID))
|
||||||
if result.Success {
|
if result.Success {
|
||||||
newTracks++
|
newTracks++
|
||||||
} else {
|
} else {
|
||||||
@@ -190,10 +190,10 @@ func (m *Monitor) checkArtistAlbums(ctx context.Context, artistID int, artistNam
|
|||||||
|
|
||||||
newAlbums := 0
|
newAlbums := 0
|
||||||
for _, album := range albums {
|
for _, album := range albums {
|
||||||
albumIDStr := album.ID
|
albumIDStr := string(album.ID)
|
||||||
if !m.isAlbumDownloaded(albumIDStr, album.TrackCount) {
|
if !m.isAlbumDownloaded(albumIDStr, album.TrackCount) {
|
||||||
m.logger.Info("new album found", "album_id", albumIDStr, "title", album.Title, "artist", artistName)
|
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
|
success := false
|
||||||
for _, r := range results {
|
for _, r := range results {
|
||||||
if r.Success {
|
if r.Success {
|
||||||
|
|||||||
@@ -536,7 +536,7 @@ func BuildTrackMetaFromYandex(track *yandexmusic.Track, album *yandexmusic.Album
|
|||||||
var albumGenre, albumLabel, albumDesc, albumReleaseDate, albumCopyright string
|
var albumGenre, albumLabel, albumDesc, albumReleaseDate, albumCopyright string
|
||||||
if album != nil {
|
if album != nil {
|
||||||
albumTitle = album.Title
|
albumTitle = album.Title
|
||||||
albumID = album.ID
|
albumID = string(album.ID)
|
||||||
year = album.Year
|
year = album.Year
|
||||||
albumGenre = album.Genre
|
albumGenre = album.Genre
|
||||||
albumLabel = album.Label
|
albumLabel = album.Label
|
||||||
@@ -547,7 +547,7 @@ func BuildTrackMetaFromYandex(track *yandexmusic.Track, album *yandexmusic.Album
|
|||||||
}
|
}
|
||||||
} else if len(track.Albums) > 0 {
|
} else if len(track.Albums) > 0 {
|
||||||
albumTitle = track.Albums[0].Title
|
albumTitle = track.Albums[0].Title
|
||||||
albumID = track.Albums[0].ID
|
albumID = string(track.Albums[0].ID)
|
||||||
year = track.Albums[0].Year
|
year = track.Albums[0].Year
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -590,7 +590,7 @@ func BuildTrackMetaFromYandex(track *yandexmusic.Track, album *yandexmusic.Album
|
|||||||
}
|
}
|
||||||
|
|
||||||
return TrackMeta{
|
return TrackMeta{
|
||||||
TrackID: track.ID,
|
TrackID: string(track.ID),
|
||||||
AlbumID: albumID,
|
AlbumID: albumID,
|
||||||
ArtistID: artistID,
|
ArtistID: artistID,
|
||||||
Title: track.Title,
|
Title: track.Title,
|
||||||
@@ -630,7 +630,7 @@ func BuildAlbumMetaFromYandex(album *yandexmusic.Album, tracks []TrackMeta) Albu
|
|||||||
}
|
}
|
||||||
|
|
||||||
return AlbumMeta{
|
return AlbumMeta{
|
||||||
AlbumID: album.ID,
|
AlbumID: string(album.ID),
|
||||||
ArtistID: artistID,
|
ArtistID: artistID,
|
||||||
Title: album.Title,
|
Title: album.Title,
|
||||||
ArtistName: artistName,
|
ArtistName: artistName,
|
||||||
|
|||||||
@@ -123,14 +123,14 @@ func (c *YandexClient) GetTrackInfoWithPosition(ctx context.Context, trackID str
|
|||||||
// Extract track position from first album
|
// Extract track position from first album
|
||||||
var position *TrackPosition
|
var position *TrackPosition
|
||||||
if len(track.Albums) > 0 {
|
if len(track.Albums) > 0 {
|
||||||
albumID := track.Albums[0].ID
|
albumID := string(track.Albums[0].ID)
|
||||||
albums, err := c.client.GetAlbumsWithTracks(ctx, []string{albumID})
|
albums, err := c.client.GetAlbumsWithTracks(ctx, []string{albumID})
|
||||||
if err == nil && len(albums) > 0 {
|
if err == nil && len(albums) > 0 {
|
||||||
album := albums[0]
|
album := albums[0]
|
||||||
// Find track in album.Volumes and get position
|
// Find track in album.Volumes and get position
|
||||||
for volIdx, volume := range album.Volumes {
|
for volIdx, volume := range album.Volumes {
|
||||||
for trackIdx, t := range volume {
|
for trackIdx, t := range volume {
|
||||||
if t.ID == trackID {
|
if string(t.ID) == trackID {
|
||||||
position = &TrackPosition{
|
position = &TrackPosition{
|
||||||
Volume: volIdx + 1,
|
Volume: volIdx + 1,
|
||||||
Index: trackIdx + 1,
|
Index: trackIdx + 1,
|
||||||
|
|||||||
Reference in new issue
Block a user