videopython 0.60.1__tar.gz → 0.61.0__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 (94) hide show
  1. {videopython-0.60.1 → videopython-0.61.0}/PKG-INFO +1 -1
  2. {videopython-0.60.1 → videopython-0.61.0}/pyproject.toml +1 -1
  3. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/ai/dubbing/models.py +2 -25
  4. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/ai/video_analysis/models.py +6 -63
  5. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/base/__init__.py +1 -1
  6. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/base/description.py +27 -195
  7. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/base/transcription.py +53 -96
  8. {videopython-0.60.1 → videopython-0.61.0}/.gitignore +0 -0
  9. {videopython-0.60.1 → videopython-0.61.0}/LICENSE +0 -0
  10. {videopython-0.60.1 → videopython-0.61.0}/README.md +0 -0
  11. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/__init__.py +0 -0
  12. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/_exceptions.py +0 -0
  13. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/_ffmpeg.py +0 -0
  14. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/ai/__init__.py +0 -0
  15. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/ai/_device.py +0 -0
  16. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/ai/_ollama.py +0 -0
  17. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/ai/_optional.py +0 -0
  18. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/ai/_predictor.py +0 -0
  19. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/ai/_revisions.py +0 -0
  20. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/ai/auto_edit/__init__.py +0 -0
  21. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/ai/auto_edit/backend.py +0 -0
  22. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/ai/auto_edit/catalog.py +0 -0
  23. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/ai/auto_edit/editor.py +0 -0
  24. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/ai/auto_edit/local.py +0 -0
  25. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/ai/auto_edit/models.py +0 -0
  26. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/ai/auto_edit/resolve.py +0 -0
  27. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/ai/dubbing/__init__.py +0 -0
  28. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/ai/dubbing/_tts_backend.py +0 -0
  29. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/ai/dubbing/audio_ops.py +0 -0
  30. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/ai/dubbing/config.py +0 -0
  31. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/ai/dubbing/dubber.py +0 -0
  32. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/ai/dubbing/pipeline.py +0 -0
  33. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/ai/dubbing/quality.py +0 -0
  34. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/ai/dubbing/remux.py +0 -0
  35. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/ai/dubbing/separation.py +0 -0
  36. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/ai/dubbing/timing.py +0 -0
  37. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/ai/dubbing/translation.py +0 -0
  38. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/ai/dubbing/voice_sample.py +0 -0
  39. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/ai/effects.py +0 -0
  40. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/ai/errors.py +0 -0
  41. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/ai/generation/__init__.py +0 -0
  42. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/ai/generation/audio.py +0 -0
  43. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/ai/generation/image.py +0 -0
  44. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/ai/generation/video.py +0 -0
  45. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/ai/keyframe.py +0 -0
  46. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/ai/ops.py +0 -0
  47. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/ai/transforms.py +0 -0
  48. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/ai/understanding/__init__.py +0 -0
  49. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/ai/understanding/_detector.py +0 -0
  50. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/ai/understanding/audio.py +0 -0
  51. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/ai/understanding/classification.py +0 -0
  52. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/ai/understanding/faces.py +0 -0
  53. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/ai/understanding/image.py +0 -0
  54. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/ai/understanding/objects.py +0 -0
  55. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/ai/understanding/temporal.py +0 -0
  56. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/ai/video_analysis/__init__.py +0 -0
  57. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/ai/video_analysis/analyzer.py +0 -0
  58. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/ai/video_analysis/detectors.py +0 -0
  59. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/ai/video_analysis/sampling.py +0 -0
  60. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/ai/video_analysis/source_metadata.py +0 -0
  61. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/audio/__init__.py +0 -0
  62. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/audio/analysis.py +0 -0
  63. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/audio/audio.py +0 -0
  64. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/base/_dimensions.py +0 -0
  65. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/base/_video_io.py +0 -0
  66. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/base/draw_detections.py +0 -0
  67. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/base/fonts/Anton-OFL.txt +0 -0
  68. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/base/fonts/Anton-Regular.ttf +0 -0
  69. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/base/fonts/BebasNeue-OFL.txt +0 -0
  70. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/base/fonts/BebasNeue-Regular.ttf +0 -0
  71. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/base/fonts/DejaVuSans.ttf +0 -0
  72. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/base/fonts/LICENSE_DEJAVU +0 -0
  73. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/base/fonts/Lato-Bold.ttf +0 -0
  74. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/base/fonts/Lato-OFL.txt +0 -0
  75. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/base/fonts/Poppins-Bold.ttf +0 -0
  76. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/base/fonts/Poppins-OFL.txt +0 -0
  77. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/base/fonts/__init__.py +0 -0
  78. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/base/video.py +0 -0
  79. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/editing/__init__.py +0 -0
  80. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/editing/_ass.py +0 -0
  81. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/editing/_easing.py +0 -0
  82. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/editing/_schema.py +0 -0
  83. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/editing/audio_ops.py +0 -0
  84. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/editing/effects.py +0 -0
  85. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/editing/errors.py +0 -0
  86. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/editing/operation.py +0 -0
  87. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/editing/streaming.py +0 -0
  88. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/editing/transcription_overlay.py +0 -0
  89. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/editing/transforms.py +0 -0
  90. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/editing/video_edit.py +0 -0
  91. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/mcp/__init__.py +0 -0
  92. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/mcp/_models.py +0 -0
  93. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/mcp/server.py +0 -0
  94. {videopython-0.60.1 → videopython-0.61.0}/src/videopython/py.typed +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: videopython
