braidio 0.0.77__tar.gz → 0.0.78__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {braidio-0.0.77 → braidio-0.0.78}/PKG-INFO +2 -2
- {braidio-0.0.77 → braidio-0.0.78}/braidio/mcp/tools.py +33 -86
- braidio-0.0.78/braidio/project.py +144 -0
- {braidio-0.0.77 → braidio-0.0.78}/pyproject.toml +2 -2
- {braidio-0.0.77 → braidio-0.0.78}/tests/test_mcp.py +146 -89
- {braidio-0.0.77 → braidio-0.0.78}/tests/test_transforms.py +53 -0
- braidio-0.0.77/braidio/project.py +0 -60
- {braidio-0.0.77 → braidio-0.0.78}/.editorconfig +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/.gitattributes +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/.gitignore +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/LICENSE +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/README.md +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/__init__.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/_paths.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/bodies/__init__.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/bodies/_domain.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/bodies/_render_nodes.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/bodies/_tiers.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/bodies/_video.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/captions.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/compose.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/conversation.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/cost.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/data/skills/braidio/SKILL.md +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/data/skills/braidio-commentary-video/SKILL.md +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/defaults.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/delivery.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/downloads.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/formats.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/genre.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/importing/__init__.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/importing/__main__.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/importing/_catalog.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/importing/_manifest.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/importing/_writer.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/kinds.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/markdown_script.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/mcp/__init__.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/mcp/_docs.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/mcp/_guide.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/mcp/_helpers.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/mcp/_media.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/mcp/credentials.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/mcp/metering.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/mcp/workspace.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/multivoice.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/music.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/pacing.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/provenance.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/relevance.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/render.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/rights.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/script.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/sources.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/structure.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/style.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/textprep.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/timeline.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/transforms/__init__.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/transforms/_asset_refs.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/transforms/_common.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/transforms/_dialogue.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/transforms/_episode.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/transforms/_ingest.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/transforms/_narration.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/transforms/_segment.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/transforms/_video_cut.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/transforms/_video_panels.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/transforms/_voice.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/tts.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/video.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/voice_library.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/weave.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/braidio/weave_config.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/conftest.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/misc/docs/Extraction and nw-App Design.md +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/misc/docs/research/commentary-formats-and-styles.md +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/misc/docs/research/conversational-vs-narration-tts.md +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/misc/docs/research/notebooklm-and-conversational-pacing.md +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/misc/docs/style/README.md +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/misc/docs/style/anti-platitude-checklist.md +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/misc/docs/style/commentary-voice-guide.md +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/misc/docs/style/voices/_style-groups.md +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/misc/docs/style/voices/amanda-dobbins.md +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/misc/docs/style/voices/david-sims.md +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/misc/docs/style/voices/griffin-newman.md +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/misc/docs/style/voices/helen-molesworth.md +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/misc/docs/style/voices/hrishikesh-hirway.md +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/misc/docs/style/voices/jason-mantzoukas.md +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/misc/docs/style/voices/john-mcwhorter.md +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/misc/docs/style/voices/jon-caramanica.md +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/misc/docs/style/voices/june-diane-raphael.md +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/misc/docs/style/voices/karina-longworth.md +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/misc/docs/style/voices/katy-hessel.md +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/misc/docs/style/voices/louis-theroux.md +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/misc/docs/style/voices/mallory-rubin.md +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/misc/docs/style/voices/melvyn-bragg.md +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/misc/docs/style/voices/michael-barbaro.md +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/misc/docs/style/voices/nate-sloan-charlie-harding.md +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/misc/docs/style/voices/paul-scheer.md +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/misc/docs/style/voices/sean-fennessey.md +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/misc/docs/style/voices/talk-art.md +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/misc/docs/style/voices/yasi-salek.md +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/misc/docs/youtube_ingest_credentials.md +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/tests/_audio.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/tests/test_body_schema_stability.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/tests/test_conversation.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/tests/test_cost.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/tests/test_credits_card.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/tests/test_defaults.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/tests/test_delivery.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/tests/test_downloads.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/tests/test_expressiveness.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/tests/test_formats.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/tests/test_genre_placement.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/tests/test_importing.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/tests/test_markdown_script.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/tests/test_mcp_caller_key.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/tests/test_media_auth.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/tests/test_multivoice.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/tests/test_music.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/tests/test_namespaced_source.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/tests/test_nw_app.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/tests/test_pacing.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/tests/test_packaging.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/tests/test_render_settings.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/tests/test_script.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/tests/test_sources.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/tests/test_structure.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/tests/test_textprep_style.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/tests/test_timeline.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/tests/test_transforms_dialogue.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/tests/test_transforms_episode_members.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/tests/test_transforms_rights.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/tests/test_transforms_secrets.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/tests/test_transforms_structure.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/tests/test_tts_api_key.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/tests/test_turn_overlap.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/tests/test_video.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/tests/test_video_bodies.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/tests/test_video_footage.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/tests/test_video_transforms.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/tests/test_voice_library.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/tests/test_weave.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/tests/test_weave_config.py +0 -0
- {braidio-0.0.77 → braidio-0.0.78}/tests/test_wire_descriptions.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: braidio
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.78
|
|
4
4
|
Summary: Weave narration with extracted media segments into audiovisual productions
|
|
5
5
|
Project-URL: Homepage, https://github.com/thorwhalen/braidio
|
|
6
6
|
Project-URL: Repository, https://github.com/thorwhalen/braidio
|
|
@@ -56,7 +56,7 @@ Requires-Dist: mdit-py-plugins; extra == 'mcp'
|
|
|
56
56
|
Requires-Dist: nw>=0.0.65; extra == 'mcp'
|
|
57
57
|
Requires-Dist: py2mcp>=0.1.9; extra == 'mcp'
|
|
58
58
|
Requires-Dist: pypdf; extra == 'mcp'
|
|
59
|
-
Requires-Dist: yb[download]>=0.1.
|
|
59
|
+
Requires-Dist: yb[download]>=0.1.24; extra == 'mcp'
|
|
60
60
|
Provides-Extra: nw-app
|
|
61
61
|
Requires-Dist: falaw[fal]; extra == 'nw-app'
|
|
62
62
|
Requires-Dist: lacing; extra == 'nw-app'
|
|
@@ -323,23 +323,16 @@ def list_projects() -> dict:
|
|
|
323
323
|
|
|
324
324
|
|
|
325
325
|
def project_status(project_id: str) -> dict:
|
|
326
|
-
"""A project's status:
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
download claim is minted against. The body's own ``artifact_id`` is the
|
|
330
|
-
lacing CONTENT hash: an identity for provenance, not a retrieval key
|
|
331
|
-
(braidio#32 — the tool used to return only the body, so the one id a
|
|
332
|
-
caller could see was the one no download tool accepted).
|
|
326
|
+
"""A project's status: beat/render counts, the next step, and its finished
|
|
327
|
+
episodes (url + duration). Each episode's ``episode_id`` is the id ``resolve``
|
|
328
|
+
accepts; the body's ``artifact_id`` is a content hash, not a download key.
|
|
333
329
|
"""
|
|
334
330
|
_require_nw("project_status")
|
|
335
|
-
import nw
|
|
336
|
-
|
|
337
331
|
proj = _workspace().open_project(project_id)
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
return {"project_id": project_id, "episodes": episodes}
|
|
332
|
+
# The genre's status (what a host's one project_status door serves) plus every
|
|
333
|
+
# episode's full body, url included: this caller owns the workspace.
|
|
334
|
+
episodes = [{"episode_id": str(a.id), **to_json(a.body)} for a in proj.episodes()]
|
|
335
|
+
return {"project_id": project_id, **proj.genre_status(), "episodes": episodes}
|
|
343
336
|
|
|
344
337
|
|
|
345
338
|
#: Content types whose extracted text has lost its markdown structure, so
|
|
@@ -558,21 +551,12 @@ def download_audio(url: str, name: str | None = None) -> dict:
|
|
|
558
551
|
size/duration-bounded; best audio stream → mp3 via yt-dlp (no login/API
|
|
559
552
|
key). Needs ``braidio[mcp]`` + ffmpeg.
|
|
560
553
|
"""
|
|
561
|
-
|
|
554
|
+
import shutil
|
|
562
555
|
|
|
563
556
|
from braidio.mcp import _docs, _media
|
|
564
557
|
|
|
565
|
-
# SSRF pre-check (matches upload_asset/ingest_document): refuse non-http(s) and
|
|
566
|
-
# loopback/private/link-local/cloud-metadata hosts. NOTE: yt-dlp resolves the page +
|
|
567
|
-
# follows redirects itself, so this closes the direct-target vector but is not a full
|
|
568
|
-
# egress sandbox — the driving agent's `url` can be steered by prompt injection.
|
|
569
558
|
try:
|
|
570
|
-
|
|
571
|
-
except ValueError as exc:
|
|
572
|
-
raise ToolError(str(exc)) from exc
|
|
573
|
-
|
|
574
|
-
try:
|
|
575
|
-
from yb.download import download_youtube_video, youtube_video_info
|
|
559
|
+
from yb.download import download_audio_bounded
|
|
576
560
|
except ImportError as exc:
|
|
577
561
|
raise ToolError(
|
|
578
562
|
"audio download needs yt-dlp — install braidio[mcp] (which pulls yb[download])"
|
|
@@ -584,82 +568,45 @@ def download_audio(url: str, name: str | None = None) -> dict:
|
|
|
584
568
|
creds = _media.SourceCredentials.from_env()
|
|
585
569
|
creds.check()
|
|
586
570
|
|
|
587
|
-
#
|
|
588
|
-
#
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
raise _media.as_tool_error(
|
|
593
|
-
exc, fallback="could not read the source", credentials=creds
|
|
594
|
-
) from exc
|
|
595
|
-
duration = preview.get("duration")
|
|
596
|
-
if isinstance(duration, (int, float)) and duration > _AUDIO_MAX_DURATION_S:
|
|
597
|
-
raise ToolError(
|
|
598
|
-
f"source is {int(duration)}s long; exceeds the "
|
|
599
|
-
f"{_AUDIO_MAX_DURATION_S}s audio-download limit"
|
|
600
|
-
)
|
|
601
|
-
|
|
571
|
+
# The link-to-audio policy (target check before the network and again on the
|
|
572
|
+
# resolved page, playlist/live/duration refusal before any media bytes, pinned
|
|
573
|
+
# caps, mp3) is yb's. braidio supplies its SSRF check — loopback/private/
|
|
574
|
+
# link-local/cloud-metadata hosts refused; not a full egress sandbox, since
|
|
575
|
+
# yt-dlp follows redirects itself — and its env-tunable caps.
|
|
602
576
|
ws = _workspace()
|
|
603
|
-
work = ws.renders_dir / "_downloads"
|
|
604
|
-
work.mkdir(parents=True, exist_ok=True)
|
|
605
577
|
try:
|
|
606
|
-
|
|
578
|
+
got = download_audio_bounded(
|
|
607
579
|
url,
|
|
608
|
-
download_dir=
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
# configured option can never widen a safety bound.
|
|
615
|
-
"max_filesize": _AUDIO_MAX_BYTES, # yt-dlp skips/aborts oversized formats
|
|
616
|
-
"postprocessors": [
|
|
617
|
-
{
|
|
618
|
-
"key": "FFmpegExtractAudio",
|
|
619
|
-
"preferredcodec": "mp3",
|
|
620
|
-
"preferredquality": "192",
|
|
621
|
-
}
|
|
622
|
-
],
|
|
623
|
-
},
|
|
580
|
+
download_dir=ws.renders_dir / "_downloads",
|
|
581
|
+
max_bytes=_AUDIO_MAX_BYTES,
|
|
582
|
+
max_duration_s=_AUDIO_MAX_DURATION_S,
|
|
583
|
+
validate_target=_docs._validate_target,
|
|
584
|
+
extra_opts=creds.opts,
|
|
585
|
+
cookies_file=False, # braidio's credentials are the only cookie source
|
|
624
586
|
)
|
|
625
|
-
except Exception as exc: # noqa: BLE001 — yt-dlp
|
|
587
|
+
except Exception as exc: # noqa: BLE001 — a refusal, a cap, or any yt-dlp error
|
|
626
588
|
raise _media.as_tool_error(
|
|
627
589
|
exc, fallback="audio download failed", credentials=creds
|
|
628
590
|
) from exc
|
|
629
591
|
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
audio_path.unlink()
|
|
640
|
-
except OSError:
|
|
641
|
-
pass
|
|
642
|
-
raise ToolError(f"downloaded audio exceeds the {_AUDIO_MAX_BYTES}-byte limit")
|
|
643
|
-
data = audio_path.read_bytes()
|
|
644
|
-
info = result.info or {}
|
|
645
|
-
title = name or info.get("title") or audio_path.stem
|
|
646
|
-
ref = ws.content_store().add(data, mime_type="audio/mpeg", name=title)
|
|
592
|
+
try:
|
|
593
|
+
title = name or got.title
|
|
594
|
+
ref = ws.content_store().add(
|
|
595
|
+
got.path.read_bytes(), mime_type="audio/mpeg", name=title
|
|
596
|
+
)
|
|
597
|
+
finally:
|
|
598
|
+
# yb hands over a per-call directory; the content-addressed store owns the
|
|
599
|
+
# bytes now (or the ingest failed), so it goes either way.
|
|
600
|
+
shutil.rmtree(got.path.parent, ignore_errors=True)
|
|
647
601
|
meta = {
|
|
648
602
|
**ref.to_json(),
|
|
649
603
|
"name": title,
|
|
650
604
|
"source": url,
|
|
651
605
|
"kind": "audio",
|
|
652
|
-
"duration":
|
|
653
|
-
"copyright_notice":
|
|
654
|
-
"Downloaded from a user-supplied link — respect the source's copyright and "
|
|
655
|
-
"terms of service; you are responsible for having the right to use it."
|
|
656
|
-
),
|
|
606
|
+
"duration": got.duration_s,
|
|
607
|
+
"copyright_notice": got.notice,
|
|
657
608
|
}
|
|
658
609
|
ws.asset_meta()[ref.item_id] = meta
|
|
659
|
-
try:
|
|
660
|
-
audio_path.unlink() # the content-addressed store owns the bytes now
|
|
661
|
-
except OSError:
|
|
662
|
-
pass
|
|
663
610
|
return meta
|
|
664
611
|
|
|
665
612
|
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"""braidio as an nw app: a :class:`nw.Project` for commentary-weave productions.
|
|
2
|
+
|
|
3
|
+
Subclassing ``nw.Project`` inherits the whole folder facade + lacing graph +
|
|
4
|
+
freshness (``stale_after``) machinery; braidio adds its production kind and its
|
|
5
|
+
domain/render body-schema vocabulary (registered on import of
|
|
6
|
+
:mod:`braidio.bodies`). This module requires ``nw``; it is imported lazily by
|
|
7
|
+
``braidio/__init__`` only when ``nw`` is available.
|
|
8
|
+
|
|
9
|
+
The costed ``plan``/``execute`` Transform pipeline (each transform delegating to
|
|
10
|
+
braidio's functional core for the actual audio, and recording provenance via
|
|
11
|
+
:mod:`braidio.provenance`) is the next increment — see the design doc and
|
|
12
|
+
nw#9 (generalizing nw's shot/mp4 render seam).
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
from pathlib import Path
|
|
18
|
+
|
|
19
|
+
import nw
|
|
20
|
+
|
|
21
|
+
from braidio import bodies as _bodies # noqa: F401 (import registers schemas)
|
|
22
|
+
from braidio.kinds import WeaveKind
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
#: The next step, by how far the project has got: ``(op, why)``, ``op`` in
|
|
26
|
+
#: braidio's own vocabulary (a host maps it to its tool name, prefix and all).
|
|
27
|
+
NEXT_STEP_SAVE_SCRIPT = ("save_script", "there is no script yet")
|
|
28
|
+
NEXT_STEP_WEAVE = ("weave_project", "the script has not been rendered yet")
|
|
29
|
+
NEXT_STEP_DONE = (
|
|
30
|
+
"weave_project",
|
|
31
|
+
"an episode is made — download it by its episode_id, or weave again after "
|
|
32
|
+
"changing the script",
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _tiers():
|
|
37
|
+
"""The tier names, from the one table the transforms write by (lazy: the
|
|
38
|
+
transforms package is heavy and this module is imported with ``braidio``)."""
|
|
39
|
+
from braidio.transforms import _common
|
|
40
|
+
|
|
41
|
+
return _common
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _episode_row(annotation) -> dict:
|
|
45
|
+
"""One finished episode, path-free: the body's ``file://`` url and its
|
|
46
|
+
(large) timeline are left out."""
|
|
47
|
+
body = annotation.body
|
|
48
|
+
duration = body.get("duration_s")
|
|
49
|
+
return {
|
|
50
|
+
"episode_id": str(annotation.id),
|
|
51
|
+
"profile": body.get("profile"),
|
|
52
|
+
"duration_s": None if duration is None else round(float(duration), 2),
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class Project(nw.Project):
|
|
57
|
+
"""An nw project for a braidio commentary-weave production."""
|
|
58
|
+
|
|
59
|
+
KIND: WeaveKind = WeaveKind.COMMENTARY_WEAVE
|
|
60
|
+
|
|
61
|
+
def episodes(self) -> list:
|
|
62
|
+
"""The project's finished episodes (``episode-renders`` nodes), oldest first.
|
|
63
|
+
|
|
64
|
+
A re-weave adds an episode and keeps the earlier ones, so the last is
|
|
65
|
+
the current one.
|
|
66
|
+
"""
|
|
67
|
+
tiers = _tiers()
|
|
68
|
+
return sorted(
|
|
69
|
+
nw.annotations_at_tier(self.root, tiers.TIER_EPISODE_RENDER),
|
|
70
|
+
# generation time, then id: nw's own order (ties: legacy tick-0 stamps)
|
|
71
|
+
key=lambda a: (a.provenance.generated_at_time.to_seconds(), str(a.id)),
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
def genre_status(self) -> dict:
|
|
75
|
+
"""Where this production stands, for a host's one ``project_status`` door
|
|
76
|
+
(``nw.Project.genre_status``, nw#133; braidio#125).
|
|
77
|
+
|
|
78
|
+
Counted, in muvid's shape: the script's beats by kind, how many episodes
|
|
79
|
+
were rendered, the latest one (path-free), and the next step as
|
|
80
|
+
``{"op", "why"}``. Indexed tier reads only — no freshness walk, no file
|
|
81
|
+
probe — and no per-item list, so it stays small however often the
|
|
82
|
+
project is re-woven, and never names a path.
|
|
83
|
+
|
|
84
|
+
>>> import tempfile
|
|
85
|
+
>>> with tempfile.TemporaryDirectory() as d:
|
|
86
|
+
... status = create_project_at(d, "ep").genre_status()
|
|
87
|
+
>>> status["episode_count"], status["next_step"]["op"]
|
|
88
|
+
(0, 'save_script')
|
|
89
|
+
"""
|
|
90
|
+
tiers = _tiers()
|
|
91
|
+
counts = {
|
|
92
|
+
key: len(nw.annotations_at_tier(self.root, tier))
|
|
93
|
+
for key, tier in (
|
|
94
|
+
("narration_beats", tiers.TIER_NARRATIVE_BEAT),
|
|
95
|
+
("dialogue_beats", tiers.TIER_DIALOGUE_BEAT),
|
|
96
|
+
("clips", tiers.TIER_AUDIO_CLIP),
|
|
97
|
+
("scene_breaks", tiers.TIER_SCENE_BREAK),
|
|
98
|
+
)
|
|
99
|
+
}
|
|
100
|
+
episodes = self.episodes()
|
|
101
|
+
if episodes:
|
|
102
|
+
op, why = NEXT_STEP_DONE
|
|
103
|
+
elif any(counts.values()):
|
|
104
|
+
op, why = NEXT_STEP_WEAVE
|
|
105
|
+
else:
|
|
106
|
+
op, why = NEXT_STEP_SAVE_SCRIPT
|
|
107
|
+
return {
|
|
108
|
+
**counts,
|
|
109
|
+
"episode_count": len(episodes),
|
|
110
|
+
"latest_episode": _episode_row(episodes[-1]) if episodes else None,
|
|
111
|
+
"next_step": {"op": op, "why": why},
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def create_project_at(
|
|
116
|
+
projects_dir: "str | Path", project_id: str, *, title: str = "", force: bool = False
|
|
117
|
+
) -> Project:
|
|
118
|
+
"""Create a braidio project at ``projects_dir/<project_id>`` — the *host-placed* create.
|
|
119
|
+
|
|
120
|
+
The counterpart to :meth:`braidio.mcp.workspace.Workspace.create_project`, which
|
|
121
|
+
places a project in braidio's own per-caller workspace. This one takes the
|
|
122
|
+
directory from its caller, because a host that will **serve** the project
|
|
123
|
+
(reelee, over HTTP) has to put it where its own resolver and lister look — under
|
|
124
|
+
braidio's data home it would be a sibling of nothing the host can address. See
|
|
125
|
+
nw's ``projects_dir`` placement contract (thorwhalen/nw#84).
|
|
126
|
+
|
|
127
|
+
Deliberately here and not in ``braidio.mcp.workspace``: importing that module
|
|
128
|
+
runs ``braidio/mcp/__init__.py`` and pulls **fastmcp**, and the host-placed path
|
|
129
|
+
has no reason to require the MCP extra. ``project_id`` is validated as a single
|
|
130
|
+
traversal-safe component, so the result is always a direct child of
|
|
131
|
+
``projects_dir`` — which is the property the host's lister depends on, and which
|
|
132
|
+
nw verifies after the fact.
|
|
133
|
+
|
|
134
|
+
>>> import tempfile
|
|
135
|
+
>>> with tempfile.TemporaryDirectory() as d:
|
|
136
|
+
... p = create_project_at(d, "ep_01", title="Episode 1")
|
|
137
|
+
... p.root.name
|
|
138
|
+
'ep_01'
|
|
139
|
+
"""
|
|
140
|
+
from braidio._paths import safe_component
|
|
141
|
+
|
|
142
|
+
root = Path(projects_dir) / safe_component(project_id, label="project_id")
|
|
143
|
+
root.parent.mkdir(parents=True, exist_ok=True)
|
|
144
|
+
return Project.init(root, title=title or project_id, force=force)
|
|
@@ -6,7 +6,7 @@ build-backend = "hatchling.build"
|
|
|
6
6
|
|
|
7
7
|
[project]
|
|
8
8
|
name = "braidio"
|
|
9
|
-
version = "0.0.
|
|
9
|
+
version = "0.0.78"
|
|
10
10
|
description = "Weave narration with extracted media segments into audiovisual productions"
|
|
11
11
|
readme = "README.md"
|
|
12
12
|
requires-python = ">=3.10"
|
|
@@ -139,7 +139,7 @@ nw-app = ["lacing", "nw>=0.0.65", "falaw[fal]"]
|
|
|
139
139
|
# older dol without it.
|
|
140
140
|
# nw>=0.0.58: see the nw-app note above (the `secrets=` seam, braidio#58; the
|
|
141
141
|
# asset-ref declarations `braidio.transforms` makes on import, nw#55).
|
|
142
|
-
mcp = ["fastmcp", "py2mcp>=0.1.9", "pypdf", "dol>=0.3.57", "lacing", "nw>=0.0.65", "falaw[fal]", "yb[download]>=0.1.
|
|
142
|
+
mcp = ["fastmcp", "py2mcp>=0.1.9", "pypdf", "dol>=0.3.57", "lacing", "nw>=0.0.65", "falaw[fal]", "yb[download]>=0.1.24", "graze>=0.1.45", "markdown-it-py", "mdit-py-plugins"]
|
|
143
143
|
# The importer (`braidio.importing`): a finished commentary production ->
|
|
144
144
|
# a real project graph. Needs the nw-app layer (it writes annotations) plus
|
|
145
145
|
# `illustration` for licence normalization.
|
|
@@ -686,6 +686,47 @@ def test_create_and_list_projects():
|
|
|
686
686
|
assert row["modified"] is not None and row["created"] is None
|
|
687
687
|
|
|
688
688
|
|
|
689
|
+
@_NW
|
|
690
|
+
def test_project_status_serves_the_genre_status_plus_full_episodes(
|
|
691
|
+
monkeypatch, tmp_path
|
|
692
|
+
):
|
|
693
|
+
from braidio.mcp.tools import _workspace
|
|
694
|
+
|
|
695
|
+
server = _local_server(ledger={})
|
|
696
|
+
_call(server, "create_project", {"project_id": "demo", "title": "Demo"})
|
|
697
|
+
empty = _call(server, "project_status", {"project_id": "demo"}).structured_content
|
|
698
|
+
assert empty["next_step"]["op"] == "save_script" and empty["episodes"] == []
|
|
699
|
+
|
|
700
|
+
# weave one episode with the audio boundaries stubbed (no synthesis, no ffmpeg)
|
|
701
|
+
def _write(out, tag=b"A"):
|
|
702
|
+
Path(out).parent.mkdir(parents=True, exist_ok=True)
|
|
703
|
+
Path(out).write_bytes(tag)
|
|
704
|
+
return Path(out)
|
|
705
|
+
|
|
706
|
+
monkeypatch.setattr(
|
|
707
|
+
braidio,
|
|
708
|
+
"narrate",
|
|
709
|
+
lambda text, out, *, return_cache_status=False, **kw: (
|
|
710
|
+
(_write(out), False) if return_cache_status else _write(out)
|
|
711
|
+
),
|
|
712
|
+
)
|
|
713
|
+
monkeypatch.setattr(braidio, "weave_timeline", lambda items, out, **kw: _write(out))
|
|
714
|
+
monkeypatch.setattr(braidio, "duration_s", lambda path: 3.0)
|
|
715
|
+
proj = Workspace.for_email(OWNER).open_project("demo")
|
|
716
|
+
script = braidio.Script(
|
|
717
|
+
title="Demo", id_slug="demo", beats=[braidio.Narration(text="Hello.")]
|
|
718
|
+
)
|
|
719
|
+
episode = braidio.weave_project(proj, script)
|
|
720
|
+
|
|
721
|
+
out = _call(server, "project_status", {"project_id": "demo"}).structured_content
|
|
722
|
+
assert out["project_id"] == "demo" and out["episode_count"] == 1
|
|
723
|
+
assert out["latest_episode"]["episode_id"] == str(episode.id)
|
|
724
|
+
# the tool, unlike the path-free genre status, returns each full body
|
|
725
|
+
(row,) = out["episodes"]
|
|
726
|
+
assert row["episode_id"] == str(episode.id)
|
|
727
|
+
assert row["url"].startswith("file://")
|
|
728
|
+
|
|
729
|
+
|
|
689
730
|
@_NW
|
|
690
731
|
def test_weave_project_records_cost(monkeypatch):
|
|
691
732
|
server = _local_server(ledger={})
|
|
@@ -1480,31 +1521,37 @@ def test_weave_project_reports_sting_applied_in_result(monkeypatch):
|
|
|
1480
1521
|
# --- download_audio (yt-dlp via yb) + identity fallback (reelee#232) ---------
|
|
1481
1522
|
|
|
1482
1523
|
|
|
1483
|
-
def
|
|
1484
|
-
|
|
1485
|
-
import sys
|
|
1486
|
-
import types
|
|
1487
|
-
|
|
1488
|
-
import braidio.mcp._docs as _docs
|
|
1524
|
+
def _fake_bounded(monkeypatch, tmp_path, *, raises=None):
|
|
1525
|
+
"""Replace ``yb.download.download_audio_bounded`` with a no-network fake.
|
|
1489
1526
|
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1527
|
+
Returns the list of calls (kwargs) it received. The fake hands back an mp3
|
|
1528
|
+
alone in its own directory, as the real one does.
|
|
1529
|
+
"""
|
|
1530
|
+
from yb.download import AudioDownload
|
|
1531
|
+
|
|
1532
|
+
calls = []
|
|
1533
|
+
|
|
1534
|
+
def _bounded(url, **kw):
|
|
1535
|
+
calls.append({"url": url, **kw})
|
|
1536
|
+
if raises is not None:
|
|
1537
|
+
raise raises
|
|
1538
|
+
work = Path(kw["download_dir"]) / "per-call"
|
|
1539
|
+
work.mkdir(parents=True)
|
|
1540
|
+
mp3 = work / "grabbed.mp3"
|
|
1541
|
+
mp3.write_bytes(b"ID3\x03fake-mp3-bytes")
|
|
1542
|
+
return AudioDownload(
|
|
1543
|
+
path=mp3, title="My Song", duration_s=200, notice="© respect it", info={}
|
|
1544
|
+
)
|
|
1493
1545
|
|
|
1494
|
-
|
|
1495
|
-
|
|
1546
|
+
monkeypatch.setattr("yb.download.download_audio_bounded", _bounded)
|
|
1547
|
+
return calls
|
|
1496
1548
|
|
|
1497
|
-
class _Res:
|
|
1498
|
-
path = str(mp3)
|
|
1499
|
-
info = {"title": "My Song", "duration": 200}
|
|
1500
|
-
sidecars = {}
|
|
1501
1549
|
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
monkeypatch.setitem(sys.modules, "yb", types.ModuleType("yb"))
|
|
1506
|
-
monkeypatch.setitem(sys.modules, "yb.download", fake)
|
|
1550
|
+
def test_download_audio_stores_asset_without_network(monkeypatch, tmp_path):
|
|
1551
|
+
import braidio.mcp._docs as _docs
|
|
1552
|
+
from braidio.mcp import tools
|
|
1507
1553
|
|
|
1554
|
+
calls = _fake_bounded(monkeypatch, tmp_path)
|
|
1508
1555
|
server = _local_server()
|
|
1509
1556
|
out = _call(
|
|
1510
1557
|
server, "download_audio", {"url": "https://example.com/song"}
|
|
@@ -1513,11 +1560,55 @@ def test_download_audio_stores_asset_without_network(monkeypatch, tmp_path):
|
|
|
1513
1560
|
assert out["name"] == "My Song"
|
|
1514
1561
|
assert out["duration"] == 200
|
|
1515
1562
|
assert out["source"] == "https://example.com/song"
|
|
1516
|
-
assert "
|
|
1563
|
+
assert out["copyright_notice"] == "© respect it" # yb's notice, carried
|
|
1517
1564
|
# stored content-addressed in the library (same shape as upload_asset) + listed
|
|
1518
1565
|
assert out["_tag"] == "ContentRef"
|
|
1519
1566
|
listed = _call(server, "list_assets", {}).structured_content["assets"]
|
|
1520
1567
|
assert any(a.get("name") == "My Song" and a.get("kind") == "audio" for a in listed)
|
|
1568
|
+
# braidio's policy inputs reach yb: its SSRF check and its env-tunable caps
|
|
1569
|
+
(call,) = calls
|
|
1570
|
+
assert call["validate_target"] is _docs._validate_target
|
|
1571
|
+
assert call["max_bytes"] == tools._AUDIO_MAX_BYTES
|
|
1572
|
+
assert call["max_duration_s"] == tools._AUDIO_MAX_DURATION_S
|
|
1573
|
+
assert dict(call["extra_opts"]) == {} # no credentials provisioned here
|
|
1574
|
+
# the per-call directory yb handed over is gone once the store owns the bytes,
|
|
1575
|
+
# and only it: the shared download directory other calls use stays
|
|
1576
|
+
downloads = Path(call["download_dir"])
|
|
1577
|
+
assert downloads.is_dir() and not (downloads / "per-call").exists()
|
|
1578
|
+
assert call["cookies_file"] is False # no cookie source but braidio's own
|
|
1579
|
+
|
|
1580
|
+
|
|
1581
|
+
def test_download_audio_limit_refusal_is_a_tool_error(monkeypatch, tmp_path):
|
|
1582
|
+
from fastmcp.exceptions import ToolError
|
|
1583
|
+
from yb.download import AudioLimitError
|
|
1584
|
+
|
|
1585
|
+
_fake_bounded(
|
|
1586
|
+
monkeypatch, tmp_path, raises=AudioLimitError("live streams are not supported")
|
|
1587
|
+
)
|
|
1588
|
+
with pytest.raises(ToolError, match="live streams are not supported"):
|
|
1589
|
+
_call(_local_server(), "download_audio", {"url": "https://example.com/live"})
|
|
1590
|
+
|
|
1591
|
+
|
|
1592
|
+
def test_download_audio_removes_the_download_when_ingest_fails(monkeypatch, tmp_path):
|
|
1593
|
+
from braidio.mcp import tools
|
|
1594
|
+
|
|
1595
|
+
calls = _fake_bounded(monkeypatch, tmp_path)
|
|
1596
|
+
|
|
1597
|
+
class _Boom(RuntimeError):
|
|
1598
|
+
pass
|
|
1599
|
+
|
|
1600
|
+
def _store():
|
|
1601
|
+
class _S:
|
|
1602
|
+
def add(self, *a, **k):
|
|
1603
|
+
raise _Boom("disk full")
|
|
1604
|
+
|
|
1605
|
+
return _S()
|
|
1606
|
+
|
|
1607
|
+
monkeypatch.setattr(tools.Workspace, "content_store", lambda self: _store())
|
|
1608
|
+
with pytest.raises(Exception, match="disk full"):
|
|
1609
|
+
_call(_local_server(), "download_audio", {"url": "https://example.com/song"})
|
|
1610
|
+
downloads = Path(calls[0]["download_dir"])
|
|
1611
|
+
assert downloads.is_dir() and not (downloads / "per-call").exists()
|
|
1521
1612
|
|
|
1522
1613
|
|
|
1523
1614
|
def test_download_audio_registered_free():
|
|
@@ -1527,15 +1618,14 @@ def test_download_audio_registered_free():
|
|
|
1527
1618
|
|
|
1528
1619
|
def test_download_audio_rejects_ssrf_target():
|
|
1529
1620
|
# A server-side fetch to a loopback/metadata host must be refused (no network:
|
|
1530
|
-
#
|
|
1621
|
+
# a literal IP is rejected by _validate_target without DNS). Matched on the
|
|
1622
|
+
# refusal's own words: any other ToolError would pass a bare raises().
|
|
1531
1623
|
from fastmcp.exceptions import ToolError
|
|
1532
1624
|
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
with pytest.raises(ToolError):
|
|
1538
|
-
download_audio("http://169.254.169.254/latest/meta-data/")
|
|
1625
|
+
server = _local_server()
|
|
1626
|
+
for url in ("http://127.0.0.1:8010/api/secrets", "http://169.254.169.254/latest/"):
|
|
1627
|
+
with pytest.raises(ToolError, match="not allowed|non-public host"):
|
|
1628
|
+
_call(server, "download_audio", {"url": url})
|
|
1539
1629
|
|
|
1540
1630
|
|
|
1541
1631
|
def test_current_email_falls_back_to_token(monkeypatch):
|
|
@@ -1588,96 +1678,63 @@ def test_register_tools_prefixes_and_excludes():
|
|
|
1588
1678
|
|
|
1589
1679
|
|
|
1590
1680
|
def test_download_audio_passes_configured_cookies_to_ytdlp(monkeypatch, tmp_path):
|
|
1591
|
-
"""braidio#23: credentials
|
|
1592
|
-
|
|
1593
|
-
The bot gate fires during metadata extraction, so cookies on the download call
|
|
1594
|
-
alone would still fail — and braidio's own `max_filesize` must survive the
|
|
1595
|
-
merge of the deployment's options.
|
|
1596
|
-
"""
|
|
1597
|
-
import sys
|
|
1681
|
+
"""braidio#23: the deployment's credentials reach yb, which hands them to both
|
|
1682
|
+
yt-dlp calls under its pinned caps (yb's own tests pin that half)."""
|
|
1598
1683
|
import time
|
|
1599
|
-
import types
|
|
1600
1684
|
|
|
1601
|
-
import braidio.mcp._docs as _docs
|
|
1602
1685
|
from braidio.mcp import _media
|
|
1603
1686
|
|
|
1604
|
-
monkeypatch.setattr(_docs, "_validate_target", lambda url: None)
|
|
1605
|
-
|
|
1606
1687
|
jar = tmp_path / "cookies.txt"
|
|
1607
1688
|
jar.write_text(
|
|
1608
1689
|
"# Netscape HTTP Cookie File\n"
|
|
1609
1690
|
f".youtube.com\tTRUE\t/\tTRUE\t{int(time.time() + 86400)}\tLOGIN_INFO\tv\n"
|
|
1610
1691
|
)
|
|
1611
1692
|
monkeypatch.setenv(_media.COOKIES_FILE_ENV_VAR, str(jar))
|
|
1693
|
+
calls = _fake_bounded(monkeypatch, tmp_path)
|
|
1612
1694
|
|
|
1613
|
-
|
|
1614
|
-
mp3.write_bytes(b"ID3\x03fake-mp3-bytes")
|
|
1615
|
-
seen = {}
|
|
1616
|
-
|
|
1617
|
-
class _Res:
|
|
1618
|
-
path = str(mp3)
|
|
1619
|
-
info = {"title": "S", "duration": 10}
|
|
1620
|
-
sidecars = {}
|
|
1621
|
-
|
|
1622
|
-
def _info(url, **kw):
|
|
1623
|
-
seen["info"] = kw.get("extra_opts") or {}
|
|
1624
|
-
return {"title": "S", "duration": 10}
|
|
1695
|
+
_call(_local_server(), "download_audio", {"url": "https://example.com/s"})
|
|
1625
1696
|
|
|
1626
|
-
|
|
1627
|
-
seen["download"] = kw.get("extra_opts") or {}
|
|
1628
|
-
return _Res()
|
|
1697
|
+
assert dict(calls[0]["extra_opts"]) == {"cookiefile": str(jar)}
|
|
1629
1698
|
|
|
1630
|
-
fake = types.ModuleType("yb.download")
|
|
1631
|
-
fake.youtube_video_info = _info
|
|
1632
|
-
fake.download_youtube_video = _download
|
|
1633
|
-
monkeypatch.setitem(sys.modules, "yb", types.ModuleType("yb"))
|
|
1634
|
-
monkeypatch.setitem(sys.modules, "yb.download", fake)
|
|
1635
1699
|
|
|
1636
|
-
|
|
1700
|
+
def test_download_audio_refuses_an_unreadable_cookie_jar_before_the_network(
|
|
1701
|
+
monkeypatch, tmp_path
|
|
1702
|
+
):
|
|
1703
|
+
from fastmcp.exceptions import ToolError
|
|
1637
1704
|
|
|
1638
|
-
|
|
1639
|
-
assert seen["download"]["cookiefile"] == str(jar)
|
|
1640
|
-
# braidio's bound is written after the deployment's options, so it stands.
|
|
1641
|
-
from braidio.mcp.tools import _AUDIO_MAX_BYTES
|
|
1705
|
+
from braidio.mcp import _media
|
|
1642
1706
|
|
|
1643
|
-
|
|
1707
|
+
monkeypatch.setenv(_media.COOKIES_FILE_ENV_VAR, str(tmp_path / "missing.txt"))
|
|
1708
|
+
calls = _fake_bounded(monkeypatch, tmp_path)
|
|
1709
|
+
with pytest.raises(ToolError, match="missing or unreadable"):
|
|
1710
|
+
_call(_local_server(), "download_audio", {"url": "https://example.com/s"})
|
|
1711
|
+
assert calls == [] # refused before yb (and the network) was reached
|
|
1644
1712
|
|
|
1645
1713
|
|
|
1646
1714
|
def test_download_audio_surfaces_bot_gate_as_auth_error(monkeypatch, tmp_path):
|
|
1647
1715
|
"""A bot gate becomes an error naming its own fix, not a raw yt-dlp string."""
|
|
1648
|
-
import
|
|
1649
|
-
import types
|
|
1716
|
+
from fastmcp.exceptions import ToolError
|
|
1650
1717
|
|
|
1651
|
-
import braidio.mcp._docs as _docs
|
|
1652
1718
|
from braidio.mcp import _media
|
|
1653
|
-
from braidio.mcp.tools import download_audio
|
|
1654
1719
|
|
|
1655
|
-
monkeypatch.setattr(_docs, "_validate_target", lambda url: None)
|
|
1656
1720
|
for var in (
|
|
1657
1721
|
_media.COOKIES_FILE_ENV_VAR,
|
|
1658
1722
|
_media.COOKIES_FROM_BROWSER_ENV_VAR,
|
|
1659
1723
|
_media.EXTRACTOR_ARGS_ENV_VAR,
|
|
1660
1724
|
):
|
|
1661
1725
|
monkeypatch.delenv(var, raising=False)
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
)
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
monkeypatch.setitem(sys.modules, "yb.download", fake)
|
|
1675
|
-
|
|
1676
|
-
with pytest.raises(_media.SourceAuthRequired) as excinfo:
|
|
1677
|
-
download_audio("https://example.com/s")
|
|
1678
|
-
message = str(excinfo.value)
|
|
1679
|
-
assert _media.COOKIES_FILE_ENV_VAR in message
|
|
1680
|
-
assert "--cookies-from-browser" not in message # no raw yt-dlp string leaks
|
|
1726
|
+
gate = (
|
|
1727
|
+
"ERROR: [youtube] x: Sign in to confirm you're not a bot. "
|
|
1728
|
+
"Use --cookies-from-browser or --cookies for the authentication."
|
|
1729
|
+
)
|
|
1730
|
+
# a ValueError too: yt-dlp can let one through, and it must still be classified
|
|
1731
|
+
for exc_type in (RuntimeError, ValueError):
|
|
1732
|
+
_fake_bounded(monkeypatch, tmp_path, raises=exc_type(gate))
|
|
1733
|
+
with pytest.raises(ToolError) as excinfo:
|
|
1734
|
+
_call(_local_server(), "download_audio", {"url": "https://example.com/s"})
|
|
1735
|
+
message = str(excinfo.value)
|
|
1736
|
+
assert _media.COOKIES_FILE_ENV_VAR in message
|
|
1737
|
+
assert "--cookies-from-browser" not in message # no raw yt-dlp string leaks
|
|
1681
1738
|
|
|
1682
1739
|
|
|
1683
1740
|
def test_ingest_document_as_beats_returns_a_loadable_script():
|