mirror of
https://git.sr.ht/~joren/streamrip-go
synced 2026-08-17 09:38:39 +02:00
fix: playlist cover art, compilation tag, and year
- ripPlaylist/ripTrackCollection: pre-fetch playlist artwork once, embed in all tracks - ripTrack: skip per-track album cover when playlist embed is provided - buildTagMetadata: set COMPILATION=1 and year from playlist publish_date - beatport: normalize playlistMetadata to include date fields for year extraction - qobuz: normalize playlist image_rectangle to standard image map
This commit is contained in:
+44
-5
@@ -11,6 +11,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
"streamrip-go/internal/artwork"
|
"streamrip-go/internal/artwork"
|
||||||
"streamrip-go/internal/audio/convert"
|
"streamrip-go/internal/audio/convert"
|
||||||
@@ -58,6 +59,7 @@ type ripTrackOptions struct {
|
|||||||
forPlaylist bool
|
forPlaylist bool
|
||||||
playlistName string
|
playlistName string
|
||||||
playlistPos int
|
playlistPos int
|
||||||
|
playlistYear int
|
||||||
}
|
}
|
||||||
|
|
||||||
type folderAudioValues struct {
|
type folderAudioValues struct {
|
||||||
@@ -372,14 +374,22 @@ func (m *Main) ripTrackCollection(ctx context.Context, p provider.Client, source
|
|||||||
ids = append(ids, id)
|
ids = append(ids, id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
var artRes artwork.Result
|
||||||
|
var playlistYear int
|
||||||
|
if playlistLike {
|
||||||
|
artRes, _ = artwork.Prepare(ctx, m.DL, folder, meta, m.Config.Session.Artwork, true)
|
||||||
|
playlistYear = extractYear(meta)
|
||||||
|
}
|
||||||
|
|
||||||
m.logf("%s: %s (%d tracks)\n", kind, name, len(ids))
|
m.logf("%s: %s (%d tracks)\n", kind, name, len(ids))
|
||||||
failures := 0
|
failures := 0
|
||||||
runOne := func(i int, trackID string) {
|
runOne := func(i int, trackID string) {
|
||||||
opts := ripTrackOptions{albumFolder: folder, index: i, total: len(ids)}
|
opts := ripTrackOptions{albumFolder: folder, albumEmbedCover: artRes.EmbedPath, index: i, total: len(ids)}
|
||||||
if playlistLike {
|
if playlistLike {
|
||||||
opts.forPlaylist = true
|
opts.forPlaylist = true
|
||||||
opts.playlistName = name
|
opts.playlistName = name
|
||||||
opts.playlistPos = i
|
opts.playlistPos = i
|
||||||
|
opts.playlistYear = playlistYear
|
||||||
}
|
}
|
||||||
if err := m.ripTrack(ctx, p, source, trackID, "", opts); err != nil {
|
if err := m.ripTrack(ctx, p, source, trackID, "", opts); err != nil {
|
||||||
failures++
|
failures++
|
||||||
@@ -404,11 +414,12 @@ func (m *Main) ripTrackCollection(ctx context.Context, p provider.Client, source
|
|||||||
go func(pos int, tid string) {
|
go func(pos int, tid string) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
defer func() { <-sem }()
|
defer func() { <-sem }()
|
||||||
opts := ripTrackOptions{albumFolder: folder, index: pos, total: len(ids)}
|
opts := ripTrackOptions{albumFolder: folder, albumEmbedCover: artRes.EmbedPath, index: pos, total: len(ids)}
|
||||||
if playlistLike {
|
if playlistLike {
|
||||||
opts.forPlaylist = true
|
opts.forPlaylist = true
|
||||||
opts.playlistName = name
|
opts.playlistName = name
|
||||||
opts.playlistPos = pos
|
opts.playlistPos = pos
|
||||||
|
opts.playlistYear = playlistYear
|
||||||
}
|
}
|
||||||
if err := m.ripTrack(ctx, p, source, tid, "", opts); err != nil {
|
if err := m.ripTrack(ctx, p, source, tid, "", opts); err != nil {
|
||||||
mu.Lock()
|
mu.Lock()
|
||||||
@@ -806,6 +817,10 @@ func (m *Main) ripPlaylist(ctx context.Context, p provider.Client, source, playl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
artRes, _ := artwork.Prepare(ctx, m.DL, folder, playlistMeta, m.Config.Session.Artwork, true)
|
||||||
|
|
||||||
|
playlistYear := extractYear(playlistMeta)
|
||||||
|
|
||||||
total := len(ids)
|
total := len(ids)
|
||||||
m.logf("Playlist: %s (%d tracks)\n", name, total)
|
m.logf("Playlist: %s (%d tracks)\n", name, total)
|
||||||
failures := 0
|
failures := 0
|
||||||
@@ -813,11 +828,13 @@ func (m *Main) ripPlaylist(ctx context.Context, p provider.Client, source, playl
|
|||||||
runOne := func(i int, id string) {
|
runOne := func(i int, id string) {
|
||||||
opts := ripTrackOptions{
|
opts := ripTrackOptions{
|
||||||
albumFolder: folder,
|
albumFolder: folder,
|
||||||
|
albumEmbedCover: artRes.EmbedPath,
|
||||||
index: i,
|
index: i,
|
||||||
total: total,
|
total: total,
|
||||||
forPlaylist: true,
|
forPlaylist: true,
|
||||||
playlistName: name,
|
playlistName: name,
|
||||||
playlistPos: i,
|
playlistPos: i,
|
||||||
|
playlistYear: playlistYear,
|
||||||
}
|
}
|
||||||
if err := m.ripTrack(ctx, p, source, id, "", opts); err != nil {
|
if err := m.ripTrack(ctx, p, source, id, "", opts); err != nil {
|
||||||
failures++
|
failures++
|
||||||
@@ -843,7 +860,7 @@ func (m *Main) ripPlaylist(ctx context.Context, p provider.Client, source, playl
|
|||||||
go func(pos int, tid string) {
|
go func(pos int, tid string) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
defer func() { <-sem }()
|
defer func() { <-sem }()
|
||||||
opts := ripTrackOptions{albumFolder: folder, index: pos, total: total, forPlaylist: true, playlistName: name, playlistPos: pos}
|
opts := ripTrackOptions{albumFolder: folder, albumEmbedCover: artRes.EmbedPath, index: pos, total: total, forPlaylist: true, playlistName: name, playlistPos: pos, playlistYear: playlistYear}
|
||||||
if err := m.ripTrack(ctx, p, source, tid, "", opts); err != nil {
|
if err := m.ripTrack(ctx, p, source, tid, "", opts); err != nil {
|
||||||
mu.Lock()
|
mu.Lock()
|
||||||
failures++
|
failures++
|
||||||
@@ -1010,7 +1027,7 @@ func (m *Main) ripTrack(ctx context.Context, p provider.Client, source, id, fall
|
|||||||
downloaded:
|
downloaded:
|
||||||
|
|
||||||
embedCoverPath := opts.albumEmbedCover
|
embedCoverPath := opts.albumEmbedCover
|
||||||
if opts.forPlaylist {
|
if opts.forPlaylist && embedCoverPath == "" {
|
||||||
parent := opts.albumFolder
|
parent := opts.albumFolder
|
||||||
if parent == "" {
|
if parent == "" {
|
||||||
parent = filepath.Dir(outPath)
|
parent = filepath.Dir(outPath)
|
||||||
@@ -1020,7 +1037,7 @@ downloaded:
|
|||||||
embedCoverPath = res.EmbedPath
|
embedCoverPath = res.EmbedPath
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if embedCoverPath == "" {
|
} else if !opts.forPlaylist && embedCoverPath == "" {
|
||||||
parent := opts.albumFolder
|
parent := opts.albumFolder
|
||||||
if parent == "" {
|
if parent == "" {
|
||||||
parent = filepath.Dir(outPath)
|
parent = filepath.Dir(outPath)
|
||||||
@@ -1473,7 +1490,9 @@ func buildTagMetadata(trackMeta map[string]any, title, source, trackID string, o
|
|||||||
Artist: artist,
|
Artist: artist,
|
||||||
Artists: artistNames,
|
Artists: artistNames,
|
||||||
AlbumArtist: albumArtist,
|
AlbumArtist: albumArtist,
|
||||||
|
Compilation: opts.forPlaylist,
|
||||||
OmitDiscTags: opts.forPlaylist,
|
OmitDiscTags: opts.forPlaylist,
|
||||||
|
Year: opts.playlistYear,
|
||||||
TrackNumber: trackNumber,
|
TrackNumber: trackNumber,
|
||||||
DiscNumber: discNumber,
|
DiscNumber: discNumber,
|
||||||
TrackTotal: trackTotal,
|
TrackTotal: trackTotal,
|
||||||
@@ -1646,3 +1665,23 @@ func displayArtistNames(names []string) string {
|
|||||||
return strings.Join(names[:len(names)-1], ", ") + " & " + names[len(names)-1]
|
return strings.Join(names[:len(names)-1], ", ") + " & " + names[len(names)-1]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func extractYear(meta map[string]any) int {
|
||||||
|
date := jsonutil.FirstNonEmpty(
|
||||||
|
jsonutil.StringFromAny(meta["publish_date"]),
|
||||||
|
jsonutil.StringFromAny(meta["creation_date"]),
|
||||||
|
jsonutil.StringFromAny(meta["created_at"]),
|
||||||
|
jsonutil.StringFromAny(meta["release_date"]),
|
||||||
|
jsonutil.StringFromAny(meta["new_release_date"]),
|
||||||
|
)
|
||||||
|
if date == "" {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
if t, err := time.Parse(time.RFC3339, date); err == nil {
|
||||||
|
return t.Year()
|
||||||
|
}
|
||||||
|
if t, err := time.Parse("2006-01-02", date); err == nil {
|
||||||
|
return t.Year()
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|||||||
@@ -16,7 +16,9 @@ type Metadata struct {
|
|||||||
Artist string
|
Artist string
|
||||||
Artists []string
|
Artists []string
|
||||||
AlbumArtist string
|
AlbumArtist string
|
||||||
|
Compilation bool
|
||||||
OmitDiscTags bool
|
OmitDiscTags bool
|
||||||
|
Year int
|
||||||
TrackNumber int
|
TrackNumber int
|
||||||
DiscNumber int
|
DiscNumber int
|
||||||
TrackTotal int
|
TrackTotal int
|
||||||
@@ -197,6 +199,12 @@ func toTags(meta Metadata) map[string]string {
|
|||||||
if meta.DiscTotal > 0 {
|
if meta.DiscTotal > 0 {
|
||||||
tags["disctotal"] = strconv.Itoa(meta.DiscTotal)
|
tags["disctotal"] = strconv.Itoa(meta.DiscTotal)
|
||||||
}
|
}
|
||||||
|
if meta.Compilation {
|
||||||
|
tags["COMPILATION"] = "1"
|
||||||
|
}
|
||||||
|
if meta.Year > 0 {
|
||||||
|
tags["year"] = strconv.Itoa(meta.Year)
|
||||||
|
}
|
||||||
return tags
|
return tags
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -615,6 +615,9 @@ func playlistMetadata(raw map[string]any, tracks []any) map[string]any {
|
|||||||
"title": name,
|
"title": name,
|
||||||
"tracks_count": firstPositiveInt(jsonutil.IntFromAny(raw["track_count"]), len(tracks)),
|
"tracks_count": firstPositiveInt(jsonutil.IntFromAny(raw["track_count"]), len(tracks)),
|
||||||
"image": imageMap(raw["image"]),
|
"image": imageMap(raw["image"]),
|
||||||
|
"publish_date": jsonutil.StringFromAny(raw["publish_date"]),
|
||||||
|
"new_release_date": jsonutil.StringFromAny(raw["new_release_date"]),
|
||||||
|
"release_date": jsonutil.StringFromAny(raw["release_date"]),
|
||||||
"tracks": map[string]any{"items": tracks},
|
"tracks": map[string]any{"items": tracks},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -613,11 +613,13 @@ func (c *Client) getPlaylist(ctx context.Context, playlistID string) (map[string
|
|||||||
|
|
||||||
total, _ := intValue(resp["tracks_count"])
|
total, _ := intValue(resp["tracks_count"])
|
||||||
if total <= pageLimit {
|
if total <= pageLimit {
|
||||||
|
normalizePlaylistImage(resp)
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
tracksObj, ok := mapValue(resp["tracks"])
|
tracksObj, ok := mapValue(resp["tracks"])
|
||||||
if !ok {
|
if !ok {
|
||||||
|
normalizePlaylistImage(resp)
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
items, ok := tracksObj["items"].([]any)
|
items, ok := tracksObj["items"].([]any)
|
||||||
@@ -653,9 +655,25 @@ func (c *Client) getPlaylist(ctx context.Context, playlistID string) (map[string
|
|||||||
|
|
||||||
tracksObj["items"] = items
|
tracksObj["items"] = items
|
||||||
resp["tracks"] = tracksObj
|
resp["tracks"] = tracksObj
|
||||||
|
normalizePlaylistImage(resp)
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func normalizePlaylistImage(resp map[string]any) {
|
||||||
|
if resp["image"] != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
rect, ok := resp["image_rectangle"].([]any)
|
||||||
|
if !ok || len(rect) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
url, ok := rect[0].(string)
|
||||||
|
if !ok || url == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resp["image"] = map[string]any{"original": url, "large": url}
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Client) getLabel(ctx context.Context, labelID string) (map[string]any, error) {
|
func (c *Client) getLabel(ctx context.Context, labelID string) (map[string]any, error) {
|
||||||
pageLimit := 500
|
pageLimit := 500
|
||||||
params := url.Values{}
|
params := url.Values{}
|
||||||
|
|||||||
Reference in New Issue
Block a user