DEV Community

Cover image for Preventing IDM: A Tactical Guide to Protecting Your Video Content on Website
Kareem Khaled
Kareem Khaled

Posted on

Preventing IDM: A Tactical Guide to Protecting Your Video Content on Website

Introduction

Ever put your heart and soul into making a stunning video only to see it being ripped and shared all over the internet without your permission? If you nodding, then most probably IDM is familiar to you. This powerhouse of a tool might be deemed a godsend for users in a zeal of downloading videos, but surely a bane upon creators like us enthralled with the prospects of protection from cyber theft of our treasured content.

Now, here's the challenge:

Any website has no direct access to your system's processes, so we can't simply ask, "Hey, is IDM running?" But, fellow creators, fear not! We're about to outsmart IDM a little with some clever code and tactical maneuvering.

Tell-tale Sign of IDM: The Video Tag

IDM isn't subtle, like most download managers, in targeting a video. It leaves a fingerprint in the form of a custom attribute, "idm_id", on the video tag. This is how IDM keeps track of which videos to snatch. But that very attribute is its Achilles' heel, and we're going to exploit it.

function checkForIDM() {
    const videos = document.getElementsByTagName('video');
    for (const video of videos) {
        if (video.hasAttribute('__idm_id__')) {
            return true; // IDM is likely running
        }
    }
    return false; // IDM not detected (yet)
}
Enter fullscreen mode Exit fullscreen mode

One of our Lines of Defense: The IDM Detector

This JavaScript snippet will check your page for the presence of the "idm_id" attribute once every second. If it is found, we know IDM is on the prowl.

let idmCheckInterval;

function startIDMCheck() {
    idmCheckInterval = setInterval(() => {
        if (checkForIDM()) {
            clearInterval(idmCheckInterval);
            blockContent(); // (see next snippet)
        }
    }, 1000); // Check every second
}

startIDMCheck(); // Begin monitoring immediately
Enter fullscreen mode Exit fullscreen mode

Block and Redirect: When IDM Strikes

If IDM is detected, we need to act fast. Here's how we'll block the content and give the user clear instructions:

function blockContent() {
    const content = document.body.innerHTML;
    document.body.innerHTML = `
        <h1>IDM Detected</h1>
        <p>Please disable IDM and reload the page to view this content.</p>
        <button onclick="location.reload()">Reload</button>
    `;
}
Enter fullscreen mode Exit fullscreen mode

The Bait-and-Switch: Protecting Your Video URL

But we're not done yet. Though we block IDM, it might have taken your video URL. To counter this, we're going to do a little trickery.

  1. When the page loads, embed your video with a fake URL (like some very short, silent video).
  2. After 5 seconds, start a timer.
  3. If there is no IDM activity within those 5 seconds, we know we are in the clear.
  4. Replace this with your actual video source.
const realVideoSrc = "your-actual-video.mp4";
const fakeVideoSrc = "dummy-video.mp4";

function swapVideoSrc() {
    const video = document.querySelector('video');
    video.src = realVideoSrc;
}

setTimeout(() => {
    if (!checkForIDM()) {
        swapVideoSrc();
    }
}, 5000); // Replace after 5 seconds if safe
Enter fullscreen mode Exit fullscreen mode

Don't Forget..

This is a good base but this fight against downloaders never gets really won. You may need to tune these techniques from time to time when new tools are invented .

Let's Chat!

I'd love to hear your thoughts on this approach. Have you faced similar challenges? Do you have other tricks up your sleeve? Feel free to drop a comment below or reach out to me via email at karemkhaled945@gmail.com .
Let's geek out about video protection together!

Top comments (0)