braidio 0.0.89__tar.gz → 0.0.90__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.
Files changed (150) hide show
  1. {braidio-0.0.89 → braidio-0.0.90}/PKG-INFO +1 -1
  2. {braidio-0.0.89 → braidio-0.0.90}/braidio/transforms/_episode.py +51 -13
  3. {braidio-0.0.89 → braidio-0.0.90}/pyproject.toml +1 -1
  4. {braidio-0.0.89 → braidio-0.0.90}/tests/test_transforms.py +153 -0
  5. {braidio-0.0.89 → braidio-0.0.90}/.editorconfig +0 -0
  6. {braidio-0.0.89 → braidio-0.0.90}/.gitattributes +0 -0
  7. {braidio-0.0.89 → braidio-0.0.90}/.gitignore +0 -0
  8. {braidio-0.0.89 → braidio-0.0.90}/LICENSE +0 -0
  9. {braidio-0.0.89 → braidio-0.0.90}/README.md +0 -0
  10. {braidio-0.0.89 → braidio-0.0.90}/braidio/__init__.py +0 -0
  11. {braidio-0.0.89 → braidio-0.0.90}/braidio/_paths.py +0 -0
  12. {braidio-0.0.89 → braidio-0.0.90}/braidio/bodies/__init__.py +0 -0
  13. {braidio-0.0.89 → braidio-0.0.90}/braidio/bodies/_domain.py +0 -0
  14. {braidio-0.0.89 → braidio-0.0.90}/braidio/bodies/_render_nodes.py +0 -0
  15. {braidio-0.0.89 → braidio-0.0.90}/braidio/bodies/_tiers.py +0 -0
  16. {braidio-0.0.89 → braidio-0.0.90}/braidio/bodies/_video.py +0 -0
  17. {braidio-0.0.89 → braidio-0.0.90}/braidio/captions.py +0 -0
  18. {braidio-0.0.89 → braidio-0.0.90}/braidio/compose.py +0 -0
  19. {braidio-0.0.89 → braidio-0.0.90}/braidio/conversation.py +0 -0
  20. {braidio-0.0.89 → braidio-0.0.90}/braidio/cost.py +0 -0
  21. {braidio-0.0.89 → braidio-0.0.90}/braidio/data/skills/braidio/SKILL.md +0 -0
  22. {braidio-0.0.89 → braidio-0.0.90}/braidio/data/skills/braidio-commentary-video/SKILL.md +0 -0
  23. {braidio-0.0.89 → braidio-0.0.90}/braidio/defaults.py +0 -0
  24. {braidio-0.0.89 → braidio-0.0.90}/braidio/delivery.py +0 -0
  25. {braidio-0.0.89 → braidio-0.0.90}/braidio/downloads.py +0 -0
  26. {braidio-0.0.89 → braidio-0.0.90}/braidio/formats.py +0 -0
  27. {braidio-0.0.89 → braidio-0.0.90}/braidio/genre.py +0 -0
  28. {braidio-0.0.89 → braidio-0.0.90}/braidio/importing/__init__.py +0 -0
  29. {braidio-0.0.89 → braidio-0.0.90}/braidio/importing/__main__.py +0 -0
  30. {braidio-0.0.89 → braidio-0.0.90}/braidio/importing/_catalog.py +0 -0
  31. {braidio-0.0.89 → braidio-0.0.90}/braidio/importing/_manifest.py +0 -0
  32. {braidio-0.0.89 → braidio-0.0.90}/braidio/importing/_writer.py +0 -0
  33. {braidio-0.0.89 → braidio-0.0.90}/braidio/kinds.py +0 -0
  34. {braidio-0.0.89 → braidio-0.0.90}/braidio/leveling.py +0 -0
  35. {braidio-0.0.89 → braidio-0.0.90}/braidio/markdown_script.py +0 -0
  36. {braidio-0.0.89 → braidio-0.0.90}/braidio/mcp/__init__.py +0 -0
  37. {braidio-0.0.89 → braidio-0.0.90}/braidio/mcp/_docs.py +0 -0
  38. {braidio-0.0.89 → braidio-0.0.90}/braidio/mcp/_guide.py +0 -0
  39. {braidio-0.0.89 → braidio-0.0.90}/braidio/mcp/_helpers.py +0 -0
  40. {braidio-0.0.89 → braidio-0.0.90}/braidio/mcp/_media.py +0 -0
  41. {braidio-0.0.89 → braidio-0.0.90}/braidio/mcp/credentials.py +0 -0
  42. {braidio-0.0.89 → braidio-0.0.90}/braidio/mcp/metering.py +0 -0
  43. {braidio-0.0.89 → braidio-0.0.90}/braidio/mcp/tools.py +0 -0
  44. {braidio-0.0.89 → braidio-0.0.90}/braidio/mcp/workspace.py +0 -0
  45. {braidio-0.0.89 → braidio-0.0.90}/braidio/multivoice.py +0 -0
  46. {braidio-0.0.89 → braidio-0.0.90}/braidio/music.py +0 -0
  47. {braidio-0.0.89 → braidio-0.0.90}/braidio/pacing.py +0 -0
  48. {braidio-0.0.89 → braidio-0.0.90}/braidio/project.py +0 -0
  49. {braidio-0.0.89 → braidio-0.0.90}/braidio/provenance.py +0 -0
  50. {braidio-0.0.89 → braidio-0.0.90}/braidio/relevance.py +0 -0
  51. {braidio-0.0.89 → braidio-0.0.90}/braidio/render.py +0 -0
  52. {braidio-0.0.89 → braidio-0.0.90}/braidio/rights.py +0 -0
  53. {braidio-0.0.89 → braidio-0.0.90}/braidio/script.py +0 -0
  54. {braidio-0.0.89 → braidio-0.0.90}/braidio/sources.py +0 -0
  55. {braidio-0.0.89 → braidio-0.0.90}/braidio/structure.py +0 -0
  56. {braidio-0.0.89 → braidio-0.0.90}/braidio/style.py +0 -0
  57. {braidio-0.0.89 → braidio-0.0.90}/braidio/textprep.py +0 -0
  58. {braidio-0.0.89 → braidio-0.0.90}/braidio/timeline.py +0 -0
  59. {braidio-0.0.89 → braidio-0.0.90}/braidio/transforms/__init__.py +0 -0
  60. {braidio-0.0.89 → braidio-0.0.90}/braidio/transforms/_asset_refs.py +0 -0
  61. {braidio-0.0.89 → braidio-0.0.90}/braidio/transforms/_common.py +0 -0
  62. {braidio-0.0.89 → braidio-0.0.90}/braidio/transforms/_dialogue.py +0 -0
  63. {braidio-0.0.89 → braidio-0.0.90}/braidio/transforms/_ingest.py +0 -0
  64. {braidio-0.0.89 → braidio-0.0.90}/braidio/transforms/_narration.py +0 -0
  65. {braidio-0.0.89 → braidio-0.0.90}/braidio/transforms/_segment.py +0 -0
  66. {braidio-0.0.89 → braidio-0.0.90}/braidio/transforms/_video_cut.py +0 -0
  67. {braidio-0.0.89 → braidio-0.0.90}/braidio/transforms/_video_panels.py +0 -0
  68. {braidio-0.0.89 → braidio-0.0.90}/braidio/transforms/_voice.py +0 -0
  69. {braidio-0.0.89 → braidio-0.0.90}/braidio/tts.py +0 -0
  70. {braidio-0.0.89 → braidio-0.0.90}/braidio/video.py +0 -0
  71. {braidio-0.0.89 → braidio-0.0.90}/braidio/voice_library.py +0 -0
  72. {braidio-0.0.89 → braidio-0.0.90}/braidio/weave.py +0 -0
  73. {braidio-0.0.89 → braidio-0.0.90}/braidio/weave_config.py +0 -0
  74. {braidio-0.0.89 → braidio-0.0.90}/conftest.py +0 -0
  75. {braidio-0.0.89 → braidio-0.0.90}/misc/docs/Extraction and nw-App Design.md +0 -0
  76. {braidio-0.0.89 → braidio-0.0.90}/misc/docs/research/commentary-formats-and-styles.md +0 -0
  77. {braidio-0.0.89 → braidio-0.0.90}/misc/docs/research/conversational-vs-narration-tts.md +0 -0
  78. {braidio-0.0.89 → braidio-0.0.90}/misc/docs/research/notebooklm-and-conversational-pacing.md +0 -0
  79. {braidio-0.0.89 → braidio-0.0.90}/misc/docs/style/README.md +0 -0
  80. {braidio-0.0.89 → braidio-0.0.90}/misc/docs/style/anti-platitude-checklist.md +0 -0
  81. {braidio-0.0.89 → braidio-0.0.90}/misc/docs/style/commentary-voice-guide.md +0 -0
  82. {braidio-0.0.89 → braidio-0.0.90}/misc/docs/style/voices/_style-groups.md +0 -0
  83. {braidio-0.0.89 → braidio-0.0.90}/misc/docs/style/voices/amanda-dobbins.md +0 -0
  84. {braidio-0.0.89 → braidio-0.0.90}/misc/docs/style/voices/david-sims.md +0 -0
  85. {braidio-0.0.89 → braidio-0.0.90}/misc/docs/style/voices/griffin-newman.md +0 -0
  86. {braidio-0.0.89 → braidio-0.0.90}/misc/docs/style/voices/helen-molesworth.md +0 -0
  87. {braidio-0.0.89 → braidio-0.0.90}/misc/docs/style/voices/hrishikesh-hirway.md +0 -0
  88. {braidio-0.0.89 → braidio-0.0.90}/misc/docs/style/voices/jason-mantzoukas.md +0 -0
  89. {braidio-0.0.89 → braidio-0.0.90}/misc/docs/style/voices/john-mcwhorter.md +0 -0
  90. {braidio-0.0.89 → braidio-0.0.90}/misc/docs/style/voices/jon-caramanica.md +0 -0
  91. {braidio-0.0.89 → braidio-0.0.90}/misc/docs/style/voices/june-diane-raphael.md +0 -0
  92. {braidio-0.0.89 → braidio-0.0.90}/misc/docs/style/voices/karina-longworth.md +0 -0
  93. {braidio-0.0.89 → braidio-0.0.90}/misc/docs/style/voices/katy-hessel.md +0 -0
  94. {braidio-0.0.89 → braidio-0.0.90}/misc/docs/style/voices/louis-theroux.md +0 -0
  95. {braidio-0.0.89 → braidio-0.0.90}/misc/docs/style/voices/mallory-rubin.md +0 -0
  96. {braidio-0.0.89 → braidio-0.0.90}/misc/docs/style/voices/melvyn-bragg.md +0 -0
  97. {braidio-0.0.89 → braidio-0.0.90}/misc/docs/style/voices/michael-barbaro.md +0 -0
  98. {braidio-0.0.89 → braidio-0.0.90}/misc/docs/style/voices/nate-sloan-charlie-harding.md +0 -0
  99. {braidio-0.0.89 → braidio-0.0.90}/misc/docs/style/voices/paul-scheer.md +0 -0
  100. {braidio-0.0.89 → braidio-0.0.90}/misc/docs/style/voices/sean-fennessey.md +0 -0
  101. {braidio-0.0.89 → braidio-0.0.90}/misc/docs/style/voices/talk-art.md +0 -0
  102. {braidio-0.0.89 → braidio-0.0.90}/misc/docs/style/voices/yasi-salek.md +0 -0
  103. {braidio-0.0.89 → braidio-0.0.90}/misc/docs/youtube_ingest_credentials.md +0 -0
  104. {braidio-0.0.89 → braidio-0.0.90}/tests/_audio.py +0 -0
  105. {braidio-0.0.89 → braidio-0.0.90}/tests/test_body_schema_stability.py +0 -0
  106. {braidio-0.0.89 → braidio-0.0.90}/tests/test_conversation.py +0 -0
  107. {braidio-0.0.89 → braidio-0.0.90}/tests/test_cost.py +0 -0
  108. {braidio-0.0.89 → braidio-0.0.90}/tests/test_credits_card.py +0 -0
  109. {braidio-0.0.89 → braidio-0.0.90}/tests/test_defaults.py +0 -0
  110. {braidio-0.0.89 → braidio-0.0.90}/tests/test_delivery.py +0 -0
  111. {braidio-0.0.89 → braidio-0.0.90}/tests/test_downloads.py +0 -0
  112. {braidio-0.0.89 → braidio-0.0.90}/tests/test_expressiveness.py +0 -0
  113. {braidio-0.0.89 → braidio-0.0.90}/tests/test_formats.py +0 -0
  114. {braidio-0.0.89 → braidio-0.0.90}/tests/test_genre_placement.py +0 -0
  115. {braidio-0.0.89 → braidio-0.0.90}/tests/test_graph_speak.py +0 -0
  116. {braidio-0.0.89 → braidio-0.0.90}/tests/test_importing.py +0 -0
  117. {braidio-0.0.89 → braidio-0.0.90}/tests/test_leveling.py +0 -0
  118. {braidio-0.0.89 → braidio-0.0.90}/tests/test_markdown_script.py +0 -0
  119. {braidio-0.0.89 → braidio-0.0.90}/tests/test_mcp.py +0 -0
  120. {braidio-0.0.89 → braidio-0.0.90}/tests/test_mcp_caller_key.py +0 -0
  121. {braidio-0.0.89 → braidio-0.0.90}/tests/test_media_auth.py +0 -0
  122. {braidio-0.0.89 → braidio-0.0.90}/tests/test_multivoice.py +0 -0
  123. {braidio-0.0.89 → braidio-0.0.90}/tests/test_music.py +0 -0
  124. {braidio-0.0.89 → braidio-0.0.90}/tests/test_namespaced_source.py +0 -0
  125. {braidio-0.0.89 → braidio-0.0.90}/tests/test_nw_app.py +0 -0
  126. {braidio-0.0.89 → braidio-0.0.90}/tests/test_pacing.py +0 -0
  127. {braidio-0.0.89 → braidio-0.0.90}/tests/test_packaging.py +0 -0
  128. {braidio-0.0.89 → braidio-0.0.90}/tests/test_render_settings.py +0 -0
  129. {braidio-0.0.89 → braidio-0.0.90}/tests/test_script.py +0 -0
  130. {braidio-0.0.89 → braidio-0.0.90}/tests/test_sources.py +0 -0
  131. {braidio-0.0.89 → braidio-0.0.90}/tests/test_speak_seam.py +0 -0
  132. {braidio-0.0.89 → braidio-0.0.90}/tests/test_structure.py +0 -0
  133. {braidio-0.0.89 → braidio-0.0.90}/tests/test_textprep_style.py +0 -0
  134. {braidio-0.0.89 → braidio-0.0.90}/tests/test_timeline.py +0 -0
  135. {braidio-0.0.89 → braidio-0.0.90}/tests/test_transforms_dialogue.py +0 -0
  136. {braidio-0.0.89 → braidio-0.0.90}/tests/test_transforms_episode_members.py +0 -0
  137. {braidio-0.0.89 → braidio-0.0.90}/tests/test_transforms_rights.py +0 -0
  138. {braidio-0.0.89 → braidio-0.0.90}/tests/test_transforms_secrets.py +0 -0
  139. {braidio-0.0.89 → braidio-0.0.90}/tests/test_transforms_structure.py +0 -0
  140. {braidio-0.0.89 → braidio-0.0.90}/tests/test_tts_api_key.py +0 -0
  141. {braidio-0.0.89 → braidio-0.0.90}/tests/test_turn_overlap.py +0 -0
  142. {braidio-0.0.89 → braidio-0.0.90}/tests/test_video.py +0 -0
  143. {braidio-0.0.89 → braidio-0.0.90}/tests/test_video_bodies.py +0 -0
  144. {braidio-0.0.89 → braidio-0.0.90}/tests/test_video_footage.py +0 -0
  145. {braidio-0.0.89 → braidio-0.0.90}/tests/test_video_transforms.py +0 -0
  146. {braidio-0.0.89 → braidio-0.0.90}/tests/test_voice_library.py +0 -0
  147. {braidio-0.0.89 → braidio-0.0.90}/tests/test_weave.py +0 -0
  148. {braidio-0.0.89 → braidio-0.0.90}/tests/test_weave_config.py +0 -0
  149. {braidio-0.0.89 → braidio-0.0.90}/tests/test_weave_master.py +0 -0
  150. {braidio-0.0.89 → braidio-0.0.90}/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.89
