From da9a6e40f9da2dbe5a97b3102d914328888e6631 Mon Sep 17 00:00:00 2001 From: pacnpal <183241239+pacnpal@users.noreply.github.com> Date: Fri, 15 Nov 2024 00:53:56 +0000 Subject: [PATCH] fix: Properly validate URLs using extractors' suitable() method --- videoarchiver/utils/video_downloader.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/videoarchiver/utils/video_downloader.py b/videoarchiver/utils/video_downloader.py index 85e372a..9a3ac4c 100644 --- a/videoarchiver/utils/video_downloader.py +++ b/videoarchiver/utils/video_downloader.py @@ -5,6 +5,7 @@ import logging import asyncio import ffmpeg import yt_dlp +import shutil from concurrent.futures import ThreadPoolExecutor from typing import Dict, List, Optional, Tuple from pathlib import Path @@ -301,9 +302,21 @@ class VideoDownloader: """Check if URL is supported""" try: with yt_dlp.YoutubeDL() as ydl: - # Try to extract info without downloading - ie = ydl.extract_info(url, download=False, process=False) - return ie is not None + # Get extractors + extractors = ydl._ies + # Try each extractor + for extractor in extractors: + if hasattr(extractor, '_VALID_URL') and extractor._VALID_URL: + # Skip if site is not enabled + if self.enabled_sites and not any( + site.lower() in extractor.IE_NAME.lower() + for site in self.enabled_sites + ): + continue + # Try to match URL + if extractor.suitable(url): + return True + return False except Exception as e: logger.error(f"Error checking URL support: {str(e)}") return False