3
- Version: 0.60.1
3
+ Version: 0.61.0
4
4
  Summary: LLM-friendly Python video editing with JSON plans, local AI, and MCP tools.
5
5
  Project-URL: Homepage, https://videopython.com
6
6
  Project-URL: Repository, https://github.com/bartwojtowicz/videopython/
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "videopython"
3
- version = "0.60.1"
3
+ version = "0.61.0"
4
4
  description = "LLM-friendly Python video editing with JSON plans, local AI, and MCP tools."
5
5
  authors = [
6
6
  { name = "Bartosz Wójtowicz", email = "bartoszwojtowicz@outlook.com" },
@@ -3,9 +3,8 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  from dataclasses import dataclass
6
- from typing import Annotated, Any
7
6
 
8
- from pydantic import BaseModel, BeforeValidator, ConfigDict, Field, PlainSerializer, model_validator
7
+ from pydantic import BaseModel, ConfigDict, Field, model_validator
9
8
 
10
9
  from videopython.ai.dubbing.quality import TranscriptQuality
11
10
  from videopython.audio import Audio
@@ -39,26 +38,6 @@ class TimingAdjustment:
39
38
  CLEAN_SPEED_TOLERANCE = 0.01
40
39
 
41
40
 
42
- # TranscriptionSegment and Transcription still live in videopython.base as
43
- # plain dataclasses with hand-rolled to_dict/from_dict. Bridge them at
44
- # the field boundary so the dubbing cache wire format stays identical.
45
- def _validate_transcription_segment(value: Any) -> Any:
46
- if value is None or isinstance(value, TranscriptionSegment):
47
- return value
48
- return TranscriptionSegment.from_dict(value)
49
-
50
-
51
- def _serialize_with_to_dict(value: Any) -> Any:
52
- return value.to_dict() if value is not None else None
53
-
54
-
55
- _TranscriptionSegmentField = Annotated[
56
- TranscriptionSegment,
57
- BeforeValidator(_validate_transcription_segment),
58
- PlainSerializer(_serialize_with_to_dict, return_type=dict, when_used="always"),
59
- ]
60
-
61
-
62
41
  class Expressiveness(BaseModel):
63
42
  """Chatterbox ``generate()`` knobs derived from source-segment prosody.
64
43
 
@@ -108,9 +87,7 @@ class TranslatedSegment(BaseModel):
108
87
  end: End time in seconds.
109
88
  """
110
89
 
111
- model_config = ConfigDict(arbitrary_types_allowed=True)
112
-
113
- original_segment: _TranscriptionSegmentField
90
+ original_segment: TranscriptionSegment
114
91
  translated_text: str
115
92
  source_lang: str
116
93
  target_lang: str
@@ -3,9 +3,9 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  from pathlib import Path
6
- from typing import Annotated, Any, Literal
6
+ from typing import Any, Literal
7
7
 
8
- from pydantic import BaseModel, BeforeValidator, ConfigDict, Field, PlainSerializer, model_validator
8
+ from pydantic import BaseModel, ConfigDict, Field, model_validator
9
9
 
10
10
  from videopython.base.description import AudioClassification, FaceTrack, SceneDescription
11
11
  from videopython.base.transcription import Transcription
@@ -51,59 +51,6 @@ ALL_ANALYZER_IDS: tuple[_AnalyzerId, ...] = (
51
51
  )
52
52
 
53
53
 
54
- # Nested-type bridges: Transcription, SceneDescription, AudioClassification,
55
- # and FaceTrack still live in videopython.base as plain dataclasses with
56
- # hand-rolled to_dict/from_dict. Until they migrate to BaseModel, we
57
- # interop at the field boundary so the wire format stays identical.
58
- def _build_validator(cls: Any) -> Any:
59
- def _validate(value: Any) -> Any:
60
- if value is None or isinstance(value, cls):
61
- return value
62
- return cls.from_dict(value)
63
-
64
- return _validate
65
-
66
-
67
- def _serialize(value: Any) -> Any:
68
- return value.to_dict() if value is not None else None
69
-
70
-
71
- _TranscriptionField = Annotated[
72
- Transcription,
73
- BeforeValidator(_build_validator(Transcription)),
74
- PlainSerializer(_serialize, return_type=dict, when_used="always"),
75
- ]
76
- _SceneDescriptionField = Annotated[
77
- SceneDescription,
78
- BeforeValidator(_build_validator(SceneDescription)),
79
- PlainSerializer(_serialize, return_type=dict, when_used="always"),
80
- ]
81
- _AudioClassificationField = Annotated[
82
- AudioClassification,
83
- BeforeValidator(_build_validator(AudioClassification)),
84
- PlainSerializer(_serialize, return_type=dict, when_used="always"),
85
- ]
86
-
87
-
88
- def _validate_face_tracks(value: Any) -> Any:
89
- if value is None:
90
- return None
91
- return [item if isinstance(item, FaceTrack) else FaceTrack.from_dict(item) for item in value]
92
-
93
-
94
- def _serialize_face_tracks(value: Any) -> Any:
95
- if value is None:
96
- return None
97
- return [track.to_dict() for track in value]
98
-
99
-
100
- _FaceTracksField = Annotated[
101
- list[FaceTrack],
102
- BeforeValidator(_validate_face_tracks),
103
- PlainSerializer(_serialize_face_tracks, return_type=list, when_used="always"),
104
- ]
105
-
106
-
107
54
  class GeoMetadata(BaseModel):
108
55
  """Optional geolocation metadata attached to a video container."""
109
56
 
@@ -206,9 +153,7 @@ class VideoAnalysisConfig(BaseModel):
206
153
  class AudioAnalysisSection(BaseModel):
207
154
  """Audio understanding outputs."""
208
155
 
209
- model_config = ConfigDict(arbitrary_types_allowed=True)
210
-
211
- transcription: _TranscriptionField | None = None
156
+ transcription: Transcription | None = None
212
157
 
213
158
 
214
159
  class SceneAnalysisSample(BaseModel):
@@ -220,16 +165,14 @@ class SceneAnalysisSample(BaseModel):
220
165
  trajectory internally.
221
166
  """
222
167
 
223
- model_config = ConfigDict(arbitrary_types_allowed=True)
224
-
225
168
  scene_index: int
226
169
  start_second: float
227
170
  end_second: float
228
171
  start_frame: int | None = None
229
172
  end_frame: int | None = None
230
- scene_description: _SceneDescriptionField | None = None
231
- audio_classification: _AudioClassificationField | None = None
232
- faces: _FaceTracksField | None = None
173
+ scene_description: SceneDescription | None = None
174
+ audio_classification: AudioClassification | None = None
175
+ faces: list[FaceTrack] | None = None
233
176
 
234
177
 
235
178
  class SceneAnalysisSection(BaseModel):
@@ -41,7 +41,7 @@ __all__ = [
41
41
  "draw_detections",
42
42
  "DetectionStyle",
43
43
  "class_color",
44
- # Transcription data classes
44
+ # Transcription result models
45
45
  "Transcription",
46
46
  "TranscriptionSegment",
47
47
  "TranscriptionWord",
@@ -1,8 +1,5 @@
1
1
  from __future__ import annotations
2
2
 
3
- from dataclasses import dataclass, field
4
- from typing import Any
5
-
6
3
  from pydantic import BaseModel, ConfigDict, Field
7
4
 
8
5
  __all__ = [
@@ -19,8 +16,11 @@ __all__ = [
19
16
  ]
20
17
 
21
18
 
22
- @dataclass
23
- class SceneBoundary:
19
+ class _ResultModel(BaseModel):
20
+ model_config = ConfigDict(extra="forbid")
21
+
22
+
23
+ class SceneBoundary(_ResultModel):
24
24
  """Timing information for a detected scene.
25
25
 
26
26
  A lightweight structure representing scene boundaries returned by
@@ -50,33 +50,14 @@ class SceneBoundary:
50
50
  """Number of frames in this scene."""
51
51
  return self.end_frame - self.start_frame
52
52
 
53
- def to_dict(self) -> dict[str, Any]:
54
- """Convert to dictionary for JSON serialization."""
55
- return {
56
- "start": self.start,
57
- "end": self.end,
58
- "start_frame": self.start_frame,
59
- "end_frame": self.end_frame,
60
- }
61
-
62
- @classmethod
63
- def from_dict(cls, data: dict[str, Any]) -> "SceneBoundary":
64
- """Create SceneBoundary from dictionary."""
65
- return cls(
66
- start=data["start"],
67
- end=data["end"],
68
- start_frame=data["start_frame"],
69
- end_frame=data["end_frame"],
70
- )
71
-
72
-
73
- class BoundingBox(BaseModel):
53
+
54
+ class BoundingBox(_ResultModel):
74
55
  """A bounding box for detected objects or crop regions in an image.
75
56
 
76
57
  Coordinates are normalized to ``[0, 1]`` relative to image dimensions.
77
- Promoted to a Pydantic model so it can be embedded directly into
78
- ``Operation`` fields (e.g. ``KenBurns.start_region``) and validated /
79
- serialised as part of an op's JSON wire format.
58
+ It can be embedded directly into ``Operation`` fields (for example,
59
+ ``KenBurns.start_region``) and validated as part of an operation's JSON
60
+ wire format.
80
61
  """
81
62
 
82
63
  model_config = ConfigDict(extra="forbid", frozen=True)
@@ -96,18 +77,8 @@ class BoundingBox(BaseModel):
96
77
  """Area of the bounding box (normalized)."""
97
78
  return self.width * self.height
98
79
 
99
- def to_dict(self) -> dict[str, Any]:
100
- """Backwards-compat alias for ``model_dump()``."""
101
- return self.model_dump()
102
-
103
- @classmethod
104
- def from_dict(cls, data: dict[str, Any]) -> BoundingBox:
105
- """Backwards-compat alias for ``model_validate(data)``."""
106
- return cls.model_validate(data)
107
80
 
108
-
109
- @dataclass
110
- class DetectedObject:
81
+ class DetectedObject(_ResultModel):
111
82
  """An object detected in a video frame.
112
83
 
113
84
  Attributes:
@@ -120,26 +91,8 @@ class DetectedObject:
120
91
  confidence: float
121
92
  bounding_box: BoundingBox | None = None
122
93
 
123
- def to_dict(self) -> dict[str, Any]:
124
- """Convert to dictionary for JSON serialization."""
125
- return {
126
- "label": self.label,
127
- "confidence": self.confidence,
128
- "bounding_box": self.bounding_box.to_dict() if self.bounding_box else None,
129
- }
130
-
131
- @classmethod
132
- def from_dict(cls, data: dict[str, Any]) -> DetectedObject:
133
- """Create DetectedObject from dictionary."""
134
- return cls(
135
- label=data["label"],
136
- confidence=data["confidence"],
137
- bounding_box=BoundingBox.from_dict(data["bounding_box"]) if data.get("bounding_box") else None,
138
- )
139
-
140
-
141
- @dataclass
142
- class DetectedFace:
94
+
95
+ class DetectedFace(_ResultModel):
143
96
  """A face detected in a video frame.
144
97
 
145
98
  Attributes:
@@ -161,24 +114,8 @@ class DetectedFace:
161
114
  """Area of the face bounding box (normalized), or None if no bounding box."""
162
115
  return self.bounding_box.area if self.bounding_box else None
163
116
 
164
- def to_dict(self) -> dict[str, Any]:
165
- """Convert to dictionary for JSON serialization."""
166
- return {
167
- "bounding_box": self.bounding_box.to_dict() if self.bounding_box else None,
168
- "confidence": self.confidence,
169
- }
170
-
171
- @classmethod
172
- def from_dict(cls, data: dict[str, Any]) -> DetectedFace:
173
- """Create DetectedFace from dictionary."""
174
- return cls(
175
- bounding_box=BoundingBox.from_dict(data["bounding_box"]) if data.get("bounding_box") else None,
176
- confidence=data.get("confidence", 1.0),
177
- )
178
-
179
117
 
180
- @dataclass
181
- class DetectedText:
118
+ class DetectedText(_ResultModel):
182
119
  """Text detected in a video frame.
183
120
 
184
121
  Attributes:
@@ -191,26 +128,8 @@ class DetectedText:
191
128
  confidence: float
192
129
  bounding_box: BoundingBox | None = None
193
130
 
194
- def to_dict(self) -> dict[str, Any]:
195
- """Convert to dictionary for JSON serialization."""
196
- return {
197
- "text": self.text,
198
- "confidence": self.confidence,
199
- "bounding_box": self.bounding_box.to_dict() if self.bounding_box else None,
200
- }
201
-
202
- @classmethod
203
- def from_dict(cls, data: dict[str, Any]) -> "DetectedText":
204
- """Create DetectedText from dictionary."""
205
- return cls(
206
- text=data["text"],
207
- confidence=data["confidence"],
208
- bounding_box=BoundingBox.from_dict(data["bounding_box"]) if data.get("bounding_box") else None,
209
- )
210
-
211
-
212
- @dataclass
213
- class AudioEvent:
131
+
132
+ class AudioEvent(_ResultModel):
214
133
  """A detected audio event with timestamp.
215
134
 
216
135
  Attributes:
@@ -230,28 +149,8 @@ class AudioEvent:
230
149
  """Duration of the audio event in seconds."""
231
150
  return self.end - self.start
232
151
 
233
- def to_dict(self) -> dict[str, Any]:
234
- """Convert to dictionary for JSON serialization."""
235
- return {
236
- "start": self.start,
237
- "end": self.end,
238
- "label": self.label,
239
- "confidence": self.confidence,
240
- }
241
-
242
- @classmethod
243
- def from_dict(cls, data: dict[str, Any]) -> AudioEvent:
244
- """Create AudioEvent from dictionary."""
245
- return cls(
246
- start=data["start"],
247
- end=data["end"],
248
- label=data["label"],
249
- confidence=data["confidence"],
250
- )
251
-
252
-
253
- @dataclass
254
- class AudioClassification:
152
+
153
+ class AudioClassification(_ResultModel):
255
154
  """Complete audio classification results.
256
155
 
257
156
  Attributes:
@@ -260,26 +159,10 @@ class AudioClassification:
260
159
  """
261
160
 
262
161
  events: list[AudioEvent]
263
- clip_predictions: dict[str, float] = field(default_factory=dict)
264
-
265
- def to_dict(self) -> dict[str, Any]:
266
- """Convert to dictionary for JSON serialization."""
267
- return {
268
- "events": [event.to_dict() for event in self.events],
269
- "clip_predictions": self.clip_predictions,
270
- }
271
-
272
- @classmethod
273
- def from_dict(cls, data: dict[str, Any]) -> "AudioClassification":
274
- """Create AudioClassification from dictionary."""
275
- return cls(
276
- events=[AudioEvent.from_dict(event) for event in data.get("events", [])],
277
- clip_predictions={k: float(v) for k, v in data.get("clip_predictions", {}).items()},
278
- )
279
-
280
-
281
- @dataclass
282
- class MotionInfo:
162
+ clip_predictions: dict[str, float] = Field(default_factory=dict)
163
+
164
+
165
+ class MotionInfo(_ResultModel):
283
166
  """Motion characteristics between consecutive frames.
284
167
 
285
168
  Attributes:
@@ -307,26 +190,8 @@ class MotionInfo:
307
190
  """Check if this frame has significant motion."""
308
191
  return self.motion_type != "static"
309
192
 
310
- def to_dict(self) -> dict[str, Any]:
311
- """Convert to dictionary for JSON serialization."""
312
- return {
313
- "motion_type": self.motion_type,
314
- "magnitude": self.magnitude,
315
- "raw_magnitude": self.raw_magnitude,
316
- }
317
-
318
- @classmethod
319
- def from_dict(cls, data: dict[str, Any]) -> MotionInfo:
320
- """Create MotionInfo from dictionary."""
321
- return cls(
322
- motion_type=data["motion_type"],
323
- magnitude=data["magnitude"],
324
- raw_magnitude=data["raw_magnitude"],
325
- )
326
-
327
-
328
- @dataclass
329
- class SceneDescription:
193
+
194
+ class SceneDescription(_ResultModel):
330
195
  """Structured visual scene description from the SceneVLM.
331
196
 
332
197
  The v1 schema is intentionally narrow (caption + subjects + shot_type).
@@ -342,27 +207,11 @@ class SceneDescription:
342
207
  """
343
208
 
344
209
  caption: str
345
- subjects: list[str] = field(default_factory=list)
210
+ subjects: list[str] = Field(default_factory=list)
346
211
  shot_type: str | None = None
347
212
 
348
- def to_dict(self) -> dict[str, Any]:
349
- return {
350
- "caption": self.caption,
351
- "subjects": list(self.subjects),
352
- "shot_type": self.shot_type,
353
- }
354
-
355
- @classmethod
356
- def from_dict(cls, data: dict[str, Any]) -> "SceneDescription":
357
- return cls(
358
- caption=str(data["caption"]),
359
- subjects=[str(s) for s in data.get("subjects", [])],
360
- shot_type=data.get("shot_type"),
361
- )
362
213
 
363
-
364
- @dataclass
365
- class FaceTrack:
214
+ class FaceTrack(_ResultModel):
366
215
  """A face tracked across consecutive frames within a single shot.
367
216
 
368
217
  Tracks are produced by IoU association — no embedding re-id, so a
@@ -380,26 +229,9 @@ class FaceTrack:
380
229
  track_id: int
381
230
  frame_indices: list[int]
382
231
  boxes: list[BoundingBox]
383
- confidences: list[float] = field(default_factory=list)
232
+ confidences: list[float] = Field(default_factory=list)
384
233
 
385
234
  @property
386
235
  def length(self) -> int:
387
236
  """Number of frames in this track."""
388
237
  return len(self.frame_indices)
389
-
390
- def to_dict(self) -> dict[str, Any]:
391
- return {
392
- "track_id": self.track_id,
393
- "frame_indices": list(self.frame_indices),
394
- "boxes": [box.to_dict() for box in self.boxes],
395
- "confidences": list(self.confidences),
396
- }
397
-
398
- @classmethod
399
- def from_dict(cls, data: dict[str, Any]) -> "FaceTrack":
400
- return cls(
401
- track_id=int(data["track_id"]),
402
- frame_indices=[int(i) for i in data.get("frame_indices", [])],
403
- boxes=[BoundingBox.from_dict(b) for b in data.get("boxes", [])],
404
- confidences=[float(c) for c in data.get("confidences", [])],
405
- )
@@ -1,9 +1,10 @@
1
1
  from __future__ import annotations
2
2
 
3
- from dataclasses import dataclass, replace
4
3
  from pathlib import Path
5
4
  from typing import Any
6
5
 
6
+ from pydantic import BaseModel, ConfigDict, PrivateAttr
7
+
7
8
  __all__ = ["Transcription", "TranscriptionSegment", "TranscriptionWord"]
8
9
 
9
10
  # Sentence-ending punctuation used by ``Transcription.capitalize_sentences``.
@@ -14,35 +15,18 @@ _SENTENCE_TERMINATORS = (".", "!", "?", "…")
14
15
  _TRAILING_WRAPPERS = "\"')]}»”’ "
15
16
 
16
17
 
17
- @dataclass
18
- class TranscriptionWord:
18
+ class TranscriptionWord(BaseModel):
19
+ model_config = ConfigDict(extra="forbid")
20
+
19
21
  start: float
20
22
  end: float
21
23
  word: str
22
24
  speaker: str | None = None
23
25
 
24
- def to_dict(self) -> dict[str, Any]:
25
- """Convert to dictionary for JSON serialization."""
26
- return {
27
- "start": self.start,
28
- "end": self.end,
29
- "word": self.word,
30
- "speaker": self.speaker,
31
- }
32
-
33
- @classmethod
34
- def from_dict(cls, data: dict[str, Any]) -> TranscriptionWord:
35
- """Create TranscriptionWord from dictionary."""
36
- return cls(
37
- start=data["start"],
38
- end=data["end"],
39
- word=data["word"],
40
- speaker=data.get("speaker"),
41
- )
42
26
 
27
+ class TranscriptionSegment(BaseModel):
28
+ model_config = ConfigDict(extra="forbid")
43
29
 
44
- @dataclass
45
- class TranscriptionSegment:
46
30
  start: float
47
31
  end: float
48
32
  text: str
@@ -52,33 +36,6 @@ class TranscriptionSegment:
52
36
  no_speech_prob: float | None = None
53
37
  compression_ratio: float | None = None
54
38
 
55
- def to_dict(self) -> dict[str, Any]:
56
- """Convert to dictionary for JSON serialization."""
57
- return {
58
- "start": self.start,
59
- "end": self.end,
60
- "text": self.text,
61
- "words": [w.to_dict() for w in self.words],
62
- "speaker": self.speaker,
63
- "avg_logprob": self.avg_logprob,
64
- "no_speech_prob": self.no_speech_prob,
65
- "compression_ratio": self.compression_ratio,
66
- }
67
-
68
- @classmethod
69
- def from_dict(cls, data: dict[str, Any]) -> TranscriptionSegment:
70
- """Create TranscriptionSegment from dictionary."""
71
- return cls(
72
- start=data["start"],
73
- end=data["end"],
74
- text=data["text"],
75
- words=[TranscriptionWord.from_dict(w) for w in data["words"]],
76
- speaker=data.get("speaker"),
77
- avg_logprob=data.get("avg_logprob"),
78
- no_speech_prob=data.get("no_speech_prob"),
79
- compression_ratio=data.get("compression_ratio"),
80
- )
81
-
82
39
  @classmethod
83
40
  def from_words(
84
41
  cls,
@@ -112,35 +69,42 @@ class TranscriptionSegment:
112
69
  )
113
70
 
114
71
 
115
- class Transcription:
72
+ class Transcription(BaseModel):
73
+ """A timed transcription grouped into segments.
74
+
75
+ Construct it with exactly one of ``segments`` or ``words``. The ``words``
76
+ form groups adjacent words by speaker.
77
+
78
+ Raises:
79
+ ValueError: If both ``segments`` and ``words`` are set, or neither is set.
80
+ """
81
+
82
+ model_config = ConfigDict(extra="forbid")
83
+
84
+ _speakers: set[str] = PrivateAttr(default_factory=set)
85
+
86
+ segments: list[TranscriptionSegment]
87
+ language: str | None = None
88
+
116
89
  def __init__(
117
90
  self,
91
+ *,
118
92
  segments: list[TranscriptionSegment] | None = None,
119
93
  words: list[TranscriptionWord] | None = None,
120
94
  language: str | None = None,
121
- ):
122
- """Initialize Transcription from either segments or words.
123
-
124
- Args:
125
- segments: Pre-constructed segments (backward compatible)
126
- words: Words to group into segments by speaker (for diarization)
127
- language: ISO 639-1 language code detected during transcription (e.g. "en", "pl")
128
-
129
- Raises:
130
- ValueError: If both or neither arguments are provided
131
- """
132
- if (segments is None) == (words is None):
95
+ **data: Any,
96
+ ) -> None:
97
+ if segments is not None and words is not None:
133
98
  raise ValueError("Exactly one of 'segments' or 'words' must be provided")
