This commit is contained in:
2026-01-11 14:46:41 -08:00
parent 1f3de7db1c
commit 275f18cb31
19 changed files with 2741 additions and 394 deletions

View File

@@ -16,10 +16,10 @@ import json
import time
from typing import Any, Dict, List, Optional
from .HTTP import HTTPClient
from .base import API, ApiError
class PodcastIndexError(Exception):
class PodcastIndexError(ApiError):
pass
@@ -55,41 +55,31 @@ def build_auth_headers(
}
class PodcastIndexClient:
BASE_URL = "https://api.podcastindex.org/api/1.0"
class PodcastIndexClient(API):
def __init__(
self,
api_key: str,
api_secret: str,
*,
base_url: str = "https://api.podcastindex.org/api/1.0",
user_agent: str = "downlow/1.0",
timeout: float = 30.0,
):
super().__init__(base_url=base_url, timeout=timeout)
self.api_key = str(api_key or "").strip()
self.api_secret = str(api_secret or "").strip()
self.user_agent = str(user_agent or "downlow/1.0")
self.timeout = float(timeout)
if not self.api_key or not self.api_secret:
raise PodcastIndexError("PodcastIndex api key/secret are required")
def _get(self, path: str, *, params: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
url = self.BASE_URL.rstrip("/") + "/" + str(path or "").lstrip("/")
headers = build_auth_headers(
self.api_key,
self.api_secret,
user_agent=self.user_agent,
)
with HTTPClient(timeout=self.timeout, headers=headers) as client:
response = client.get(url, params=params)
response.raise_for_status()
try:
return json.loads(response.content.decode("utf-8"))
except Exception as exc:
raise PodcastIndexError(f"Invalid JSON response: {exc}")
return self._get_json(path, params=params, headers=headers)
def search_byterm(self, query: str, *, max_results: int = 10) -> List[Dict[str, Any]]:
q = str(query or "").strip()