Spaces:
Running
Running
async function downloadReel() { | |
const reelUrl = document.getElementById('reelUrl').value.trim(); | |
const messageDiv = document.getElementById('message'); | |
const downloadLinkDiv = document.getElementById('downloadLink'); | |
// Clear previous messages | |
messageDiv.textContent = ''; | |
downloadLinkDiv.innerHTML = ''; | |
// Check if the URL is empty or invalid | |
if (!reelUrl || !isValidUrl(reelUrl)) { | |
messageDiv.textContent = 'Please enter a valid Instagram Reel URL.'; | |
return; | |
} | |
// Display loading message | |
messageDiv.textContent = 'Processing... Please wait.'; | |
try { | |
const response = await fetch(`https://slimshadow-instagram-r-api.hf.space/download/?reel_url=${encodeURIComponent(reelUrl)}`); | |
const data = await response.json(); | |
if (data && data.url) { | |
// Display download link | |
messageDiv.textContent = 'Reel downloaded successfully!'; | |
downloadLinkDiv.innerHTML = `<a href="${data.url}" download>Click here to download the Reel</a>`; | |
} else { | |
messageDiv.textContent = 'Failed to fetch Reel. Please try again later.'; | |
} | |
} catch (error) { | |
messageDiv.textContent = 'An error occurred. Please try again later.'; | |
} | |
} | |
// Function to validate the URL format | |
function isValidUrl(url) { | |
const regex = /^(https?:\/\/)?(www\.)?instagram\.com\/reel\/[A-Za-z0-9_-]+$/; | |
return regex.test(url); | |
} | |