Add yt-dlp error parser for user-friendly messages

Introduces the parse_yt_dlp_error function to convert raw yt-dlp error messages into actionable, user-friendly feedback. This improves error handling and provides clearer guidance to users encountering common download issues.
This commit is contained in:
Your Name
2025-08-26 19:27:59 +03:00
parent 47609c7017
commit 6ff72f296a
+72
View File
@@ -629,3 +629,75 @@ def update_auto_update_settings(enabled, frequency) -> bool:
except Exception as e: except Exception as e:
logger.error(f"Error updating auto-update settings: {e}") logger.error(f"Error updating auto-update settings: {e}")
return False return False
def parse_yt_dlp_error(error_message: str) -> str:
"""
Parse yt-dlp error messages and return user-friendly error messages.
Args:
error_message: The raw error message from yt-dlp
Returns:
str: A user-friendly error message with actionable advice
"""
error_str = str(error_message).lower()
# Private video errors
if any(keyword in error_str for keyword in ['private video', 'login_required', 'sign in if you']):
return ("This is a private video. You can download it by logging into your account using cookies.\n"
"Go to 'Custom Options''Login with Cookies''Extract cookies from browser' to authenticate.")
# Age-restricted content
if any(keyword in error_str for keyword in ['age restricted', 'age-restricted', 'confirm your age']):
return ("This video is age-restricted. You need to be logged in to access it.\n"
"Use 'Custom Options''Login with Cookies' to authenticate with your account.")
# Geo-blocked content
if any(keyword in error_str for keyword in ['not available in your country', 'geo-blocked', 'video is not available', 'not made this video available in your country']):
return ("This video is not available in your region (geo-blocked).\n"
"You may need to use a VPN or the video might be restricted in your country.")
# Removed/deleted videos
if any(keyword in error_str for keyword in ['video unavailable', 'this video has been removed', 'video does not exist']):
return ("This video has been removed or is no longer available.\n"
"The video may have been deleted by the uploader or removed due to policy violations.")
# Live stream errors
if any(keyword in error_str for keyword in ['live stream', 'livestream', 'is live']):
return ("This is a live stream that cannot be downloaded while active.\n"
"Wait for the stream to end, then try downloading the archived version.")
# Playlist errors
if any(keyword in error_str for keyword in ['playlist', 'no entries']):
return ("Unable to access this playlist. It may be private, deleted, or empty.\n"
"Check if the playlist exists and is publicly accessible.")
# Network/connection errors
if any(keyword in error_str for keyword in ['network error', 'connection', 'timeout', 'unable to download']):
return ("Network connection error. Please check your internet connection and try again.\n"
"If the problem persists, the video server might be temporarily unavailable.")
# Invalid URL
if any(keyword in error_str for keyword in ['invalid url', 'unsupported url', 'no video found']):
return ("Invalid or unsupported URL. Please check the link and try again.\n"
"Make sure you're using a valid YouTube, Vimeo, or other supported platform URL.")
# YouTube premium content
if any(keyword in error_str for keyword in ['youtube premium', 'premium', 'members only']):
return ("This content requires YouTube Premium or channel membership.\n"
"You need to be logged in with an account that has access to this content.")
# Copyright/DMCA
if any(keyword in error_str for keyword in ['copyright', 'dmca', 'blocked']):
return ("This video is blocked due to copyright claims.\n"
"The content owner has restricted access to this video.")
# Extraction errors (could be temporary)
if any(keyword in error_str for keyword in ['unable to extract', 'extraction failed']):
return ("Failed to extract video information. This might be a temporary issue.\n"
"Please try again in a few minutes, or check if the video link is correct.")
# Generic fallback with the original error for debugging
return (f"Could not extract video information. Please check your link.\n"
f"Technical details: {error_message}")