SkyX
SkyX

Reputation: 1

Download mp4 files at once with jQuery via console

I am opening HTML pages in a new window. These pages have a media file ".mp4" among other tags. I am able to save the page through this code:

How to download only the media inside of each HTML page opened? There is a way to find and save any media these pages load?

var anchor = document.getElementsByTagName('a');
for (var i=0; i < anchor.length; i++){

    fetch(anchor[i].href)
        .then(resp => resp.blob())
        .then(blob => {
            const url = window.URL.createObjectURL(blob);
            const a = document.createElement('a');
            a.style.display = 'none';
            a.href = url;
            a.setAttribute('target', '_blank');
            a.download = anchor[i].innerText; // the file name
            document.body.appendChild(a);
            a.click();
            window.URL.revokeObjectURL(url);
        });
}

Upvotes: 0

Views: 864

Answers (1)

Ricardo Madela
Ricardo Madela

Reputation: 95

Try this:

    var a = document.getElementsByTagName("video");
for(i of a){
console.log(i.src);
fetch(i.src)
.then(resp => resp.blob())
.then(blob => {
    const url = window.URL.createObjectURL(blob);
    const b = document.createElement('a');
    b.style.display = 'none';
    b.href = url;
    b.setAttribute("download", 'arquivo.mp4')
    b.download = 'arquivo.mp4'; // the file name
    document.body.appendChild(b);
    b.click();
    window.URL.revokeObjectURL(url);
});
};

Upvotes: 1

Related Questions