3
+ Version: 0.0.90
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
@@ -57,6 +57,7 @@ into the delivered artifact.
57
57
  from __future__ import annotations
58
58
 
59
59
  import uuid
60
+ from pathlib import Path
60
61
  from dataclasses import dataclass
61
62
  from typing import Optional
62
63
 
@@ -109,6 +110,7 @@ from braidio.transforms._common import (
109
110
  audio_artifact,
110
111
  safe_duration,
111
112
  file_url,
113
+ media_path,
112
114
  url_to_path,
113
115
  )
114
116
  from braidio.transforms._segment import _pads_fades
@@ -120,12 +122,15 @@ NAME = "weave_to_episode.default"
120
122
  _LABEL_SNIPPET_CHARS = 48
121
123
 
122
124
 
123
- def _structure_and_bed(node: Annotation | None):
125
+ def _structure_and_bed(project_root, node: Annotation | None):
124
126
  """``(MusicStructure, MusicBed | None)`` from a ``production-structure`` node.
125
127
 
126
128
  ``None`` (no such node) resolves to braidio's inert default structure and no
127
129
  bed — the pre-structure behaviour, reconstructed rather than special-cased
128
- at every use site.
130
+ at every use site. The sting and bed audio are found by their asset id
131
+ first (:func:`media_path`), so a project moved to another machine still
132
+ reads them; one found nowhere, with a recorded url, is not an error *here*
133
+ (a timeline read never plays the bed), only where it is played.
129
134
  """
