79 lines
2.0 KiB
Python
79 lines
2.0 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
yt-dlp integration wrapper for backward compatibility.
|
|
|
|
This module now uses the centralized ytdlp_service for all operations.
|
|
"""
|
|
import logging
|
|
from youtube.ytdlp_service import (
|
|
extract_video_info,
|
|
get_language_name,
|
|
clear_cache,
|
|
get_cache_info,
|
|
)
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def extract_video_info_ytdlp(video_id):
|
|
"""
|
|
Extract video information using yt-dlp (with caching).
|
|
|
|
This is a wrapper around ytdlp_service.extract_video_info()
|
|
for backward compatibility.
|
|
|
|
Args:
|
|
video_id: YouTube video ID
|
|
|
|
Returns:
|
|
Dictionary with audio_tracks, formats, title, duration
|
|
"""
|
|
logger.debug(f'Extracting video info (legacy API): {video_id}')
|
|
|
|
info = extract_video_info(video_id)
|
|
|
|
# Convert to legacy format for backward compatibility
|
|
return {
|
|
'audio_tracks': info.get('audio_tracks', []),
|
|
'all_audio_formats': info.get('formats', []),
|
|
'formats': info.get('formats', []),
|
|
'title': info.get('title', ''),
|
|
'duration': info.get('duration', 0),
|
|
'error': info.get('error'),
|
|
}
|
|
|
|
|
|
def get_audio_formats_for_language(video_id, language='en'):
|
|
"""
|
|
Get available audio formats for a specific language.
|
|
|
|
Args:
|
|
video_id: YouTube video ID
|
|
language: Language code (default: 'en')
|
|
|
|
Returns:
|
|
List of audio format dicts
|
|
"""
|
|
info = extract_video_info_ytdlp(video_id)
|
|
|
|
if 'error' in info:
|
|
logger.warning(f'Cannot get audio formats: {info["error"]}')
|
|
return []
|
|
|
|
audio_formats = []
|
|
for track in info.get('audio_tracks', []):
|
|
if track['language'] == language:
|
|
audio_formats.append(track)
|
|
|
|
logger.debug(f'Found {len(audio_formats)} {language} audio formats')
|
|
return audio_formats
|
|
|
|
|
|
__all__ = [
|
|
'extract_video_info_ytdlp',
|
|
'get_audio_formats_for_language',
|
|
'get_language_name',
|
|
'clear_cache',
|
|
'get_cache_info',
|
|
]
|