From 84e1acaab8f7e4e7e36d19e3b6847a0ab6c33759 Mon Sep 17 00:00:00 2001 From: Astounds Date: Sun, 22 Mar 2026 14:17:23 -0500 Subject: yt-dlp --- youtube/ytdlp_integration.py | 78 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 youtube/ytdlp_integration.py (limited to 'youtube/ytdlp_integration.py') 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', +] -- cgit v1.2.3