| from __future__ import annotations | |
| from pathlib import Path | |
| from typing import Dict, List, Optional | |
| from fastapi import HTTPException | |
| from src.podcast import ( | |
| download_podcast_audio, | |
| fetch_audio, | |
| fetch_episodes, | |
| search_podcast_series, | |
| ) | |
| from .file_service import store_audio_file | |
| def search_series(query: str) -> List[Dict[str, object]]: | |
| return search_podcast_series(query) | |
| def list_episodes(feed_url: str) -> List[Dict[str, object]]: | |
| return fetch_episodes(feed_url) | |
| def download_episode(audio_url: str, title: str) -> Dict[str, str]: | |
| file_path, status = download_podcast_audio(audio_url, title, status="Podcast download") | |
| if not file_path: | |
| raise HTTPException(status_code=500, detail=status or "Download failed") | |
| _, audio_url = store_audio_file(Path(file_path), prefix="podcast") | |
| return {"audioUrl": audio_url, "status": status} | |
| def fetch_youtube_audio(youtube_url: str) -> Dict[str, str]: | |
| audio_path, status = fetch_audio(youtube_url, status="YouTube fetch") | |
| if not audio_path: | |
| raise HTTPException(status_code=500, detail=status or "YouTube download failed") | |
| _, audio_url = store_audio_file(Path(audio_path), prefix="youtube") | |
| return {"audioUrl": audio_url, "status": status} | |