mirror of
https://github.com/pacnpal/Pac-cogs.git
synced 2025-12-20 10:51:05 -05:00
fix: Improve URL validation and extraction - Use suitable() method for URL validation - Add word-based URL detection - Fix URL extraction errors
This commit is contained in:
@@ -257,7 +257,8 @@ class VideoProcessor:
|
|||||||
settings = await self.config.get_guild_settings(message.guild.id)
|
settings = await self.config.get_guild_settings(message.guild.id)
|
||||||
|
|
||||||
# Check if message is in a monitored channel
|
# Check if message is in a monitored channel
|
||||||
if message.channel.id not in settings["monitored_channels"]:
|
monitored_channels = settings.get("monitored_channels", [])
|
||||||
|
if monitored_channels and message.channel.id not in monitored_channels:
|
||||||
return
|
return
|
||||||
|
|
||||||
# Find all video URLs in message with improved pattern matching
|
# Find all video URLs in message with improved pattern matching
|
||||||
@@ -282,13 +283,16 @@ class VideoProcessor:
|
|||||||
"""Extract video URLs from message content with improved pattern matching"""
|
"""Extract video URLs from message content with improved pattern matching"""
|
||||||
urls = []
|
urls = []
|
||||||
try:
|
try:
|
||||||
|
# Create a YoutubeDL instance to get extractors
|
||||||
with yt_dlp.YoutubeDL() as ydl:
|
with yt_dlp.YoutubeDL() as ydl:
|
||||||
for ie in ydl._ies:
|
# Split content into words and check each for URLs
|
||||||
if ie._VALID_URL:
|
words = content.split()
|
||||||
# Use more specific pattern matching
|
for word in words:
|
||||||
pattern = f"(?P<url>{ie._VALID_URL})"
|
# Try each extractor
|
||||||
matches = re.finditer(pattern, content, re.IGNORECASE)
|
for ie in ydl._ies:
|
||||||
urls.extend(match.group("url") for match in matches)
|
if ie.suitable(word):
|
||||||
|
urls.append(word)
|
||||||
|
break # Stop once we find a matching extractor
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"URL extraction error: {str(e)}")
|
logger.error(f"URL extraction error: {str(e)}")
|
||||||
return list(set(urls)) # Remove duplicates
|
return list(set(urls)) # Remove duplicates
|
||||||
|
|||||||
Reference in New Issue
Block a user