@lunarity/nebula-fetch-cli 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # nebula-fetch-cli
package/bun.lockb ADDED
Binary file
@@ -0,0 +1,39 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+
4
+ import { YtdlCore, toPipeableStream } from "@ybd-project/ytdl-core";
5
+ import chalk from "chalk";
6
+
7
+ export async function downloadYoutubeAudio(
8
+ url: string,
9
+ outputPath?: string
10
+ ): Promise<void> {
11
+ try {
12
+ if (!url) {
13
+ throw new Error("Please provide a YouTube URL");
14
+ }
15
+
16
+ console.log(chalk.cyan("🔍 Fetching video information..."));
17
+ const ytdl = new YtdlCore({});
18
+ let videoTitle = "";
19
+
20
+ await ytdl.getBasicInfo(url).then((info) => {
21
+ videoTitle = info.videoDetails.title.replace(/[^\w\s]/gi, "_");
22
+ });
23
+
24
+ const stream = await ytdl.download(url, {
25
+ filter: "audioonly",
26
+ });
27
+
28
+ const outputFilePath =
29
+ outputPath || path.join(process.cwd(), `${videoTitle}.mp3`);
30
+ toPipeableStream(stream).pipe(fs.createWriteStream(outputFilePath));
31
+
32
+ console.log(chalk.green(`✅ Download finished: ${outputFilePath}`));
33
+ } catch (error) {
34
+ if (error instanceof Error) {
35
+ console.error(chalk.red("Error:", error.message));
36
+ }
37
+ throw error;
38
+ }
39
+ }