audiodl-mp3
Advanced tools
Comparing version 1.4.2 to 1.4.3
@@ -21,3 +21,3 @@ import { MoreVideoDetails } from 'ytdl-core'; | ||
constructor(); | ||
videoToAudio(videoData: Buffer, outputFile: string): void; | ||
videoToAudio(videoData: Buffer, outputFile: string): Promise<void>; | ||
} | ||
@@ -24,0 +24,0 @@ |
@@ -9,3 +9,2 @@ // src/Downloader.ts | ||
import cp from "child_process"; | ||
import fs2 from "fs"; | ||
import ffmpeg from "ffmpeg-static"; | ||
@@ -81,8 +80,24 @@ | ||
} | ||
videoToAudio(videoData, outputFile) { | ||
if (fs2.existsSync(outputFile)) { | ||
throw new YtdlMp3Error(`Output file already exists: ${outputFile}`); | ||
async videoToAudio(videoData, outputFile) { | ||
if (!this.ffmpegBinary) { | ||
throw new YtdlMp3Error("Failed to resolve ffmpeg binary"); | ||
} | ||
cp.execSync(`${this.ffmpegBinary} -loglevel 24 -i pipe:0 -vn -sn -c:a mp3 -ab 320k ${outputFile}`, { | ||
input: videoData | ||
const ffmpegOptions = ["-loglevel", "24", "-i", "pipe:0", "-vn", "-sn", "-c:a", "mp3", "-ab", "320k", outputFile]; | ||
return new Promise((resolve, reject) => { | ||
try { | ||
const ffmpegProcess = cp.spawn(this.ffmpegBinary, ffmpegOptions); | ||
ffmpegProcess.on("exit", (code) => { | ||
if (code !== 0) { | ||
reject(new YtdlMp3Error(`FFmpeg process exited with code ${code}`)); | ||
} else { | ||
console.log("Conversion completed successfully."); | ||
resolve(); | ||
} | ||
}); | ||
ffmpegProcess.on("error", (err) => { | ||
reject(new YtdlMp3Error(`Error during FFmpeg spawn: ${err.message}`)); | ||
}); | ||
} catch (error) { | ||
reject(new YtdlMp3Error(`Error during FFmpeg execution: ${error.message}`)); | ||
} | ||
}); | ||
@@ -107,4 +122,5 @@ } | ||
const result = verify ? await this.getVerifiedResult(searchResults) : searchResults[0]; | ||
const artworkUrl = result.artworkUrl100.length > 0 ? result.artworkUrl100.replace("100x100bb.jpg", "600x600bb.jpg") : result.artworkUrl; | ||
const albumArt = await this.fetchAlbumArt(artworkUrl); | ||
const albumArt = await this.fetchAlbumArt( | ||
result.artworkUrl100.length > 0 ? result.artworkUrl100.replace("100x100bb.jpg", "600x600bb.jpg") : result.artworkUrl | ||
); | ||
const songYear = await this.processDate(result?.releaseDate); | ||
@@ -233,3 +249,3 @@ return { | ||
// src/Downloader.ts | ||
import fs3 from "fs"; | ||
import fs2 from "fs"; | ||
var Downloader = class _Downloader { | ||
@@ -279,3 +295,3 @@ constructor(options) { | ||
let suffix = 1; | ||
while (fs3.existsSync(path.join(outputDir, fileName))) { | ||
while (fs2.existsSync(path.join(outputDir, fileName))) { | ||
fileName = `${baseFileName}_${suffix}.mp3`; | ||
@@ -282,0 +298,0 @@ suffix++; |
{ | ||
"name": "audiodl-mp3", | ||
"version": "1.4.2", | ||
"version": "1.4.3", | ||
"description": "An NPM package to facilitate downloading music from YouTube, including automatic retrieval of ID3 tags and album art via the iTunes public API.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
77722
772
4