Created
January 15, 2025 16:25
-
-
Save kukicado/e649cfbe225a926ab3743c4977179255 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { spawn } = require('child_process'); | |
const videoUrls = ["YOUR-TIKTOK-VIDEO-THAT-YOU-WANT-TO-DOWNLOAD"]; | |
async function downloadVideo(videoUrl) { | |
return new Promise((resolve, reject) => { | |
const ytDlpProcess = spawn('yt-dlp', [videoUrl]); | |
ytDlpProcess.stdout.on('data', (data) => { | |
console.log(`yt-dlp stdout: ${data}`); | |
}); | |
ytDlpProcess.stderr.on('data', (data) => { | |
console.error(`yt-dlp stderr: ${data}`); | |
}); | |
ytDlpProcess.on('close', (code) => { | |
if (code === 0) { | |
console.log(`Successfully downloaded: ${videoUrl}`); | |
resolve(); | |
} else { | |
console.error(`yt-dlp process exited with code ${code} for ${videoUrl}`); | |
reject(new Error(`yt-dlp failed with code ${code}`)); | |
} | |
}); | |
ytDlpProcess.on('error', (err) => { | |
console.error(`Failed to start yt-dlp for ${videoUrl}: ${err.message}`); | |
reject(err); | |
}); | |
}); | |
} | |
async function downloadVideosSequentially() { | |
if (videoUrls.length === 0) { | |
console.log("No video URLs provided. Add URLs to the 'videoUrls' array."); | |
return; | |
} | |
let currentIndex = 0; | |
const intervalId = setInterval(async () => { | |
if (currentIndex < videoUrls.length) { | |
const videoUrl = videoUrls[currentIndex]; | |
console.log(`Downloading video ${currentIndex + 1}/${videoUrls.length}: ${videoUrl}`); | |
try { | |
await downloadVideo(videoUrl); | |
} catch (error) { | |
console.error(`Error downloading ${videoUrl}: ${error.message}`); | |
// Optionally handle the error - e.g., skip to the next video | |
} | |
currentIndex++; | |
} else { | |
clearInterval(intervalId); | |
console.log("All videos downloaded."); | |
} | |
}, 1000); // Download one video every 1000 milliseconds (1 second) | |
} | |
// Start the download process | |
downloadVideosSequentially(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment