feat: improve YouTube download experience and add progress handling

- Add start callback trigger for video stream
- Update form description with download guidance
- Temporarily hardcode development URL for testing
- Bump package version to 0.1.2
This commit is contained in:
Huakun Shen 2025-01-28 09:16:00 -05:00
parent 37066b3474
commit a8eca4392a
No known key found for this signature in database
4 changed files with 10 additions and 6 deletions

View File

@ -125,7 +125,9 @@ export class YouTubeDownloader implements API {
const videoStream = ytdl(url, { format: videoFormat }); const videoStream = ytdl(url, { format: videoFormat });
const audioStream = ytdl(url, { format: audioFormat }); const audioStream = ytdl(url, { format: audioFormat });
videoStream.once("readable", () => {
startCallback?.();
});
videoStream.on("progress", (_, downloaded, total) => { videoStream.on("progress", (_, downloaded, total) => {
videoDownloaded += downloaded; videoDownloaded += downloaded;
const now = Date.now(); const now = Date.now();

View File

@ -1,6 +1,6 @@
{ {
"name": "@kunkun/kunkun-ext-youtube-downloader", "name": "@kunkun/kunkun-ext-youtube-downloader",
"version": "0.1.1", "version": "0.1.2",
"license": "MIT", "license": "MIT",
"exports": "./mod.ts", "exports": "./mod.ts",
"imports": { "imports": {

View File

@ -1,7 +1,7 @@
{ {
"$schema": "https://schema.kunkun.sh", "$schema": "https://schema.kunkun.sh",
"name": "kunkun-ext-youtube-dowloader", "name": "kunkun-ext-youtube-dowloader",
"version": "0.1.1", "version": "0.1.2",
"license": "MIT", "license": "MIT",
"type": "module", "type": "module",
"kunkun": { "kunkun": {

View File

@ -180,7 +180,7 @@ class DownloadYouTubeExtension extends WorkerExtension {
} }
let url = await clipboard.readText(); let url = await clipboard.readText();
// url = "https://youtu.be/-b1FogYHTZc"; // for development only url = "https://youtu.be/-b1FogYHTZc"; // for development only
// check if url is a valid youtube url // check if url is a valid youtube url
if (!url.includes("youtube.com") && !url.includes("youtu.be")) { if (!url.includes("youtube.com") && !url.includes("youtu.be")) {
toast.warning("Invalid YouTube URL from clipboard"); toast.warning("Invalid YouTube URL from clipboard");
@ -189,8 +189,10 @@ class DownloadYouTubeExtension extends WorkerExtension {
const formats = await this.rpc.api.getAvailableResolutions(url); const formats = await this.rpc.api.getAvailableResolutions(url);
const form = new Form.Form({ const form = new Form.Form({
title: "Download YouTube Video", title: "Download YouTube Video",
description: "Please copy a YouTube URL then enter this extension.", description: `Please copy a YouTube URL then enter this extension.
key: "form1", High Resolution video (e.g. 4K) could take a very long time to download, please be patient.
A progress bar with estimated time isn't implemented yet. There is a loading bar on the top.`,
key: "download-youtube-video",
showFormDataDebug: true, showFormDataDebug: true,
submitBtnText: "Download", submitBtnText: "Download",
fields: [ fields: [