(async function () {

  const delay = ms => new Promise(res => setTimeout(res, ms));


  // 1) Auto-scroll to load lazy items

  let lastHeight = -1;

  while (document.body.scrollHeight !== lastHeight) {

    lastHeight = document.body.scrollHeight;

    window.scrollTo(0, document.body.scrollHeight);

    await delay(1200);

  }


  // 2) Collect links

  const links = [];

  const cards = document.querySelectorAll("div.tw-aspect-video");

  for (const card of cards) {

    try {

      const img = card.querySelector("img");

      if (!img || !img.src) continue;


      const parts = img.src.split("/");

      const randomToken = parts[parts.length - 2] || "";

      const videoId = (parts[parts.length - 1] || "").split(".")[0] || "";


      // 3) Try to find the displayed filename by searching ancestors for a span with .txt/.mp4

      let filename = null;

      let node = card;

      for (let i = 0; i < 8 && node; i++) {

        const spans = node.querySelectorAll("span");

        for (const s of spans) {

          const t = s.textContent.trim();

          if (!t) continue;

          // Prefer span texts that end with common extensions (txt/mp4/etc)

          if (/\.(txt|mp4|mov|mkv|avi)$/i.test(t)) {

            filename = t;

            break;

          }

          // Sometimes UI shows names without extension — try short heuristic (has underscore + digits)

          if (/^\d+[_\-\w ]+\.[a-z]{1,5}$/i.test(t)) {

            filename = t;

            break;

          }

        }

        if (filename) break;

        node = node.parentElement;

      }


      // fallback: try a few common selectors near card

      if (!filename) {

        const alt = card.parentElement?.querySelector("span.tw-text-ellipsis, span.tw-overflow-hidden, span.tw-text-textTitle span");

        if (alt) filename = alt.textContent.trim();

      }


      // final fallback -> videoId

      if (!filename) filename = videoId || "video";


      // Ensure file ends with .mp4 (if UI shows "name.txt", we keep it and add .mp4 -> name.txt.mp4)

      if (!/\.(mp4|mov|mkv|avi)$/i.test(filename)) {

        filename = filename + ".mp4";

      }


      // Build final base URL and percent-encoded query param

      const baseUrl = `https://resource2.heygen.ai/video/transcode/${videoId}/${randomToken}/1920x1080.mp4`;

      const q = encodeURIComponent(`attachment; filename*=UTF-8''${filename};`);

      const final = `${baseUrl}?response-content-disposition=${q}`;


      links.push(final);

    } catch (err) {

      console.error("card error", err);

    }

  }


  console.log("✅ Found", links.length, "links");

  console.log(links.join("\n"));


  // copy to clipboard for quick paste

  try {

    await navigator.clipboard.writeText(links.join("\n"));

    console.log("✅ Links copied to clipboard");

  } catch (e) {

    console.warn("Could not copy to clipboard:", e);

  }


  return links;

})();



## run above code in console to get all the download links... run below code in python script to download one by one. replace the URLs

import requests
import time
import os
import re
from urllib.parse import unquote

# Paste all your download links here
video_urls = [
    "https://resource2.heygen.ai/video/transcode/9c99dccf700d47e6bff85e5bd67534e5/vG6x8dR304x3xM3bUEeoBUoAtwCycToxM/1920x1080.mp4?response-content-disposition=attachment%3B%20filename*%3DUTF-8''29_side_effects.txt.mp4%3B",
    "https://resource2.heygen.ai/video/transcode/ed9a623ea2e64f539ca14ce2b8e183e2/vQ9OM0A5yc1cReaWQja6TxQ0SbBCAypUi/1920x1080.mp4?response-content-disposition=attachment%3B%20filename*%3DUTF-8''29_introduction.txt.mp4%3B",
    "https://resource2.heygen.ai/video/transcode/c0825f5209334d668db7b2c1346fe37a/vsU4Gg2a56FGCWHcF32foNBfU3VkEa5is/1920x1080.mp4?response-content-disposition=attachment%3B%20filename*%3DUTF-8''29_how_to_use.txt.mp4%3B",
    # ... add rest of your links here
]

# Folder to save videos
save_folder = "downloaded_videos"
os.makedirs(save_folder, exist_ok=True)

for idx, url in enumerate(video_urls, start=1):
    try:
        # Extract filename from query param
        match = re.search(r"filename\*%3DUTF-8''([^%]+)", url)
        if match:
            file_name = unquote(match.group(1))  # decode %20 etc.
        else:
            file_name = f"video_{idx}.mp4"

        file_path = os.path.join(save_folder, file_name)

        print(f"▶️ Downloading ({idx}/{len(video_urls)}): {file_name}")
        response = requests.get(url, stream=True)
        response.raise_for_status()

        with open(file_path, "wb") as f:
            for chunk in response.iter_content(chunk_size=1024 * 1024):
                f.write(chunk)

        print(f"✅ Saved: {file_path}")

        # Wait 2 minutes before next file
        if idx < len(video_urls):
            print("⏳ Waiting 2 minutes before next download...")
            time.sleep(120)

    except Exception as e:
        print(f"❌ Failed to download {url}: {e}")

Next
This is the most recent post.
Previous
Older Post

0 comments:

Post a Comment

 
Top