|
|
|
@@ -2,6 +2,7 @@ import type { PlaybackSource, PlaybackStreamPlan } from "./playback-stream"
|
|
|
|
|
|
|
|
|
|
/** Qualities a listener can pick when downloading, lowest first. */
|
|
|
|
|
export const DOWNLOAD_QUALITIES = [
|
|
|
|
|
"low",
|
|
|
|
|
"medium",
|
|
|
|
|
"high",
|
|
|
|
|
"lossless",
|
|
|
|
@@ -11,6 +12,7 @@ export const DOWNLOAD_QUALITIES = [
|
|
|
|
|
export type DownloadQuality = (typeof DOWNLOAD_QUALITIES)[number]
|
|
|
|
|
|
|
|
|
|
export const DOWNLOAD_QUALITY_LABELS: Record<DownloadQuality, string> = {
|
|
|
|
|
low: "Low",
|
|
|
|
|
medium: "Medium",
|
|
|
|
|
high: "High",
|
|
|
|
|
lossless: "Lossless",
|
|
|
|
@@ -18,12 +20,14 @@ export const DOWNLOAD_QUALITY_LABELS: Record<DownloadQuality, string> = {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const DOWNLOAD_QUALITY_DETAILS: Record<DownloadQuality, string> = {
|
|
|
|
|
low: "AAC 64 kbps",
|
|
|
|
|
medium: "AAC 128 kbps",
|
|
|
|
|
high: "AAC 256 kbps",
|
|
|
|
|
lossless: "ALAC or FLAC",
|
|
|
|
|
atmos: "Spatial audio",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const LOW_KBPS = 64
|
|
|
|
|
const MEDIUM_KBPS = 128
|
|
|
|
|
const HIGH_KBPS = 256
|
|
|
|
|
|
|
|
|
@@ -54,13 +58,14 @@ function highPlan(files: Record<string, unknown>): DownloadPlan {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Picks the file for one song. Lossless and Dolby Atmos fall back to High when
|
|
|
|
|
* the song lacks them, and Medium is always transcoded.
|
|
|
|
|
* the song lacks them, and Low and Medium are always transcoded.
|
|
|
|
|
*/
|
|
|
|
|
export function downloadPlan(
|
|
|
|
|
files: Record<string, unknown>,
|
|
|
|
|
quality: DownloadQuality
|
|
|
|
|
): DownloadPlan {
|
|
|
|
|
switch (quality) {
|
|
|
|
|
case "low":
|
|
|
|
|
case "medium":
|
|
|
|
|
return {
|
|
|
|
|
quality,
|
|
|
|
@@ -70,7 +75,7 @@ export function downloadPlan(
|
|
|
|
|
: "normal" in files
|
|
|
|
|
? "normal"
|
|
|
|
|
: "atmos",
|
|
|
|
|
kbps: MEDIUM_KBPS,
|
|
|
|
|
kbps: quality === "low" ? LOW_KBPS : MEDIUM_KBPS,
|
|
|
|
|
}
|
|
|
|
|
case "high":
|
|
|
|
|
return highPlan(files)
|
|
|
|
@@ -84,7 +89,7 @@ export function downloadPlan(
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The download quality holding the same audio a stream plan plays, so a
|
|
|
|
|
* download can stand in for streaming. Low has no download equivalent.
|
|
|
|
|
* download can stand in for streaming.
|
|
|
|
|
*/
|
|
|
|
|
export function streamDownloadQuality(
|
|
|
|
|
plan: PlaybackStreamPlan
|
|
|
|
@@ -95,6 +100,7 @@ export function streamDownloadQuality(
|
|
|
|
|
}
|
|
|
|
|
if (plan.kbps === HIGH_KBPS) return "high"
|
|
|
|
|
if (plan.kbps === MEDIUM_KBPS) return "medium"
|
|
|
|
|
if (plan.kbps === LOW_KBPS) return "low"
|
|
|
|
|
return undefined
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -129,6 +135,7 @@ export function downloadOptions(
|
|
|
|
|
).length
|
|
|
|
|
if (
|
|
|
|
|
fallbackCount === songs.length &&
|
|
|
|
|
quality !== "low" &&
|
|
|
|
|
quality !== "medium" &&
|
|
|
|
|
quality !== "high"
|
|
|
|
|
) {
|
|
|
|
|