Add Pixabay video API: dual search (Pexels + Pixabay), optional both APIs, 9:16 portrait filtering
cce7cd9 | """ | |
| Video Creator Module for NCAkit | |
| Creates short-form videos with TTS, captions, background videos, and music. | |
| """ | |
| from fastapi import FastAPI | |
| import logging | |
| # Module Metadata | |
| MODULE_NAME = "video_creator" | |
| MODULE_PREFIX = "/api/video" | |
| MODULE_DESCRIPTION = "Create short-form videos with TTS, captions, and background music" | |
| logger = logging.getLogger(__name__) | |
| def register(app: FastAPI, config): | |
| """ | |
| Register the video creator module with FastAPI. | |
| Initializes all services and adds routes. | |
| """ | |
| from .router import router, set_short_creator | |
| from .services.libraries.tts_client import TTSClient | |
| from .services.libraries.whisper_client import WhisperClient | |
| from .services.libraries.pexels_client import PexelsClient | |
| from .services.libraries.pixabay_client import PixabayClient | |
| from .services.music_manager import MusicManager | |
| from .services.short_creator import ShortCreator | |
| logger.info("Registering video_creator module...") | |
| # Validate environment variables | |
| if not config.pexels_api_key and not config.pixabay_api_key: | |
| logger.warning("Neither PEXELS_API_KEY nor PIXABAY_API_KEY is set! Video generation may fail.") | |
| if not config.hf_tts: | |
| logger.warning("HF_TTS is missing! TTS will fail.") | |
| # Initialize TTS client | |
| logger.info("Initializing TTS client...") | |
| tts_client = TTSClient(config.hf_tts) | |
| # Initialize Whisper client | |
| logger.info("Initializing Whisper client...") | |
| whisper_client = WhisperClient( | |
| model_name=config.whisper_model, | |
| model_dir=config.whisper_model_dir | |
| ) | |
| # Initialize Pexels client (optional) | |
| pexels_client = None | |
| if config.pexels_api_key: | |
| logger.info("Initializing Pexels client...") | |
| pexels_client = PexelsClient(config.pexels_api_key) | |
| else: | |
| logger.info("Pexels API key not set, skipping Pexels client") | |
| # Initialize Pixabay client (optional) | |
| pixabay_client = None | |
| if config.pixabay_api_key: | |
| logger.info("Initializing Pixabay client...") | |
| pixabay_client = PixabayClient(config.pixabay_api_key) | |
| else: | |
| logger.info("Pixabay API key not set, skipping Pixabay client") | |
| # Initialize music manager | |
| logger.info("Initializing music manager...") | |
| music_manager = MusicManager(config.music_dir_path) | |
| try: | |
| music_manager.ensure_music_files_exist() | |
| except FileNotFoundError as e: | |
| logger.error(f"Music setup error: {e}") | |
| logger.warning("Creating empty music directory") | |
| config.music_dir_path.mkdir(parents=True, exist_ok=True) | |
| # Initialize short creator with both video clients | |
| logger.info("Initializing short creator...") | |
| short_creator = ShortCreator( | |
| config=config, | |
| tts_client=tts_client, | |
| whisper_client=whisper_client, | |
| pexels_client=pexels_client, | |
| pixabay_client=pixabay_client, | |
| music_manager=music_manager | |
| ) | |
| # Set the global short creator in the router | |
| set_short_creator(short_creator) | |
| # Store in app state for access from other modules if needed | |
| app.state.video_creator = short_creator | |
| # Register routes | |
| app.include_router(router, prefix=MODULE_PREFIX, tags=["Video Creator"]) | |
| logger.info("video_creator module registered successfully!") | |