134
-
135
- self.language = language
136
-
137
99
  if segments is not None:
138
- self.segments = segments
139
- self.speakers = {s.speaker for s in segments if s.speaker is not None}
100
+ resolved_segments = segments
101
+ elif words is not None:
102
+ resolved_segments = self._words_to_segments(words)
140
103
  else:
141
- assert words is not None
142
- self.segments = self._words_to_segments(words)
143
- self.speakers = {w.speaker for w in words if w.speaker is not None}
104
+ raise ValueError("Exactly one of 'segments' or 'words' must be provided")
105
+
106
+ super().__init__(segments=resolved_segments, language=language, **data)
107
+ self._speakers = {segment.speaker for segment in self.segments if segment.speaker is not None}
144
108
 
145
109
  @property
146
110
  def words(self) -> list[TranscriptionWord]:
@@ -150,7 +114,17 @@ class Transcription:
150
114
  all_words.extend(segment.words)
151
115
  return all_words
152
116
 
153
- def _words_to_segments(self, words: list[TranscriptionWord]) -> list[TranscriptionSegment]:
117
+ @property
118
+ def speakers(self) -> set[str]:
119
+ """Return the stored speaker identifiers."""
120
+ return self._speakers
121
+
122
+ @speakers.setter
123
+ def speakers(self, value: set[str]) -> None:
124
+ self._speakers = value
125
+
126
+ @staticmethod
127
+ def _words_to_segments(words: list[TranscriptionWord]) -> list[TranscriptionSegment]:
154
128
  """Group words into segments based on speaker changes."""
