Mp4Hydra Movie/Video Downloader

Adds a movie download button to the mp4hydra.org video player. Clicking the button will start the download of the mp4 video file.

< Feedback on Mp4Hydra Movie/Video Downloader

Review: Good - script works

§
Posted: 10.01.2024.
Edited: 10.01.2024.

Your code isn't working, but I was able to fix it. Here is the corrected code:

// ==UserScript== // @name Mp4Hydra Movie/Video Downloader // @namespace https://greasyfork.org/ // @version 1.13 // @description Adds a movie download button to the mp4hydra.org video player. Clicking the button will start the download of the mp4 video file. // @author paleocode // @match https://mp4hydra.org/movie/* // @icon https://mp4hydra.org/favicon-32x32.png // @license MIT // @unwrap // @downloadURL https://update.greasyfork.org/scripts/484039/Mp4Hydra%20MovieVideo%20Downloader.user.js // @updateURL https://update.greasyfork.org/scripts/484039/Mp4Hydra%20MovieVideo%20Downloader.meta.js // ==/UserScript==

(function () { if (document.title === 'Movie Not Found | Mp4Hydra.org') { return; }

function getVideoSrc() {
    var player = document.querySelector('video'); // Assuming the video player is a <video> element
    if (player) {
        var src = player.src;
        console.log("Source: " + src);
        return src;
    }
    return null;
}

var button = Object.assign(document.createElement('button'), {
    innerHTML: 'Download',
    title: 'Download Movie',
    style: 'display: inline-block; margin: 0 0 0 10px; color: #000;',
    onclick: function () {
        var vidSrc = getVideoSrc();
        if (vidSrc) {
            var link = document.createElement("a");
            link.href = vidSrc + '?dl=dl';
            link.setAttribute('download', 'video.mp4'); // Set a default filename
            document.body.appendChild(link);
            link.click();
            document.body.removeChild(link);
        }
    }
});

const interval = setInterval(function () {
    var vcount = document.querySelector('#vcount > small');
    if (!vcount || vcount.innerText === "---") return;

    clearInterval(interval);
    var videoSrc = getVideoSrc();
    if (videoSrc) {
        document.querySelector('#vbar').appendChild(button);
    }
}, 100);

})();

Fixed:

Added a check to ensure the video player element (<video>) is properly obtained.

Improved the naming and scoping of variables (vidSrc -> videoSrc for clarity).

Set the download attribute for the created <a> element to suggest a default filename for the downloaded video.

hope this helps.

paleocodeAuthor
§
Posted: 10.01.2024.

Thanks, I will implement these changes soon. I should have tested the previous code on more browsers. Your improvements also gets the new source if the user changes video server, which is much better.

Post reply

Sign in to post a reply.