fix(download): add format fallback selectors (#63)

This commit is contained in:
Nexmoe
2026-01-01 14:41:59 +08:00
committed by GitHub
parent e8413aefae
commit 71ae4a4425
2 changed files with 7 additions and 7 deletions

View File

@@ -34,8 +34,8 @@ export const resolveVideoFormatSelector = (options: DownloadOptions): string =>
return 'bestvideo+none'
}
if (!audioFormat || audioFormat === 'best') {
// Use bestvideo+bestaudio to ensure video and audio are merged into a single file
return 'bestvideo+bestaudio'
// Prefer merged formats, but allow single-file "best" for sites without separate streams.
return 'bestvideo+bestaudio/best'
}
return `bestvideo+${audioFormat}`
}

View File

@@ -78,11 +78,11 @@ const getQualityPreset = (settings: AppSettings): OneClickQualityPreset =>
const buildAudioSelectors = (preset: OneClickQualityPreset): string[] => {
if (preset === 'worst') {
return ['worstaudio']
return dedupe(['worstaudio', 'bestaudio'])
}
const abrLimit = qualityPresetToAudioAbr[preset]
// Remove 'best' fallback to ensure merging - only use 'bestaudio' variants
// Prefer audio-only selectors so video+audio merges remain valid.
return dedupe([abrLimit ? `bestaudio[abr<=${abrLimit}]` : undefined, 'bestaudio'])
}
@@ -90,8 +90,8 @@ const buildVideoFormatPreference = (settings: AppSettings): string => {
const preset = getQualityPreset(settings)
if (preset === 'worst') {
// Use worstvideo+worstaudio as fallback instead of 'worst' to ensure merging
return 'worstvideo+worstaudio'
// Prefer separate streams, then fall back to single-file selectors.
return 'worstvideo+worstaudio/worst/best'
}
const maxHeight = qualityPresetToVideoHeight[preset]
@@ -125,7 +125,7 @@ const buildVideoFormatPreference = (settings: AppSettings): string => {
const buildAudioFormatPreference = (settings: AppSettings): string => {
const selectors = buildAudioSelectors(getQualityPreset(settings))
return selectors.join('/')
return dedupe([...selectors, 'best']).join('/')
}
interface DownloadDialogProps {