155
129
  if not words:
156
130
  return []
@@ -206,10 +180,10 @@ class Transcription:
206
180
  TranscriptionWord(start=w.start + time, end=w.end + time, word=w.word, speaker=w.speaker)
207
181
  for w in segment.words
208
182
  ]
209
- # ``replace`` carries text, speaker, and confidence fields through a
210
- # pure timing shift unchanged -- only timestamps move.
211
183
  offset_segments.append(
212
- replace(segment, start=segment.start + time, end=segment.end + time, words=offset_words)
184
+ segment.model_copy(
185
+ update={"start": segment.start + time, "end": segment.end + time, "words": offset_words}
186
+ )
213
187
  )
214
188
 
215
189
  return Transcription(segments=offset_segments, language=self.language)
@@ -312,9 +286,9 @@ class Transcription:
312
286
  start_of_sentence = True
313
287
  new_words.append(TranscriptionWord(start=word.start, end=word.end, word=token, speaker=word.speaker))
314
288
 
315
- # Casing-only rewrite: segment boundaries, speaker, and confidence
316
- # are unchanged; only the tokens (and joined text) differ.
317
- capitalized_segments.append(replace(segment, text=" ".join(w.word for w in new_words), words=new_words))
289
+ capitalized_segments.append(
290
+ segment.model_copy(update={"text": " ".join(w.word for w in new_words), "words": new_words})
291
+ )
318
292
 
