algolia / youtube-captions-scraper

Fetch youtube user submitted or fallback to auto-generated captions
249 stars 67 forks source link

Did it stop working? #20

Closed leleitu closed 10 months ago

leleitu commented 11 months ago

I am not getting responses anymore. code seems to be right

import { getSubtitles } from 'youtube-captions-scraper';

// Get references to HTML elements const videoLinkInput = document.getElementById('videoLink'); const fetchCaptionsButton = document.getElementById('fetchCaptions'); const captionsList = document.getElementById('captionsList');

// Add a click event listener to the "Fetch Captions" button fetchCaptionsButton.addEventListener('click', async () => { const videoURL = videoLinkInput.value.trim();

if (videoURL) {
    try {
        const videoID = getVideoID(videoURL);

        // Always specify 'en' as the language code
        const lang = 'en';

        const captions = await getSubtitles({ videoID, lang });

        if (captions && captions.length > 0) {
            displayCaptions(captions);
        } else {
            captionsList.innerHTML = '<li>No captions available for this video.</li>';
        }
    } catch (error) {
        console.error('Error fetching captions:', error.message || error);
        captionsList.innerHTML = '<li>Error fetching captions. Please check the video link.</li>';
    }
} else {
    captionsList.innerHTML = '<li>Please enter a valid YouTube video link.</li>';
}

});

// Helper function to extract the video ID from the URL function getVideoID(url) { const match = url.match(/(?:v=|\/)([a-zA-Z0-9_-]{11})/); return match ? match[1] : null; }

// Helper function to display captions in the list function displayCaptions(captions) { captionsList.innerHTML = ''; captions.forEach((caption, index) => { const listItem = document.createElement('li'); listItem.textContent = ${index + 1}. ${caption.text}; captionsList.appendChild(listItem); }); }

briansunter commented 11 months ago

Seeing the same thing in the past few days.


TypeError: Invalid attempt to destructure non-iterable instance

 at index.js:8:585
    at index.js:26:24
    at Generator.next (<anonymous>)
    at step (index.js:103:187)
    at index.js:103:361
g```
leleitu commented 11 months ago

Kind of fixed it. gave on up the library and used https://github.com/devhims/youtube-caption-extractor

briansunter commented 11 months ago

Same. That other library is working for me

vgulerianb commented 11 months ago

I have raised a PR #21. Not sure if it will get merged or not

alieneby commented 11 months ago

thx. I have the same problems since some days. Perhaps I will try the other solution too.

Haroenv commented 10 months ago

I believe the latest 2.0.1 has fixed it, thanks @vgulerianb for your PR!