feat: download songs in Low quality
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d7d476e5ec
commit
06d501921d
3 files changed
+18
-9
No files matched your search
@@ -450,9 +450,10 @@ function QualitySection({ user }: { user: CurrentUser }) {
|
|||||||
|
|
||||||
/** Shades of the text color, faintest for the smallest files. */
|
/** Shades of the text color, faintest for the smallest files. */
|
||||||
const QUALITY_OPACITY: Record<DownloadQuality, number> = {
|
const QUALITY_OPACITY: Record<DownloadQuality, number> = {
|
||||||
medium: 0.25,
|
low: 0.2,
|
||||||
high: 0.45,
|
medium: 0.35,
|
||||||
lossless: 0.7,
|
high: 0.5,
|
||||||
|
lossless: 0.75,
|
||||||
atmos: 1,
|
atmos: 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,9 +39,10 @@ const ASK_EVERY_TIME = "ask"
|
|||||||
|
|
||||||
/** Shades of the text color, darkest for the smallest files. */
|
/** Shades of the text color, darkest for the smallest files. */
|
||||||
const QUALITY_OPACITY: Record<DownloadQuality, number> = {
|
const QUALITY_OPACITY: Record<DownloadQuality, number> = {
|
||||||
medium: 0.25,
|
low: 0.2,
|
||||||
high: 0.45,
|
medium: 0.35,
|
||||||
lossless: 0.7,
|
high: 0.5,
|
||||||
|
lossless: 0.75,
|
||||||
atmos: 1,
|
atmos: 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import type { PlaybackSource, PlaybackStreamPlan } from "./playback-stream"
|
|||||||
|
|
||||||
/** Qualities a listener can pick when downloading, lowest first. */
|
/** Qualities a listener can pick when downloading, lowest first. */
|
||||||
export const DOWNLOAD_QUALITIES = [
|
export const DOWNLOAD_QUALITIES = [
|
||||||
|
"low",
|
||||||
"medium",
|
"medium",
|
||||||
"high",
|
"high",
|
||||||
"lossless",
|
"lossless",
|
||||||
@@ -11,6 +12,7 @@ export const DOWNLOAD_QUALITIES = [
|
|||||||
export type DownloadQuality = (typeof DOWNLOAD_QUALITIES)[number]
|
export type DownloadQuality = (typeof DOWNLOAD_QUALITIES)[number]
|
||||||
|
|
||||||
export const DOWNLOAD_QUALITY_LABELS: Record<DownloadQuality, string> = {
|
export const DOWNLOAD_QUALITY_LABELS: Record<DownloadQuality, string> = {
|
||||||
|
low: "Low",
|
||||||
medium: "Medium",
|
medium: "Medium",
|
||||||
high: "High",
|
high: "High",
|
||||||
lossless: "Lossless",
|
lossless: "Lossless",
|
||||||
@@ -18,12 +20,14 @@ export const DOWNLOAD_QUALITY_LABELS: Record<DownloadQuality, string> = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const DOWNLOAD_QUALITY_DETAILS: Record<DownloadQuality, string> = {
|
export const DOWNLOAD_QUALITY_DETAILS: Record<DownloadQuality, string> = {
|
||||||
|
low: "AAC 64 kbps",
|
||||||
medium: "AAC 128 kbps",
|
medium: "AAC 128 kbps",
|
||||||
high: "AAC 256 kbps",
|
high: "AAC 256 kbps",
|
||||||
lossless: "ALAC or FLAC",
|
lossless: "ALAC or FLAC",
|
||||||
atmos: "Spatial audio",
|
atmos: "Spatial audio",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const LOW_KBPS = 64
|
||||||
const MEDIUM_KBPS = 128
|
const MEDIUM_KBPS = 128
|
||||||
const HIGH_KBPS = 256
|
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
|
* 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(
|
export function downloadPlan(
|
||||||
files: Record<string, unknown>,
|
files: Record<string, unknown>,
|
||||||
quality: DownloadQuality
|
quality: DownloadQuality
|
||||||
): DownloadPlan {
|
): DownloadPlan {
|
||||||
switch (quality) {
|
switch (quality) {
|
||||||
|
case "low":
|
||||||
case "medium":
|
case "medium":
|
||||||
return {
|
return {
|
||||||
quality,
|
quality,
|
||||||
@@ -70,7 +75,7 @@ export function downloadPlan(
|
|||||||
: "normal" in files
|
: "normal" in files
|
||||||
? "normal"
|
? "normal"
|
||||||
: "atmos",
|
: "atmos",
|
||||||
kbps: MEDIUM_KBPS,
|
kbps: quality === "low" ? LOW_KBPS : MEDIUM_KBPS,
|
||||||
}
|
}
|
||||||
case "high":
|
case "high":
|
||||||
return highPlan(files)
|
return highPlan(files)
|
||||||
@@ -84,7 +89,7 @@ export function downloadPlan(
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The download quality holding the same audio a stream plan plays, so a
|
* 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(
|
export function streamDownloadQuality(
|
||||||
plan: PlaybackStreamPlan
|
plan: PlaybackStreamPlan
|
||||||
@@ -95,6 +100,7 @@ export function streamDownloadQuality(
|
|||||||
}
|
}
|
||||||
if (plan.kbps === HIGH_KBPS) return "high"
|
if (plan.kbps === HIGH_KBPS) return "high"
|
||||||
if (plan.kbps === MEDIUM_KBPS) return "medium"
|
if (plan.kbps === MEDIUM_KBPS) return "medium"
|
||||||
|
if (plan.kbps === LOW_KBPS) return "low"
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,6 +135,7 @@ export function downloadOptions(
|
|||||||
).length
|
).length
|
||||||
if (
|
if (
|
||||||
fallbackCount === songs.length &&
|
fallbackCount === songs.length &&
|
||||||
|
quality !== "low" &&
|
||||||
quality !== "medium" &&
|
quality !== "medium" &&
|
||||||
quality !== "high"
|
quality !== "high"
|
||||||
) {
|
) {
|
||||||
|
|||||||
Reference in new issue
Block a user