diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index ac7dcae..f23038c 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -50,7 +50,7 @@ if (value) { chunks.push(value); receivedLength += value.length; - progress = Math.round((receivedLength / contentLength) * 100); + progress = Math.round((receivedLength / 150000) * 100); } } @@ -72,6 +72,8 @@ downloading = false; link = ''; + progress = 0; + filename = ''; }; const createAnchor = () => { diff --git a/src/routes/download/+server.ts b/src/routes/download/+server.ts index 8db31e1..247dd73 100644 --- a/src/routes/download/+server.ts +++ b/src/routes/download/+server.ts @@ -39,7 +39,6 @@ const validateRequest = (url: URL) => { export const GET: RequestHandler = async ({ url }) => { const { format, source, metadata, link } = validateRequest(url); let filename = ''; - let contentLength = 0; logger.debug(`Requested: ${link}`); @@ -47,8 +46,7 @@ export const GET: RequestHandler = async ({ url }) => { logger.debug(`Fetching video data to set filename`); // Fetch metadata for filename const ytMetadata = await getYouTubeMetadata(link); - const { title, uploader, filesize_approx } = ytMetadata; - contentLength = filesize_approx; + const { title, uploader } = ytMetadata; const safeTitle = `${uploader} - ${title}`; filename = `${safeTitle}.${format}`; } catch (err) { @@ -62,7 +60,7 @@ export const GET: RequestHandler = async ({ url }) => { return new Response(streamYouTube(link, format), { headers: { 'Content-Type': `${mimeTypeMap.get(format)}`, - 'Content-Length': contentLength, + 'Content-Disposition': `attachment; filename="${filename}"` } });