Update download method
All checks were successful
Bump deps (only minor versions) / ci (push) Successful in 18s
All checks were successful
Bump deps (only minor versions) / ci (push) Successful in 18s
This commit is contained in:
parent
08578eef0b
commit
5bcbfc70ec
5 changed files with 31 additions and 28 deletions
|
@ -2,8 +2,8 @@ const createAnchorElement = (url: string, filename: string): HTMLAnchorElement =
|
||||||
const anchor = document.createElement('a');
|
const anchor = document.createElement('a');
|
||||||
anchor.href = url;
|
anchor.href = url;
|
||||||
anchor.download = filename;
|
anchor.download = filename;
|
||||||
return anchor
|
return anchor;
|
||||||
}
|
};
|
||||||
export const download = async (url: string, filename: string) => {
|
export const download = async (url: string, filename: string) => {
|
||||||
const response = await fetch(url);
|
const response = await fetch(url);
|
||||||
|
|
||||||
|
@ -13,9 +13,9 @@ export const download = async (url: string, filename: string) => {
|
||||||
|
|
||||||
const blob = await response.blob();
|
const blob = await response.blob();
|
||||||
const objectURL = window.URL.createObjectURL(blob);
|
const objectURL = window.URL.createObjectURL(blob);
|
||||||
const anchor = createAnchorElement(url, filename)
|
const anchor = createAnchorElement(url, filename);
|
||||||
document.body.appendChild(anchor);
|
document.body.appendChild(anchor);
|
||||||
anchor.click();
|
anchor.click();
|
||||||
anchor.remove();
|
anchor.remove();
|
||||||
window.URL.revokeObjectURL(objectURL);
|
window.URL.revokeObjectURL(objectURL);
|
||||||
}
|
};
|
||||||
|
|
|
@ -52,12 +52,16 @@
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if visible}
|
{#if visible}
|
||||||
<div class="fixed inset-0 z-50 flex items-center justify-center bg-black/80 backdrop-blur-sm font-mono">
|
<div
|
||||||
<div class="w-[90%] max-w-sm rounded-2xl border border-green-400 bg-[#000f00] p-6 text-green-300 shadow-2xl text-sm">
|
class="fixed inset-0 z-50 flex items-center justify-center bg-black/80 font-mono backdrop-blur-sm"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="w-[90%] max-w-sm rounded-2xl border border-green-400 bg-[#000f00] p-6 text-sm text-green-300 shadow-2xl"
|
||||||
|
>
|
||||||
<p class="mb-2 text-center text-cyan-300">
|
<p class="mb-2 text-center text-cyan-300">
|
||||||
Downloading <span class="text-green-400 font-semibold">{filename}</span>
|
Downloading <span class="font-semibold text-green-400">{filename}</span>
|
||||||
</p>
|
</p>
|
||||||
<div class="w-full h-4 rounded-md bg-black border border-green-500 overflow-hidden">
|
<div class="h-4 w-full overflow-hidden rounded-md border border-green-500 bg-black">
|
||||||
<div
|
<div
|
||||||
class="h-full bg-gradient-to-r from-green-400 to-green-600 transition-all duration-300"
|
class="h-full bg-gradient-to-r from-green-400 to-green-600 transition-all duration-300"
|
||||||
style="width: {progress}%"
|
style="width: {progress}%"
|
||||||
|
|
|
@ -17,8 +17,8 @@ export async function getYouTubeMetadata(link: string) {
|
||||||
dumpSingleJson: true,
|
dumpSingleJson: true,
|
||||||
noCheckCertificates: true,
|
noCheckCertificates: true,
|
||||||
noWarnings: true,
|
noWarnings: true,
|
||||||
preferFreeFormats: true,
|
preferFreeFormats: true
|
||||||
}
|
};
|
||||||
|
|
||||||
if (HTTPS_PROXY) {
|
if (HTTPS_PROXY) {
|
||||||
options.proxy = HTTPS_PROXY;
|
options.proxy = HTTPS_PROXY;
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
let disabled = $state(true);
|
let disabled = $state(true);
|
||||||
let metadata = $state(false);
|
let metadata = $state(false);
|
||||||
let logs = $state('');
|
let logs = $state('');
|
||||||
let downloadManager: DownloadManager|null = null;
|
let downloadManager: DownloadManager | null = null;
|
||||||
|
|
||||||
const formats = Object.keys(supportedFormats).map((f) => {
|
const formats = Object.keys(supportedFormats).map((f) => {
|
||||||
return { value: f, label: f.toUpperCase() };
|
return { value: f, label: f.toUpperCase() };
|
||||||
|
@ -29,13 +29,13 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
const dismiss = () => {
|
const dismiss = () => {
|
||||||
unmount(downloadManager)
|
unmount(downloadManager);
|
||||||
}
|
};
|
||||||
|
|
||||||
const onClick = async (evt) => {
|
const onClick = async (evt) => {
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
|
|
||||||
const props = $state( { url: href });
|
const props = $state({ url: href });
|
||||||
downloadManager = mount(DownloadManager, { target: document.body, props, events: { dismiss } });
|
downloadManager = mount(DownloadManager, { target: document.body, props, events: { dismiss } });
|
||||||
|
|
||||||
link = '';
|
link = '';
|
||||||
|
|
|
@ -55,7 +55,6 @@ export const GET: RequestHandler = async ({ url }) => {
|
||||||
throw error(500, 'Failed to fetch video metadata');
|
throw error(500, 'Failed to fetch video metadata');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Stream video/audio
|
// Stream video/audio
|
||||||
return new Response(streamYouTube(link, format), {
|
return new Response(streamYouTube(link, format), {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue