Author SHA1 Message Date
Joren 8590a5b6b6 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
2026-08-05 23:16:37 +02:00
Joren eb7854bac3 fix: use all album artists for folder naming 2026-07-22 22:34:42 +02:00
Joren 5f61b1a3cf fix: use exact qobuz download quality 2026-07-12 21:44:01 +02:00
Joren e336bb96f1 fix: set album track totals 2026-07-12 03:28:27 +02:00
Joren 99c531928e feat: add cli help menus 2026-07-12 00:06:18 +02:00
Joren 150b5b5d85 fix: omit original mix from titles 2026-07-11 23:43:03 +02:00
10 changed files with 478 additions and 51 deletions
+4
View File
@@ -25,6 +25,7 @@ type globalOptions struct {
noProgress bool
noSSLVerify bool
verbose int
help bool
command string
commandArgs []string
}
@@ -45,6 +46,9 @@ func parseGlobalArgs(args []string) (globalOptions, error) {
}
switch {
case isHelpArg(arg):
opts.help = true
return opts, nil
case arg == "-ndb" || arg == "--no-db":
opts.noDB = true
case arg == "--no-progress":
+160
View File
@@ -0,0 +1,160 @@
package main
import (
"fmt"
"io"
"strings"
)
func isHelpArg(arg string) bool {
return arg == "-h" || arg == "--help"
}
func commandWantsHelp(args []string) bool {
for _, arg := range args {
if isHelpArg(arg) {
return true
}
}
return false
}
func printMainHelp(w io.Writer) {
fmt.Fprint(w, `streamrip-go
Usage:
rip [global options] <command> [command options]
rip help [command]
Commands:
url Rip one or more URLs
file Rip URLs or IDs from a file
id Rip by source, media type, and ID
search Search a provider and download selected results
lastfm Import a Last.fm playlist
config Manage configuration
database Inspect download databases
Global options:
-f, --folder <path> Override downloads folder
-q, --quality <0-4> Override provider quality
-c, --codec <codec> Convert after download: ALAC, FLAC, OGG, MP3, AAC
-ndb, --no-db Ignore download database
--no-progress Disable progress bars
--no-ssl-verify Disable TLS verification
--config-path <path> Use a custom config file
-v, -vv Verbose logging
-h, --help Show help
Run 'rip help <command>' for command-specific help.
`)
}
func printCommandHelp(w io.Writer, command string) bool {
switch strings.ToLower(strings.TrimSpace(command)) {
case "url":
fmt.Fprint(w, `Usage:
rip url <url...> [--force|--ignore-db]
Rip one or more provider URLs.
Examples:
rip url https://www.beatport.com/release/example/123
rip url https://play.qobuz.com/album/abc --force
Options:
--force, --ignore-db Redownload even if already in the database
`)
case "file":
fmt.Fprint(w, `Usage:
rip file <path> [--force|--ignore-db]
Rip URLs or JSON ID entries from a file.
Options:
--force, --ignore-db Redownload even if already in the database
`)
case "id":
fmt.Fprint(w, `Usage:
rip id <source> <media-type> <id> [quality] [--force|--ignore-db]
Rip an item by provider ID.
Sources:
qobuz, tidal, deezer, yandex, beatport, soundcloud
Media types:
track, album, playlist, artist, label, chart, video
Options:
quality Override quality for this rip, 0-4
--force, --ignore-db Redownload even if already in the database
`)
case "search":
fmt.Fprint(w, `Usage:
rip search <source> <media-type> <query...> [options]
Search a provider and optionally download selected results.
Sources:
qobuz, tidal, deezer, yandex, beatport, soundcloud
Media types:
track, album, playlist, artist, label, chart, video
Options:
--limit N Maximum results to show
--first Download the first result without prompting
--no-download Show results only
--output-file <path> Write results as JSON
--force, --ignore-db Redownload even if already in the database
`)
case "lastfm":
fmt.Fprint(w, `Usage:
rip lastfm [--source SOURCE] [--fallback-source SOURCE] <playlist_url>
Import a Last.fm playlist and resolve tracks through configured providers.
Options:
--source SOURCE Primary lookup source
--fallback-source SOURCE Fallback lookup source
`)
case "config":
fmt.Fprint(w, `Usage:
rip config <open|reset|path> [options]
Manage configuration.
Commands:
open Open the config file in an editor
reset Reset config to defaults
path Print the config path
Options:
-v, --vim Use Vim for 'rip config open'
-y, --yes Confirm 'rip config reset' without prompting
`)
case "database":
fmt.Fprint(w, `Usage:
rip database browse <downloads|failed>
Inspect local download databases.
`)
case "dev-help":
printDeveloperHelp(w)
default:
return false
}
return true
}
func printDeveloperHelp(w io.Writer) {
fmt.Fprint(w, `Developer smoke commands:
soundcloud-smoke
qobuz-smoke, qobuz-rip-smoke, qobuz-convert-rip-smoke
qobuz-album-rip-smoke, qobuz-playlist-rip-smoke, qobuz-artist-rip-smoke, qobuz-label-rip-smoke
qobuz-search-smoke
tidal-search-smoke, tidal-metadata-smoke, tidal-video-smoke
tidal-rip-smoke, tidal-album-rip-smoke, tidal-playlist-rip-smoke, tidal-artist-rip-smoke
`)
}
+35 -17
View File
@@ -25,10 +25,34 @@ func main() {
fmt.Fprintf(os.Stderr, "option error: %v\n", err)
os.Exit(2)
}
if gopts.help {
printMainHelp(os.Stdout)
return
}
if gopts.command == "" {
fmt.Println("usage: rip <command>")
fmt.Println("commands: url, file, config, database, id, search, lastfm")
fmt.Println("tip: run `rip dev-help` to list developer smoke commands")
printMainHelp(os.Stdout)
os.Exit(2)
}
if gopts.command == "help" {
if len(gopts.commandArgs) == 0 || isHelpArg(gopts.commandArgs[0]) {
printMainHelp(os.Stdout)
return
}
if printCommandHelp(os.Stdout, gopts.commandArgs[0]) {
return
}
fmt.Fprintf(os.Stderr, "unknown help topic: %s\n", gopts.commandArgs[0])
os.Exit(2)
}
if gopts.command == "dev-help" {
printDeveloperHelp(os.Stdout)
return
}
if commandWantsHelp(gopts.commandArgs) {
if printCommandHelp(os.Stdout, gopts.command) {
return
}
fmt.Fprintf(os.Stderr, "unknown command: %s\n", gopts.command)
os.Exit(2)
}
@@ -64,17 +88,11 @@ func main() {
switch os.Args[1] {
case "dev-help":
fmt.Println("developer smoke commands:")
fmt.Println(" soundcloud-smoke")
fmt.Println(" qobuz-smoke, qobuz-rip-smoke, qobuz-convert-rip-smoke")
fmt.Println(" qobuz-album-rip-smoke, qobuz-playlist-rip-smoke, qobuz-artist-rip-smoke, qobuz-label-rip-smoke")
fmt.Println(" qobuz-search-smoke")
fmt.Println(" tidal-search-smoke, tidal-metadata-smoke, tidal-video-smoke")
fmt.Println(" tidal-rip-smoke, tidal-album-rip-smoke, tidal-playlist-rip-smoke, tidal-artist-rip-smoke")
printDeveloperHelp(os.Stdout)
return
case "url":
if len(os.Args) < 3 {
fmt.Println("usage: rip url <url...> [--force|--ignore-db]")
printCommandHelp(os.Stdout, "url")
os.Exit(2)
}
@@ -119,7 +137,7 @@ func main() {
fmt.Printf("url rip complete (%d item(s))\n", added)
case "file":
if len(os.Args) < 3 {
fmt.Println("usage: rip file <path> [--force|--ignore-db]")
printCommandHelp(os.Stdout, "file")
os.Exit(2)
}
@@ -192,7 +210,7 @@ func main() {
fmt.Printf("file rip complete (%d item(s))\n", added)
case "config":
if len(os.Args) < 3 {
fmt.Println("usage: rip config <open|reset|path> [options]")
printCommandHelp(os.Stdout, "config")
os.Exit(2)
}
switch os.Args[2] {
@@ -258,7 +276,7 @@ func main() {
}
case "database":
if len(os.Args) < 4 || os.Args[2] != "browse" {
fmt.Println("usage: rip database browse <downloads|failed>")
printCommandHelp(os.Stdout, "database")
os.Exit(2)
}
table := strings.ToLower(strings.TrimSpace(os.Args[3]))
@@ -294,7 +312,7 @@ func main() {
}
case "id":
if len(os.Args) < 5 {
fmt.Println("usage: rip id <source> <track|album|playlist|artist|label|chart|video> <id> [quality] [--force|--ignore-db]")
printCommandHelp(os.Stdout, "id")
os.Exit(2)
}
@@ -354,7 +372,7 @@ func main() {
var sopts searchOptions
if len(os.Args) < 5 {
if !term.IsTerminal(int(os.Stdin.Fd())) {
fmt.Println("usage: rip search <qobuz|tidal|deezer|yandex|beatport|soundcloud> <track|album|playlist|artist|label|chart|video> <query...> [--limit N] [--force|--ignore-db] [--no-download]")
printCommandHelp(os.Stdout, "search")
os.Exit(2)
}
source, mediaType, sopts, err = promptSearchInteractive(cfg.Session.CLI.MaxSearchResults)
@@ -549,7 +567,7 @@ func main() {
opts, parseErr := parseLastFMArgs(os.Args[2:], cfg.Session.LastFM.Source, cfg.Session.LastFM.FallbackSource)
if parseErr != nil {
fmt.Fprintf(os.Stderr, "lastfm option error: %v\n", parseErr)
fmt.Println("usage: rip lastfm [--source SOURCE] [--fallback-source SOURCE] <playlist_url>")
printCommandHelp(os.Stdout, "lastfm")
os.Exit(2)
}
+53
View File
@@ -1,6 +1,7 @@
package main
import (
"bytes"
"errors"
"os"
"path/filepath"
@@ -206,6 +207,58 @@ func TestParseGlobalArgsNoDBBeforeCommand(t *testing.T) {
}
}
func TestParseGlobalArgsHelp(t *testing.T) {
opts, err := parseGlobalArgs([]string{"--help"})
if err != nil {
t.Fatalf("parseGlobalArgs() error = %v", err)
}
if !opts.help {
t.Fatalf("expected help=true")
}
}
func TestCommandWantsHelp(t *testing.T) {
if !commandWantsHelp([]string{"https://example.com", "-h"}) {
t.Fatalf("expected command help")
}
if commandWantsHelp([]string{"https://example.com"}) {
t.Fatalf("did not expect command help")
}
}
func TestMainHelpHidesDeveloperCommands(t *testing.T) {
var buf bytes.Buffer
printMainHelp(&buf)
out := buf.String()
if !strings.Contains(out, "rip help [command]") || !strings.Contains(out, "Commands:") {
t.Fatalf("main help missing expected text: %s", out)
}
if strings.Contains(out, "dev-help") || strings.Contains(out, "smoke") {
t.Fatalf("main help should hide developer commands: %s", out)
}
}
func TestCommandHelpURL(t *testing.T) {
var buf bytes.Buffer
if !printCommandHelp(&buf, "url") {
t.Fatalf("expected url help")
}
out := buf.String()
if !strings.Contains(out, "rip url <url...>") || !strings.Contains(out, "--ignore-db") {
t.Fatalf("url help missing expected text: %s", out)
}
}
func TestPrintCommandHelpRejectsUnknown(t *testing.T) {
var buf bytes.Buffer
if printCommandHelp(&buf, "nope") {
t.Fatalf("unexpected help for unknown command")
}
if buf.Len() != 0 {
t.Fatalf("unexpected output for unknown command: %s", buf.String())
}
}
func TestParseGlobalArgsAllOfficialFlags(t *testing.T) {
opts, err := parseGlobalArgs([]string{
"--config-path", "/tmp/custom.toml",
+93 -14
View File
@@ -11,6 +11,7 @@ import (
"strconv"
"strings"
"sync"
"time"
"streamrip-go/internal/artwork"
"streamrip-go/internal/audio/convert"
@@ -58,6 +59,7 @@ type ripTrackOptions struct {
forPlaylist bool
playlistName string
playlistPos int
playlistYear int
}
type folderAudioValues struct {
@@ -372,14 +374,22 @@ func (m *Main) ripTrackCollection(ctx context.Context, p provider.Client, source
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))
failures := 0
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 {
opts.forPlaylist = true
opts.playlistName = name
opts.playlistPos = i
opts.playlistYear = playlistYear
}
if err := m.ripTrack(ctx, p, source, trackID, "", opts); err != nil {
failures++
@@ -404,11 +414,12 @@ func (m *Main) ripTrackCollection(ctx context.Context, p provider.Client, source
go func(pos int, tid string) {
defer wg.Done()
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 {
opts.forPlaylist = true
opts.playlistName = name
opts.playlistPos = pos
opts.playlistYear = playlistYear
}
if err := m.ripTrack(ctx, p, source, tid, "", opts); err != nil {
mu.Lock()
@@ -648,10 +659,7 @@ func (m *Main) ripAlbum(ctx context.Context, p provider.Client, source, albumID
}
albumTitle := titleFromMetadata(albumMeta, albumID)
albumArtist := jsonutil.NestedString(albumMeta, "artist", "name")
if albumArtist == "" {
albumArtist = "Unknown"
}
albumArtist := extractAlbumArtist(albumMeta)
releaseDate := jsonutil.StringFromAny(albumMeta["release_date_original"])
if releaseDate == "" {
releaseDate = jsonutil.StringFromAny(albumMeta["release_date"])
@@ -809,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)
m.logf("Playlist: %s (%d tracks)\n", name, total)
failures := 0
@@ -816,11 +828,13 @@ func (m *Main) ripPlaylist(ctx context.Context, p provider.Client, source, playl
runOne := func(i int, id string) {
opts := ripTrackOptions{
albumFolder: folder,
albumEmbedCover: artRes.EmbedPath,
index: i,
total: total,
forPlaylist: true,
playlistName: name,
playlistPos: i,
playlistYear: playlistYear,
}
if err := m.ripTrack(ctx, p, source, id, "", opts); err != nil {
failures++
@@ -846,7 +860,7 @@ func (m *Main) ripPlaylist(ctx context.Context, p provider.Client, source, playl
go func(pos int, tid string) {
defer wg.Done()
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 {
mu.Lock()
failures++
@@ -1013,7 +1027,7 @@ func (m *Main) ripTrack(ctx context.Context, p provider.Client, source, id, fall
downloaded:
embedCoverPath := opts.albumEmbedCover
if opts.forPlaylist {
if opts.forPlaylist && embedCoverPath == "" {
parent := opts.albumFolder
if parent == "" {
parent = filepath.Dir(outPath)
@@ -1023,7 +1037,7 @@ downloaded:
embedCoverPath = res.EmbedPath
}
}
} else if embedCoverPath == "" {
} else if !opts.forPlaylist && embedCoverPath == "" {
parent := opts.albumFolder
if parent == "" {
parent = filepath.Dir(outPath)
@@ -1224,10 +1238,7 @@ func (m *Main) trackOutputPath(source, id, title, ext string, d *provider.Downlo
if albumID == "" {
albumID = id
}
albumArtist := jsonutil.NestedString(trackMeta, "album", "artist", "name")
if albumArtist == "" {
albumArtist = jsonutil.NestedString(trackMeta, "performer", "name")
}
albumArtist := extractAlbumArtist(trackMetaAlbum(trackMeta))
albumYear := naming.YearFromDate(jsonutil.StringFromAny(trackMeta["release_date_original"]))
if albumYear == "Unknown" {
albumYear = naming.YearFromDate(jsonutil.StringFromAny(trackMeta["release_date"]))
@@ -1310,7 +1321,7 @@ func titleFromMetadata(meta map[string]any, fallback string) string {
if title, ok := meta["title"].(string); ok {
title = strings.TrimSpace(title)
version := strings.TrimSpace(jsonutil.StringFromAny(meta["version"]))
if version != "" {
if version != "" && !isOriginalMix(version) {
return title + " (" + version + ")"
}
if title != "" {
@@ -1320,6 +1331,10 @@ func titleFromMetadata(meta map[string]any, fallback string) string {
return fallback
}
func isOriginalMix(version string) bool {
return strings.EqualFold(strings.TrimSpace(version), "Original Mix")
}
func replaygainGainFromAny(v any) string {
s := strings.TrimSpace(jsonutil.StringFromAny(v))
if s == "" {
@@ -1395,6 +1410,9 @@ func buildTagMetadata(trackMeta map[string]any, title, source, trackID string, o
if trackTotal == 0 {
trackTotal = jsonutil.IntFromAny(trackMeta["track_total"])
}
if trackTotal == 0 && opts.total > 0 {
trackTotal = opts.total
}
if opts.forPlaylist && opts.total > 0 {
trackTotal = opts.total
}
@@ -1472,7 +1490,9 @@ func buildTagMetadata(trackMeta map[string]any, title, source, trackID string, o
Artist: artist,
Artists: artistNames,
AlbumArtist: albumArtist,
Compilation: opts.forPlaylist,
OmitDiscTags: opts.forPlaylist,
Year: opts.playlistYear,
TrackNumber: trackNumber,
DiscNumber: discNumber,
TrackTotal: trackTotal,
@@ -1606,3 +1626,62 @@ func isFFmpegMissingError(err error) bool {
}
return strings.Contains(strings.ToLower(err.Error()), "ffmpeg not found")
}
func extractAlbumArtist(albumMeta map[string]any) string {
if artistsRaw, ok := albumMeta["artists"].([]any); ok {
names := make([]string, 0, len(artistsRaw))
for _, a := range artistsRaw {
artist, ok := a.(map[string]any)
if !ok {
continue
}
if name := jsonutil.StringFromAny(artist["name"]); name != "" {
names = append(names, name)
}
}
if len(names) > 0 {
return displayArtistNames(names)
}
}
if names := stringSliceFromAny(albumMeta["artist_names"]); len(names) > 0 {
return displayArtistNames(names)
}
artist := jsonutil.NestedString(albumMeta, "artist", "name")
if artist != "" {
return artist
}
return "Unknown"
}
func displayArtistNames(names []string) string {
switch len(names) {
case 0:
return ""
case 1:
return names[0]
case 2:
return names[0] + " & " + names[1]
default:
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
}
+30
View File
@@ -490,6 +490,22 @@ func TestBuildTagMetadataUsesAlbumArtistOverride(t *testing.T) {
}
}
func TestBuildTagMetadataUsesAlbumContextTrackTotal(t *testing.T) {
meta := map[string]any{
"title": "ideal world (feat. higma)",
"track_number": float64(2),
"performer": map[string]any{"name": "Seren Azuma"},
"album": map[string]any{
"title": "YUKIHASU",
"artist": map[string]any{"name": "Seren Azuma"},
},
}
tags := buildTagMetadata(meta, "ideal world (feat. higma)", "qobuz", "295525879", ripTrackOptions{total: 11})
if tags.TrackTotal != 11 {
t.Fatalf("track total = %d, want 11", tags.TrackTotal)
}
}
func TestBuildTagMetadataPlaylistOmitsDiscTags(t *testing.T) {
meta := map[string]any{
"title": "One Step Too Far",
@@ -893,6 +909,20 @@ func TestBuildTagMetadataArtistList(t *testing.T) {
}
}
func TestTitleFromMetadataSkipsOriginalMix(t *testing.T) {
meta := map[string]any{"title": "Dance Done", "version": "Original Mix"}
if got := titleFromMetadata(meta, "42"); got != "Dance Done" {
t.Fatalf("titleFromMetadata()=%q", got)
}
}
func TestTitleFromMetadataIncludesNonOriginalMix(t *testing.T) {
meta := map[string]any{"title": "Dance Done", "version": "Extended Mix"}
if got := titleFromMetadata(meta, "42"); got != "Dance Done (Extended Mix)" {
t.Fatalf("titleFromMetadata()=%q", got)
}
}
func TestNormalizeInitialKey(t *testing.T) {
tests := map[string]string{
"C Major": "C",
+8
View File
@@ -16,7 +16,9 @@ type Metadata struct {
Artist string
Artists []string
AlbumArtist string
Compilation bool
OmitDiscTags bool
Year int
TrackNumber int
DiscNumber int
TrackTotal int
@@ -197,6 +199,12 @@ func toTags(meta Metadata) map[string]string {
if meta.DiscTotal > 0 {
tags["disctotal"] = strconv.Itoa(meta.DiscTotal)
}
if meta.Compilation {
tags["COMPILATION"] = "1"
}
if meta.Year > 0 {
tags["year"] = strconv.Itoa(meta.Year)
}
return tags
}
+3
View File
@@ -615,6 +615,9 @@ func playlistMetadata(raw map[string]any, tracks []any) map[string]any {
"title": name,
"tracks_count": firstPositiveInt(jsonutil.IntFromAny(raw["track_count"]), len(tracks)),
"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},
}
}
+62 -8
View File
@@ -364,40 +364,60 @@ func qobuzDownloadExtension(resp map[string]any, quality int, streamURL string)
}
func qobuzAudioProfile(resp map[string]any, requestedQuality int, ext string) provider.AudioProfile {
exactBitDepth, _ := intValue(firstNonNil(resp["bit_depth"], resp["bits_depth"], resp["maximum_bit_depth"]))
exactSampling, _ := floatValue(firstNonNil(resp["sampling_rate"], resp["sample_rate"], resp["maximum_sampling_rate"]))
if formatID, ok := intValue(resp["format_id"]); ok {
switch formatID {
case 5:
if exactBitDepth == 0 {
exactBitDepth = 16
}
if exactSampling == 0 {
exactSampling = 44.1
}
return provider.AudioProfile{
Container: "MP3",
Codec: "MP3",
Quality: "HIGH",
BitDepth: 16,
SamplingRate: "44.1",
BitDepth: exactBitDepth,
SamplingRate: formatSamplingRate(exactSampling),
BitrateKbps: 320,
}
case 6:
if exactBitDepth == 0 {
exactBitDepth = 16
}
if exactSampling == 0 {
exactSampling = 44.1
}
return provider.AudioProfile{
Container: "FLAC",
Codec: "FLAC",
Quality: "LOSSLESS",
BitDepth: 16,
SamplingRate: "44.1",
BitDepth: exactBitDepth,
SamplingRate: formatSamplingRate(exactSampling),
}
case 7:
if exactBitDepth == 0 {
exactBitDepth = 24
}
return provider.AudioProfile{
Container: "FLAC",
Codec: "FLAC",
Quality: "HI_RES",
BitDepth: 24,
SamplingRate: "96",
BitDepth: exactBitDepth,
SamplingRate: formatSamplingRate(exactSampling),
}
case 27:
if exactBitDepth == 0 {
exactBitDepth = 24
}
return provider.AudioProfile{
Container: "FLAC",
Codec: "FLAC",
Quality: "HI_RES",
BitDepth: 24,
SamplingRate: "192",
BitDepth: exactBitDepth,
SamplingRate: formatSamplingRate(exactSampling),
}
}
}
@@ -438,6 +458,22 @@ func qobuzAudioProfile(resp map[string]any, requestedQuality int, ext string) pr
}
}
func firstNonNil(vals ...any) any {
for _, v := range vals {
if v != nil {
return v
}
}
return nil
}
func formatSamplingRate(v float64) string {
if v <= 0 {
return ""
}
return strconv.FormatFloat(v, 'f', -1, 64)
}
func (c *Client) Close() error {
return nil
}
@@ -577,11 +613,13 @@ func (c *Client) getPlaylist(ctx context.Context, playlistID string) (map[string
total, _ := intValue(resp["tracks_count"])
if total <= pageLimit {
normalizePlaylistImage(resp)
return resp, nil
}
tracksObj, ok := mapValue(resp["tracks"])
if !ok {
normalizePlaylistImage(resp)
return resp, nil
}
items, ok := tracksObj["items"].([]any)
@@ -617,9 +655,25 @@ func (c *Client) getPlaylist(ctx context.Context, playlistID string) (map[string
tracksObj["items"] = items
resp["tracks"] = tracksObj
normalizePlaylistImage(resp)
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) {
pageLimit := 500
params := url.Values{}
+18
View File
@@ -371,6 +371,24 @@ func TestGetDownloadableUsesReturnedURLExtension(t *testing.T) {
}
}
func TestQobuzAudioProfileUsesExactReturnedQuality(t *testing.T) {
profile := qobuzAudioProfile(map[string]any{
"format_id": float64(7),
"bit_depth": float64(24),
"sampling_rate": float64(44.1),
}, 4, "flac")
if profile.BitDepth != 24 || profile.SamplingRate != "44.1" || profile.Quality != "HI_RES" {
t.Fatalf("unexpected profile: %+v", profile)
}
}
func TestQobuzAudioProfileAvoidsGuessingHiResSampleRate(t *testing.T) {
profile := qobuzAudioProfile(map[string]any{"format_id": float64(7)}, 4, "flac")
if profile.BitDepth != 24 || profile.SamplingRate != "" || profile.Quality != "HI_RES" {
t.Fatalf("unexpected profile: %+v", profile)
}
}
func qobuzSecretSig(requestTS, secret string) string {
raw := "trackgetFileUrlformat_id27intentstreamtrack_id19512574" + requestTS + secret
hash := md5.Sum([]byte(raw))