Only accept URLs that match known video platform patterns (YouTube, Vimeo, TikTok, etc.)

Accept URLs that end in video file extensions (.mp4, .webm, .mov)
Reject invalid URLs like "huge." that don't match any video patterns
This commit is contained in:
pacnpal
2024-11-15 18:50:39 +00:00
parent 61fbe7ca49
commit 8b0103ca08

View File

@@ -7,7 +7,7 @@ import discord
from discord.ext import commands from discord.ext import commands
from discord import app_commands from discord import app_commands
from pathlib import Path from pathlib import Path
from typing import Dict, Any, Optional, Tuple, Set from typing import Dict, List, Optional, Tuple, Callable, Set
import traceback import traceback
from datetime import datetime from datetime import datetime
@@ -19,6 +19,7 @@ from videoarchiver.utils.exceptions import (
QueueError, QueueError,
FileOperationError FileOperationError
) )
from videoarchiver.utils.video_downloader import is_video_url_pattern
logger = logging.getLogger("VideoArchiver") logger = logging.getLogger("VideoArchiver")
@@ -211,8 +212,8 @@ class VideoProcessor:
for word in message.content.split(): for word in message.content.split():
# Log each word being checked # Log each word being checked
logger.debug(f"Checking word: {word}") logger.debug(f"Checking word: {word}")
# Basic URL validation - must start with http/https or contain a dot # Use proper video URL validation
if word.startswith(('http://', 'https://')) or '.' in word: if is_video_url_pattern(word):
# If no sites are enabled, accept all URLs # If no sites are enabled, accept all URLs
# Otherwise, check if URL contains any enabled site # Otherwise, check if URL contains any enabled site
if not enabled_sites or any(site in word.lower() for site in enabled_sites): if not enabled_sites or any(site in word.lower() for site in enabled_sites):
@@ -221,7 +222,7 @@ class VideoProcessor:
else: else:
logger.debug(f"URL {word} doesn't match any enabled sites") logger.debug(f"URL {word} doesn't match any enabled sites")
else: else:
logger.debug(f"Word {word} is not a valid URL") logger.debug(f"Word {word} is not a valid video URL")
# Add attachment URLs # Add attachment URLs
for attachment in message.attachments: for attachment in message.attachments: