"""AWS Lambda / Cloud Run / Cloud Functions handler. Package with: pip install youtube-transcript-api shephouse-yt -t .""" import json from fallback import get_transcripts def handler(event, context=None): ids = event.get("video_ids", []) out = {} for vid, r in get_transcripts(ids, languages=event.get("languages", ["en"])).items(): if isinstance(r, Exception): out[vid] = {"ok": False, "error": type(r).__name__} else: source, snippets = r out[vid] = {"ok": True, "source": source, "text": " ".join(s["text"] for s in snippets)} return {"statusCode": 200, "body": json.dumps(out)} if __name__ == "__main__": print(handler({"video_ids": ["jNQXAC9IVRw", "AAAAAAAAAAA"]})["body"][:200])