Browse Source

feat(video): temporarily disable youtube stream url resolution

master
Mohsen Taba 1 week ago
parent
commit
a90852f8c7
  1. 91
      utils/youtube.py

91
utils/youtube.py

@ -37,52 +37,55 @@ def get_youtube_stream_url(youtube_url: str) -> Optional[str]:
Returns direct stream URL string if successful, or None if extraction fails.
"""
if not youtube_url or not isinstance(youtube_url, str):
return None
youtube_url = youtube_url.strip()
if not youtube_url:
# Temporarily disabled - return None without resolving stream URL
return None
cache_key = _get_cache_key(youtube_url)
cached_url = cache.get(cache_key)
if cached_url:
return cached_url
clean_url = normalize_youtube_url(youtube_url)
try:
import yt_dlp
ydl_opts = {
'format': 'best[ext=mp4]/bestvideo[ext=mp4]+bestaudio[ext=m4a]/best',
'quiet': True,
'no_warnings': True,
'skip_download': True,
'nocheckcertificate': True,
'extractor_args': {
'youtube': {
'player_client': ['android', 'ios', 'web', 'mweb'],
}
}
}
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
info = ydl.extract_info(clean_url, download=False)
if not info:
return None
if 'entries' in info:
info = info['entries'][0]
stream_url = info.get('url')
if stream_url:
cache.set(cache_key, stream_url, YOUTUBE_STREAM_CACHE_TTL)
return stream_url
except Exception as e:
logger.error(f"Failed to extract YouTube stream URL for '{youtube_url}': {e}")
return None
# if not youtube_url or not isinstance(youtube_url, str):
# return None
#
# youtube_url = youtube_url.strip()
# if not youtube_url:
# return None
#
# cache_key = _get_cache_key(youtube_url)
# cached_url = cache.get(cache_key)
# if cached_url:
# return cached_url
#
# clean_url = normalize_youtube_url(youtube_url)
#
# try:
# import yt_dlp
#
# ydl_opts = {
# 'format': 'best[ext=mp4]/bestvideo[ext=mp4]+bestaudio[ext=m4a]/best',
# 'quiet': True,
# 'no_warnings': True,
# 'skip_download': True,
# 'nocheckcertificate': True,
# 'extractor_args': {
# 'youtube': {
# 'player_client': ['android', 'ios', 'web', 'mweb'],
# }
# }
# }
#
# with yt_dlp.YoutubeDL(ydl_opts) as ydl:
# info = ydl.extract_info(clean_url, download=False)
# if not info:
# return None
#
# if 'entries' in info:
# info = info['entries'][0]
#
# stream_url = info.get('url')
# if stream_url:
# cache.set(cache_key, stream_url, YOUTUBE_STREAM_CACHE_TTL)
# return stream_url
# except Exception as e:
# logger.error(f"Failed to extract YouTube stream URL for '{youtube_url}': {e}")
#
# return None
def clear_youtube_stream_cache(youtube_url: str) -> None:

Loading…
Cancel
Save