Need help building a python video downloader script other than youtube and it’s pytube lib

As per the title building a python video downloader script other than youtube and it’s pytube lib and to get straight to it, using chatgpt here’s what I’m currently at:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
from bs4 import BeautifulSoup
from tqdm import tqdm
import requests

def extract_video_urls(url):
    # Configure Chrome options
    chrome_options = Options()
    chrome_options.add_argument('--headless')  # Run Chrome in headless mode
    chrome_options.add_argument('--disable-gpu')  # Disable GPU acceleration

    # Path to Chrome WebDriver executable
    webdriver_service = Service('path/to/chromedriver')

    # Initialize Chrome WebDriver
    driver = webdriver.Chrome(service=webdriver_service, options=chrome_options)

    try:
        # Load the webpage
        driver.get(url)

        # Extract video URLs using JavaScript
        video_urls = driver.execute_script("""
            var videos = [];
            var videoElements = document.querySelectorAll('video');
            videoElements.forEach(function(video) {
                videos.push(video.src);
            });
            return videos;
        """)

        return video_urls
    finally:
        # Close the WebDriver session
        driver.quit()


def download_video(url, filename):
    """Downloads a video from the given URL and saves it with the specified filename."""
    try:
        response = requests.get(url, stream=True)
        response.raise_for_status()  # Raise exception for non-200 status codes

        total_size = int(response.headers.get('content-length', 0))
        chunk_size = 1024
        progress_bar = tqdm(total=total_size, unit='B', unit_scale=True, desc=filename)

        with open(filename, 'wb') as f:
            for chunk in response.iter_content(chunk_size=chunk_size):
                if chunk:
                    f.write(chunk)
                    progress_bar.update(len(chunk))

        progress_bar.close()
        print(f"nDownloaded video: {filename}")
    except requests.exceptions.RequestException as e:
        print(f"Error downloading video: {e}")


def main():
    website_url = input("Enter website URL: ")

    video_urls = extract_video_urls(website_url)

    if video_urls:
        print("Found video URLs:")
        for i, url in enumerate(video_urls):
            print(f"{i+1}. {url}")
        download_choice = input("Enter video number to download (or 0 to exit): ")
        if download_choice.isdigit() and int(download_choice) > 0:
            video_index = int(download_choice) - 1
            if 0 <= video_index < len(video_urls):
                filename = f"video_{video_index + 1}.mp4"  # Adjust filename format
                download_video(video_urls[video_index], filename)
            else:
                print("Invalid video number.")
    else:
        print("No video URLs found on the provided webpage.")

if __name__ == "__main__":
    main()
  • But eventually I end up with an exception that’s caught by the download_video function like so:
    Error downloading video: No connection adapters were found for ‘blob:https://www.ted.com/45e459e3-974b- 417c-8f05-0a92cac0f22e’

  • Which after lengthy chats with various LLMs i got to learn that:

    • Downloading a video from a blob URL can be a bit tricky because a blob URL does not refer to a direct file that can be downloaded; it refers to binary data stored in the browser’s memory.
    • And that typically, to download a video from a blob URL, you need to extract the actual video file URL from the network requests made by the browser.
  • But eventually I end up with an exception that’s caught by the download_video function like so:
    Error downloading video: No connection adapters were found for ‘blob:https://www.ted.com/45e459e3-974b- 417c-8f05-0a92cac0f22e’

  • Which after lengthy chats with various LLMs i got to learn that:

    • Downloading a video from a blob URL can be a bit tricky because a blob URL does not refer to a direct file that can be downloaded; it refers to binary data stored in the browser’s memory.
    • And that typically, to download a video from a blob URL, you need to extract the actual video file URL from the network requests made by the browser.

I simply need a way or an approach to be able to download a video from websites other that youtube

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật