fix(ytdlp): correct media size estimates

This commit is contained in:
NimBold
2026-06-19 16:41:33 +03:30
parent a2d7b689f3
commit 85df857678
6 changed files with 110 additions and 91 deletions
+1 -1
View File
@@ -1,3 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
export type DownloadProgressEvent = { id: string, fraction: number, speed: string, eta: string, size: string | null, };
export type DownloadProgressEvent = { id: string, fraction: number, speed: string, eta: string, size: string | null, size_is_final: boolean, };
+1 -1
View File
@@ -1,3 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
export type MediaFormat = { format_id: string, resolution: string, ext: string, format_label: string, fps: number | null, filesize: number | null, };
export type MediaFormat = { format_id: string, resolution: string, ext: string, format_label: string, fps: number | null, filesize: number | null, filesize_approx: number | null, };
+14 -9
View File
@@ -28,6 +28,7 @@ interface MediaFormat {
detail: string;
type: string;
bytes: number;
isApproximate?: boolean;
}
interface ParsedDownloadItem {
@@ -383,16 +384,20 @@ export const AddDownloadsModal = () => {
password: keychainPassword
});
if (mediaData && mediaData.formats.length > 0) {
const mappedFormats = mediaData.formats.map(f => {
const quality = f.resolution || 'Best';
const container = f.ext.toUpperCase();
const bytes = f.filesize || 0;
return {
name: `${quality} ${container}`,
ext: f.ext,
bytes,
const mappedFormats = mediaData.formats.map(f => {
const quality = f.resolution || 'Best';
const container = f.ext.toUpperCase();
const exactBytes = f.filesize || 0;
const approxBytes = f.filesize_approx || 0;
const bytes = exactBytes || approxBytes;
const isApproximate = !exactBytes && approxBytes > 0;
return {
name: `${quality} ${container}`,
ext: f.ext,
bytes,
isApproximate,
formatLabel: f.format_label || f.ext.toUpperCase(),
detail: bytes ? formatBytes(bytes) : 'Unknown size',
detail: bytes ? `${isApproximate ? '~' : ''}${formatBytes(bytes)}` : 'Unknown size',
selector: f.format_id,
type: quality.toLowerCase().includes('audio') ? 'Audio' : 'Video'
};
+2 -1
View File
@@ -35,11 +35,12 @@ export async function initDownloadListener() {
const mainStore = useDownloadStore.getState();
const current = mainStore.downloads.find(d => d.id === payload.id);
if (current) {
const shouldUpdateSize = Boolean(payload.size && (!current.isMedia || payload.size_is_final));
mainStore.updateDownload(payload.id, {
fraction: payload.fraction,
speed: payload.speed,
eta: payload.eta,
...(payload.size ? { size: payload.size } : {}),
...(shouldUpdateSize ? { size: payload.size! } : {}),
});
}
});