130
135
  from braidio.music import MusicBed
131
136
  from braidio.structure import DEFAULT_STRUCTURE, MusicStructure, Sting
@@ -134,14 +139,41 @@ def _structure_and_bed(node: Annotation | None):
134
139
  return DEFAULT_STRUCTURE, None
135
140
  body = node.body
136
141
  sting = None
137
- if body.get("sting_url"):
138
- sting = Sting(str(url_to_path(body["sting_url"])), **(body.get("sting") or {}))
142
+ if body.get("sting_url") or body.get("sting_asset_id"):
143
+ sting = Sting(
144
+ str(_asset_path(project_root, body, "sting")), **(body.get("sting") or {})
145
+ )
139
146
  bed = None
140
- if body.get("bed_url"):
141
- bed = MusicBed(str(url_to_path(body["bed_url"])), **(body.get("bed") or {}))
147
+ if body.get("bed_url") or body.get("bed_asset_id"):
148
+ bed = MusicBed(
149
+ str(_asset_path(project_root, body, "bed")), **(body.get("bed") or {})
150
+ )
142
151
  return MusicStructure(sting=sting, **(body.get("structure") or {})), bed
143
152
 
144
153
 
154
+ def _asset_path(project_root, body: dict, asset: str) -> Path:
155
+ """The file of a structure node's ``asset`` (``"sting"`` / ``"bed"``).
156
+
157
+ Found nowhere → the recorded location, unchecked, as before
158
+ :func:`media_path`: the caller that plays it is the one that fails.
159
+ """
160
+ ref = {
161
+ "artifact_id": body.get(f"{asset}_asset_id"),
162
+ "url": body.get(f"{asset}_url"),
163
+ }
164
+ try:
165
+ return media_path(project_root, ref, what=f"production-structure {asset}")
166
+ except FileNotFoundError:
167
+ if not ref["url"]:
168
+ raise
169
+ return url_to_path(ref["url"])
170
+
171
+
172
+ def _member_what(member: Annotation) -> str:
173
+ """How an error names ``member``'s media."""
174
+ return f"{member.tier} {member.id}"
175
+
176
+
145
177
  def _member_role(member: Annotation, index: dict, *, structure):
