function downloadVideo(url) {
// Extract the video or playlist ID from the URL
const videoId = getVideoIdFromUrl(url);
// Set the API endpoint and your API key
const apiEndpoint = 'https://example.com/youtube-dl';
const apiKey = 'YOUR_API_KEY';
// Set the desired format and resolution
const format = 'mp4';
const resolution = '720p';
// Send a GET request to the API
fetch(`${apiEndpoint}?id=${videoId}&format=${format}&resolution=${resolution}`, {
headers: {
'Authorization': `apikey ${apiKey}`
}
})
.then(response => response.json())
.then(data => {
// Download the video or playlist
const link = document.createElement('a');
link.href = data.download_url;
link.download = data.file_name;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
});
}
// Extract the video or playlist ID from the URL
function getVideoIdFromUrl(url) {
// ...
}
const form = document.querySelector('form');
form.addEventListener('submit', event => {
event.preventDefault();
const url = document.querySelector('#video-url').value;
downloadVideo(url);
});
Comments
Post a Comment