File size: 1,454 Bytes
5efa6b0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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);
}