146
178
  """``(role, label, source_span)`` for one episode member — the timeline's
147
179
  per-beat metadata, mirroring ``braidio.render``'s conventions exactly.
@@ -253,10 +285,12 @@ def _member_duration(project, member: Annotation, *, config: dict, structure) ->
253
285
  return length + sting.gap_after_s
254
286
  return float(structure.pause_s)
255
287
 
256
- url = member.body.get("url")
257
- if url:
258
- path = url_to_path(url)
259
- if path.exists():
288
+ if member.body.get("url") or member.body.get("artifact_id"):
289
+ try:
290
+ path = media_path(project.root, member.body, what=_member_what(member))
291
+ except FileNotFoundError:
292
+ path = None # gone from disk: the arithmetic below
293
+ if path is not None:
260
294
  return float(braidio.duration_s(path))
261
295
 
262
296
  if member.tier == TIER_SEGMENT_EXTRACTION:
@@ -289,7 +323,8 @@ def episode_timeline(project, episode: Annotation) -> TimelineBreakdown:
289
323
  cfg = singleton(project, TIER_WEAVE_CONFIG)
290
324
  config = cfg.body.get("config", {})
291
325
  structure, _bed = _structure_and_bed(
292
- next((p for p in parents if p.tier == TIER_PRODUCTION_STRUCTURE), None)
326
+ project.root,
327
+ next((p for p in parents if p.tier == TIER_PRODUCTION_STRUCTURE), None),
293
328
  )
294
329
  members = _resolve_members(
295
330
  episode,
@@ -652,7 +687,8 @@ class WeaveToEpisode(BaseTransform):
652
687
  cfg = require_tier(parents, TIER_WEAVE_CONFIG)
653
688
  config = cfg.body.get("config", {})
654
689
  structure, bed = _structure_and_bed(
655
- next((a for a in parents if a.tier == TIER_PRODUCTION_STRUCTURE), None)
690
+ project.root,
691
+ next((a for a in parents if a.tier == TIER_PRODUCTION_STRUCTURE), None),
656
692
  )
657
693
  weave = WeaveConfig.from_snapshot(config) # omitted knobs → the defaults
658
694
  target_lufs = weave.target_lufs
@@ -666,6 +702,7 @@ class WeaveToEpisode(BaseTransform):
666
702
  bed=bed,
667
703
  target_lufs=target_lufs,
668
704
  breaks_dir=breaks_dir,
705
+ project_root=project.root,
669
706
  )
670
707
  for m in members
671
708
  ]
@@ -735,6 +772,7 @@ class WeaveToEpisode(BaseTransform):
735
772
  bed,
736
773
  target_lufs: float,
737
774
  breaks_dir,
775
+ project_root,
738
776
  ) -> TimelineItem:
739
777
  """One timeline part for ``member`` — a rendered beat, or a scene break.