319
293
  return Transcription(segments=capitalized_segments, language=self.language)
320
294
 
@@ -341,9 +315,7 @@ class Transcription:
341
315
  for segment in self.segments:
342
316
  words = segment.words
343
317
  if not words:
344
- # Nothing to split; emit a fresh copy so the result never
345
- # aliases the source segment.
346
- chunked_segments.append(replace(segment, words=list(segment.words)))
318
+ chunked_segments.append(segment.model_copy(update={"words": list(segment.words)}))
347
319
  continue
348
320
  for i in range(0, len(words), max_words):
349
321
  group = words[i : i + max_words]
@@ -476,18 +448,3 @@ class Transcription:
476
448
  path: Output file path.
477
449
  """
478
450
  Path(path).write_text(self.to_srt(), encoding="utf-8")
479
-
480
- def to_dict(self) -> dict[str, Any]:
481
- """Convert to dictionary for JSON serialization."""
482
- return {
483
- "segments": [s.to_dict() for s in self.segments],
484
- "language": self.language,
485
- }
486
-
487
- @classmethod
488
- def from_dict(cls, data: dict[str, Any]) -> Transcription:
489
- """Create Transcription from dictionary."""
490
- return cls(
491
- segments=[TranscriptionSegment.from_dict(s) for s in data["segments"]],
492
- language=data.get("language"),
493
- )
File without changes
File without changes
File without changes