diff options
| author | Astounds <kirito@disroot.org> | 2026-03-22 14:17:23 -0500 |
|---|---|---|
| committer | Astounds <kirito@disroot.org> | 2026-03-22 14:17:23 -0500 |
| commit | 84e1acaab8f7e4e7e36d19e3b6847a0ab6c33759 (patch) | |
| tree | a4021823e3e29d1efb57271dda5024825983bacf /youtube/ytdlp_integration.py | |
| parent | ed4b05d9b616c688afc6ef03dc404009c4abfc0f (diff) | |
| download | yt-local-84e1acaab8f7e4e7e36d19e3b6847a0ab6c33759.tar.lz yt-local-84e1acaab8f7e4e7e36d19e3b6847a0ab6c33759.tar.xz yt-local-84e1acaab8f7e4e7e36d19e3b6847a0ab6c33759.zip | |
yt-dlp
Diffstat (limited to 'youtube/ytdlp_integration.py')
| -rw-r--r-- | youtube/ytdlp_integration.py | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/youtube/ytdlp_integration.py b/youtube/ytdlp_integration.py new file mode 100644 index 0000000..90a749d --- /dev/null +++ b/youtube/ytdlp_integration.py @@ -0,0 +1,78 @@ +#!/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', +] |