740
778
 
@@ -760,7 +798,7 @@ class WeaveToEpisode(BaseTransform):
760
798
  is_clip = member.tier == TIER_SEGMENT_EXTRACTION
761
799
  return TimelineItem(
762
800
  kind="clip" if is_clip else "narration",
763
- path=str(url_to_path(member.body["url"])),
801
+ path=str(media_path(project_root, member.body, what=_member_what(member))),
764
802
  placement="sequential",
765
803
  speaker=_member_speaker(member, index),
766
804
  spotlight=(
@@ -6,7 +6,7 @@ build-backend = "hatchling.build"
6
6
 
7
7
  [project]
8
8
  name = "braidio"
9
- version = "0.0.89"
9
+ version = "0.0.90"
10
10
  description = "Weave narration with extracted media segments into audiovisual productions"
11
11
  readme = "README.md"
12
12
  requires-python = ">=3.10"
@@ -1335,3 +1335,156 @@ def test_genre_status_follows_the_project_from_empty_to_woven(
1335
1335
  # and no string naming the project root — the episode's file:// url is left out)
1336
1336
  assert nw.genre_status_of(project) == woven
1337
1337
  assert str(project.root) not in repr(woven)
1338
+
1339
+
1340
+ # --- the weave reads takes by content, not by recorded path (braidio#86) ---------
1341
+
1342
+
1343
+ def test_a_reweave_reads_the_takes_by_artifact_id_when_their_urls_point_nowhere(
1344
+ project, script_and_source, patched_synthesis, monkeypatch
1345
+ ):
1346
+ """The server case for an imported project: every take's recorded url is
1347
+ the importing machine's path, so the weave must find each take through the
1348
+ delivery catalog, keyed by the ``artifact_id`` the graph already records,
1349
+ exactly as the stills do (braidio#89/#90)."""
1350
+ import shutil
1351
+
1352
+ import nw
1353
+
1354
+ from braidio.importing._catalog import CatalogReport, register_artifact
1355
+ from braidio.transforms._common import url_to_path
1356
+
1357
+ script, source = script_and_source
1358
+ braidio.weave_project(project, script, source=source)
1359
+
1360
+ takes = [
1361
+ a
1362
+ for tier in ("narration-renders", "segment-extractions")
1363
+ for a in nw.annotations_at_tier(project.root, tier)
1364
+ ]
1365
+ for take in takes:
1366
+ original = url_to_path(take.body["url"])
1367
+ inside = project.root / "media" / original.name
1368
+ inside.parent.mkdir(parents=True, exist_ok=True)
1369
+ shutil.copy2(original, inside)
1370
+ register_artifact(
1371
+ project.root,
1372
+ inside,
1373
+ artifact_id=take.body["artifact_id"],
1374
+ kind="audio",
1375
+ generated_at="2026-11-02T00:00:00Z",
1376
+ report=CatalogReport(),
1377
+ )
1378
+ original.unlink()
1379
+ _rewrite_in_place(
1380
+ project,
1381
+ take,
1382
+ body={
1383
+ **take.body,
1384
+ "url": f"file:///Users/someone-else/gone/{original.name}",
1385
+ },
1386
+ )
1387
+
1388
+ woven = []
1389
+
1390
+ def _capture(items, out, **kw):
1391
+ woven.extend(items)
1392
+ Path(out).write_bytes(b"EPISODE")
1393
+ return Path(out)
1394
+
1395
+ monkeypatch.setattr(braidio, "weave_timeline", _capture)
1396
+ braidio.weave_project(project, script, source=source)
1397
+
1398
+ assert len(woven) == len(takes)
1399
+ assert all(Path(item.path).exists() for item in woven)
1400
+ assert not any("someone-else" in item.path for item in woven)
1401
+
1402
+
1403
+ def test_the_sting_and_bed_are_read_by_asset_id_when_their_urls_point_nowhere(
1404
+ project, script_and_source, patched_synthesis, tmp_path
1405
+ ):
1406
+ """Same rule for the production-structure assets: ``*_asset_id`` first."""
1407
+ import nw
1408
+
1409
+ from braidio.importing._catalog import CatalogReport, register_artifact
1410
+ from braidio.transforms._episode import _structure_and_bed
1411
+
1412
+ _weave_with_sting_and_bed(project, script_and_source, tmp_path)
1413
+ (node,) = nw.annotations_at_tier(project.root, "production-structures")
1414
+ body = dict(node.body)
1415
+ for asset, name in (("sting", "hit.mp3"), ("bed", "bed.mp3")):
1416
+ inside = project.root / "media" / name
1417
+ inside.parent.mkdir(parents=True, exist_ok=True)
1418
+ (tmp_path / name).rename(inside)
1419
+ register_artifact(
1420
+ project.root,
1421
+ inside,
1422
+ artifact_id=body[f"{asset}_asset_id"],
1423
+ kind="audio",
1424
+ generated_at="2026-11-02T00:00:00Z",
1425
+ report=CatalogReport(),
1426
+ )
1427
+ body[f"{asset}_url"] = f"file:///Users/someone-else/gone/{name}"
1428
+
1429
+ structure, bed = _structure_and_bed(
1430
+ project.root, node.model_copy(update={"body": body})
1431
+ )
1432
+
1433
+ assert Path(structure.sting.asset_path).read_bytes() == b"STING-ASSET"
1434
+ assert Path(bed.asset_path).read_bytes() == b"BED-ASSET"
1435
+
1436
+
1437
+ def test_a_reconstructed_timeline_probes_the_takes_found_in_the_catalog(
1438
+ project, script_and_source, patched_synthesis, monkeypatch
1439
+ ):
1440
+ """``episode_timeline`` on a row with no persisted timeline probes each
1441
+ take where ``media_path`` finds it, not at its recorded url."""
1442
+ import nw
1443
+
1444
+ from braidio.importing._catalog import CatalogReport, register_artifact
1445
+ from braidio.transforms import episode_timeline
1446
+ from braidio.transforms._common import url_to_path
1447
+
1448
+ script, source = script_and_source
1449
+ episode = braidio.weave_project(project, script, source=source)
1450
+ narration = nw.annotations_at_tier(project.root, "narration-renders")[0]
1451
+ original = url_to_path(narration.body["url"])
1452
+ inside = project.root / "media" / original.name
1453
+ inside.parent.mkdir(parents=True, exist_ok=True)
1454
+ original.rename(inside)
1455
+ register_artifact(
1456
+ project.root,
1457
+ inside,
1458
+ artifact_id=narration.body["artifact_id"],
1459
+ kind="audio",
1460
+ generated_at="2026-11-02T00:00:00Z",
1461
+ report=CatalogReport(),
1462
+ )
1463
+ probed = []
1464
+ monkeypatch.setattr(braidio, "duration_s", lambda p: probed.append(p) or 2.0)
1465
+
1466
+ stripped = {k: v for k, v in episode.body.items() if k != "timeline"}
1467
+ episode_timeline(project, episode.model_copy(update={"body": stripped}))
1468
+
1469
+ assert any(Path(p).parent.name == "blobs" for p in probed), probed
1470
+
1471
+
1472
+ def test_a_missing_bed_does_not_fail_a_read_that_never_plays_it(
1473
+ project, script_and_source, patched_synthesis, tmp_path
1474
+ ):
1475
+ """Found nowhere, the sting and bed keep their recorded location unchecked:
1476
+ only the caller that plays them fails (a timeline read never does)."""
1477
+ import nw
1478
+
1479
+ from braidio.transforms._common import url_to_path
1480
+ from braidio.transforms._episode import _structure_and_bed
1481
+
1482
+ _weave_with_sting_and_bed(project, script_and_source, tmp_path)
1483
+ (node,) = nw.annotations_at_tier(project.root, "production-structures")
1484
+ (tmp_path / "bed.mp3").unlink()
1485
+ (tmp_path / "hit.mp3").unlink()
1486
+
1487
+ structure, bed = _structure_and_bed(project.root, node)
1488
+
1489
+ assert Path(bed.asset_path) == url_to_path(node.body["bed_url"])
1490
+ assert Path(structure.sting.asset_path) == url_to_path(node.body["sting_url"])
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes