Add Dockerfile for application setup, update next.config.ts for standalone output, enhance documentation for FFMPEG_PATH, and implement ffmpeg location flag in download functionality
This commit is contained in:
@@ -13,6 +13,12 @@ function getYtDlpPath(): string {
|
||||
return process.env.YT_DLP_PATH || 'yt-dlp';
|
||||
}
|
||||
|
||||
// Get ffmpeg location flag for yt-dlp (optional)
|
||||
function getFfmpegLocationFlag(): string {
|
||||
const ffmpegPath = process.env.FFMPEG_PATH;
|
||||
return ffmpegPath ? `--ffmpeg-location "${ffmpegPath}"` : '';
|
||||
}
|
||||
|
||||
const DOWNLOADS_DIR = path.join(process.cwd(), 'downloads');
|
||||
const PUBLIC_DOWNLOADS_DIR = path.join(process.cwd(), 'public', 'downloads');
|
||||
|
||||
@@ -102,19 +108,21 @@ export async function downloadVideo(
|
||||
const outputPath = path.join(DOWNLOADS_DIR, `${fileId}.%(ext)s`);
|
||||
const finalPath = path.join(PUBLIC_DOWNLOADS_DIR, `${fileId}.${outputExt}`);
|
||||
|
||||
// Get yt-dlp path at runtime
|
||||
// Get yt-dlp path and ffmpeg location at runtime
|
||||
const ytDlpPath = getYtDlpPath();
|
||||
const ffmpegFlag = getFfmpegLocationFlag();
|
||||
console.log('[downloadVideo] Using yt-dlp path:', ytDlpPath);
|
||||
if (ffmpegFlag) console.log('[downloadVideo] Using ffmpeg location flag:', ffmpegFlag);
|
||||
|
||||
// Download with yt-dlp
|
||||
let command = `"${ytDlpPath}" -f "${ytDlpFormat}" -o "${outputPath}" "${url}"`;
|
||||
let command = `"${ytDlpPath}" ${ffmpegFlag} -f "${ytDlpFormat}" -o "${outputPath}" "${url}"`;
|
||||
|
||||
if (formatType === 'audio' && format === 'mp3') {
|
||||
// For MP3, we need to extract audio and convert
|
||||
command = `"${ytDlpPath}" -f "bestaudio[ext=m4a]/bestaudio" -x --audio-format mp3 --audio-quality 0 -o "${outputPath}" "${url}"`;
|
||||
command = `"${ytDlpPath}" ${ffmpegFlag} -f "bestaudio[ext=m4a]/bestaudio" -x --audio-format mp3 --audio-quality 0 -o "${outputPath}" "${url}"`;
|
||||
} else if (formatType === 'audio' && format === 'wav') {
|
||||
// For WAV, extract and convert
|
||||
command = `"${ytDlpPath}" -f "bestaudio[ext=m4a]/bestaudio" -x --audio-format wav -o "${outputPath}" "${url}"`;
|
||||
command = `"${ytDlpPath}" ${ffmpegFlag} -f "bestaudio[ext=m4a]/bestaudio" -x --audio-format wav -o "${outputPath}" "${url}"`;
|
||||
}
|
||||
|
||||
// Increase maxBuffer for downloads as well
|
||||
|
||||
Reference in New Issue
Block a user