@clipen/clipen-cli 0.0.0-stage → 1.0.0
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.
- package/LICENSE +21 -0
- package/README.md +79 -2
- package/apps/web/dist/assets/index-D5D2HiB1.js +14 -0
- package/apps/web/dist/assets/index-DIMuOXSu.css +1 -0
- package/apps/web/dist/favicon.svg +1 -0
- package/apps/web/dist/index.html +16 -0
- package/bin/clipen.js +157 -0
- package/clipen +18 -0
- package/install +25 -0
- package/package.json +52 -4
- package/pyproject.toml +28 -0
- package/requirements/asr-runtime.txt +13 -0
- package/requirements/runtime.txt +20 -0
- package/src/clipen/__init__.py +3 -0
- package/src/clipen/analysis/__init__.py +89 -0
- package/src/clipen/analysis/artifacts.py +416 -0
- package/src/clipen/analysis/audio.py +392 -0
- package/src/clipen/analysis/evidence.py +102 -0
- package/src/clipen/analysis/evidence_service.py +751 -0
- package/src/clipen/analysis/image_similarity.py +143 -0
- package/src/clipen/analysis/keyframes.py +171 -0
- package/src/clipen/analysis/models.py +230 -0
- package/src/clipen/analysis/qwen_worker.py +629 -0
- package/src/clipen/analysis/resources.py +21 -0
- package/src/clipen/analysis/runtime.py +64 -0
- package/src/clipen/analysis/service.py +626 -0
- package/src/clipen/analysis/setup.py +935 -0
- package/src/clipen/analysis/setup_cli.py +117 -0
- package/src/clipen/analysis/storage.py +2046 -0
- package/src/clipen/analysis/transcription.py +948 -0
- package/src/clipen/analysis/visual.py +176 -0
- package/src/clipen/annotations/__init__.py +10 -0
- package/src/clipen/annotations/models.py +22 -0
- package/src/clipen/annotations/storage.py +380 -0
- package/src/clipen/annotations/suggestions.py +120 -0
- package/src/clipen/asr_release.py +139 -0
- package/src/clipen/bootstrap.py +967 -0
- package/src/clipen/cli.py +84 -0
- package/src/clipen/controller/__init__.py +17 -0
- package/src/clipen/controller/app.py +1470 -0
- package/src/clipen/controller/server.py +543 -0
- package/src/clipen/domain/__init__.py +30 -0
- package/src/clipen/domain/errors.py +5 -0
- package/src/clipen/domain/media_time.py +117 -0
- package/src/clipen/domain/timeline.py +584 -0
- package/src/clipen/domain/validation.py +15 -0
- package/src/clipen/editing/EDITORIAL_REGRESSIONS.md +38 -0
- package/src/clipen/editing/PROGRAM_FORMAT.md +102 -0
- package/src/clipen/editing/README.md +115 -0
- package/src/clipen/editing/REFACTOR_DESIGN.md +241 -0
- package/src/clipen/editing/REFACTOR_HANDOFF.md +73 -0
- package/src/clipen/editing/__init__.py +15 -0
- package/src/clipen/editing/agent.py +13 -0
- package/src/clipen/editing/agent_models.py +134 -0
- package/src/clipen/editing/agent_repository.py +757 -0
- package/src/clipen/editing/agent_tools.py +532 -0
- package/src/clipen/editing/alignment.py +110 -0
- package/src/clipen/editing/alignment_setup.py +108 -0
- package/src/clipen/editing/alignment_worker.py +22 -0
- package/src/clipen/editing/change_report.py +71 -0
- package/src/clipen/editing/compiler.py +41 -0
- package/src/clipen/editing/component_looks.py +107 -0
- package/src/clipen/editing/component_review.py +78 -0
- package/src/clipen/editing/coordinator.py +374 -0
- package/src/clipen/editing/editorial_review.py +187 -0
- package/src/clipen/editing/evidence_jobs.py +295 -0
- package/src/clipen/editing/history_changes.py +131 -0
- package/src/clipen/editing/music_choices.py +15 -0
- package/src/clipen/editing/production_catalog.py +192 -0
- package/src/clipen/editing/production_limits.py +59 -0
- package/src/clipen/editing/production_media.py +226 -0
- package/src/clipen/editing/production_preview.py +180 -0
- package/src/clipen/editing/production_progress.py +141 -0
- package/src/clipen/editing/production_requirements.py +50 -0
- package/src/clipen/editing/production_tools.py +596 -0
- package/src/clipen/editing/program_audio.py +118 -0
- package/src/clipen/editing/program_direction.py +49 -0
- package/src/clipen/editing/program_story.py +53 -0
- package/src/clipen/editing/program_subtitles.py +134 -0
- package/src/clipen/editing/programme_review.py +73 -0
- package/src/clipen/editing/prompt_history.py +47 -0
- package/src/clipen/editing/recut.py +127 -0
- package/src/clipen/editing/refinement_references.py +188 -0
- package/src/clipen/editing/resolve_export.py +616 -0
- package/src/clipen/editing/resolve_titles.py +234 -0
- package/src/clipen/editing/skill_tools.py +575 -0
- package/src/clipen/editing/source_dialogue.py +82 -0
- package/src/clipen/editing/speech_coverage.py +30 -0
- package/src/clipen/editing/speech_quality.py +6 -0
- package/src/clipen/editing/tool_receipts.py +52 -0
- package/src/clipen/editing/versions.py +161 -0
- package/src/clipen/editing/visual_preview.py +93 -0
- package/src/clipen/editing/workbench.py +74 -0
- package/src/clipen/filesystem.py +25 -0
- package/src/clipen/finishing/README.md +103 -0
- package/src/clipen/finishing/__init__.py +1 -0
- package/src/clipen/finishing/audio.py +149 -0
- package/src/clipen/finishing/catalog.py +181 -0
- package/src/clipen/finishing/models.py +14 -0
- package/src/clipen/finishing/renderer.py +26 -0
- package/src/clipen/mcp_editing/__init__.py +5 -0
- package/src/clipen/mcp_editing/__main__.py +40 -0
- package/src/clipen/mcp_editing/server.py +353 -0
- package/src/clipen/media/__init__.py +50 -0
- package/src/clipen/media/discovery.py +266 -0
- package/src/clipen/media/models.py +360 -0
- package/src/clipen/media/preview.py +147 -0
- package/src/clipen/media/probe.py +446 -0
- package/src/clipen/media/service.py +317 -0
- package/src/clipen/media/storage.py +742 -0
- package/src/clipen/music_vocabulary.py +5 -0
- package/src/clipen/planning/__init__.py +9 -0
- package/src/clipen/planning/models.py +240 -0
- package/src/clipen/power.py +23 -0
- package/src/clipen/projects/__init__.py +26 -0
- package/src/clipen/projects/agent_schema.py +94 -0
- package/src/clipen/projects/annotation_schema.py +40 -0
- package/src/clipen/projects/deletion.py +269 -0
- package/src/clipen/projects/evidence_schema.py +52 -0
- package/src/clipen/projects/finishing_schema.py +34 -0
- package/src/clipen/projects/models.py +192 -0
- package/src/clipen/projects/picker.py +256 -0
- package/src/clipen/projects/preview_schema.py +29 -0
- package/src/clipen/projects/service.py +175 -0
- package/src/clipen/projects/storage.py +1478 -0
- package/src/clipen/projects/timeline_schema.py +32 -0
- package/src/clipen/projects/validation_schema.py +28 -0
- package/src/clipen/provider_registry.py +75 -0
- package/src/clipen/providers/__init__.py +43 -0
- package/src/clipen/providers/account.py +194 -0
- package/src/clipen/providers/claude.py +375 -0
- package/src/clipen/providers/claude_editing.py +111 -0
- package/src/clipen/providers/codex.py +1036 -0
- package/src/clipen/providers/codex_editing.py +91 -0
- package/src/clipen/providers/editing_agent.py +565 -0
- package/src/clipen/providers/errors.py +51 -0
- package/src/clipen/providers/recovery.py +270 -0
- package/src/clipen/py.typed +1 -0
- package/src/clipen/rendering/__init__.py +12 -0
- package/src/clipen/rendering/cover.py +126 -0
- package/src/clipen/rendering/custom_components.py +240 -0
- package/src/clipen/rendering/custom_render.py +197 -0
- package/src/clipen/rendering/fonts/anton-OFL.txt +93 -0
- package/src/clipen/rendering/fonts/bebasneue-OFL.txt +93 -0
- package/src/clipen/rendering/fonts/caveat-OFL.txt +93 -0
- package/src/clipen/rendering/fonts/chenyu-OFL.txt +93 -0
- package/src/clipen/rendering/fonts/delagothicone-OFL.txt +93 -0
- package/src/clipen/rendering/fonts/hachimarupop-OFL.txt +93 -0
- package/src/clipen/rendering/fonts/iansui-OFL.txt +93 -0
- package/src/clipen/rendering/fonts/manifest.json +145 -0
- package/src/clipen/rendering/fonts/playfairdisplay-OFL.txt +93 -0
- package/src/clipen/rendering/fonts/rocknrollone-OFL.txt +93 -0
- package/src/clipen/rendering/fonts/yomogi-OFL.txt +94 -0
- package/src/clipen/rendering/fonts/yuseimagic-OFL.txt +93 -0
- package/src/clipen/rendering/fonts/zenkurenaido-OFL.txt +93 -0
- package/src/clipen/rendering/fonts/zenmarugothic-OFL.txt +93 -0
- package/src/clipen/rendering/production_effects.py +64 -0
- package/src/clipen/rendering/program_components.py +193 -0
- package/src/clipen/rendering/program_creator.py +649 -0
- package/src/clipen/rendering/program_identities.py +255 -0
- package/src/clipen/rendering/program_motion.py +141 -0
- package/src/clipen/rendering/program_studio.py +168 -0
- package/src/clipen/rendering/program_styles.py +235 -0
- package/src/clipen/rendering/program_subtitles.py +52 -0
- package/src/clipen/rendering/renderer.py +708 -0
- package/src/clipen/rendering/storage.py +243 -0
- package/src/clipen/rendering/titles.py +360 -0
- package/src/clipen/skills/__init__.py +4 -0
- package/src/clipen/skills/builtin/SKILL.md +72 -0
- package/src/clipen/skills/builtin/assets/sample-daily-vlog.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-event-recap.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-food-review.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-product-demo.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-product-review.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-product-unboxing.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-shorts-highlight.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-travel-highlight.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-travel-vlog.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/style-cinema.png +0 -0
- package/src/clipen/skills/builtin/assets/style-editorial.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-daily-vlog.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-event-recap.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-food-review.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-product-demo.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-product-review.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-product-unboxing.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-shorts-highlight.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-travel-highlight.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-travel-vlog.png +0 -0
- package/src/clipen/skills/builtin/assets/style-variety.png +0 -0
- package/src/clipen/skills/builtin/components.json +133 -0
- package/src/clipen/skills/builtin/font_sources.json +20 -0
- package/src/clipen/skills/builtin/font_styles.json +329 -0
- package/src/clipen/skills/builtin/manifest.json +32 -0
- package/src/clipen/skills/builtin/presets.json +8 -0
- package/src/clipen/skills/builtin/references/captions.md +14 -0
- package/src/clipen/skills/builtin/references/channel-design.md +37 -0
- package/src/clipen/skills/builtin/references/editing.md +30 -0
- package/src/clipen/skills/builtin/references/font-chenyu-OFL.txt +93 -0
- package/src/clipen/skills/builtin/references/font-iansui-OFL.txt +93 -0
- package/src/clipen/skills/builtin/references/graphics.md +59 -0
- package/src/clipen/skills/builtin/references/review.md +16 -0
- package/src/clipen/skills/builtin/references/sound.md +8 -0
- package/src/clipen/skills/builtin/references/story.md +7 -0
- package/src/clipen/skills/builtin/skills/travel-program/SKILL.md +27 -0
- package/src/clipen/skills/builtin/skills/travel-program/manifest.json +6 -0
- package/src/clipen/skills/builtin/template-skills/clipen-daily-vlog/SKILL.md +33 -0
- package/src/clipen/skills/builtin/template-skills/clipen-daily-vlog/manifest.json +8 -0
- package/src/clipen/skills/builtin/template-skills/clipen-event-recap/SKILL.md +34 -0
- package/src/clipen/skills/builtin/template-skills/clipen-event-recap/manifest.json +8 -0
- package/src/clipen/skills/builtin/template-skills/clipen-food-review/SKILL.md +33 -0
- package/src/clipen/skills/builtin/template-skills/clipen-food-review/manifest.json +8 -0
- package/src/clipen/skills/builtin/template-skills/clipen-product-demo/SKILL.md +35 -0
- package/src/clipen/skills/builtin/template-skills/clipen-product-demo/manifest.json +8 -0
- package/src/clipen/skills/builtin/template-skills/clipen-product-review/SKILL.md +36 -0
- package/src/clipen/skills/builtin/template-skills/clipen-product-review/manifest.json +8 -0
- package/src/clipen/skills/builtin/template-skills/clipen-product-unboxing/SKILL.md +39 -0
- package/src/clipen/skills/builtin/template-skills/clipen-product-unboxing/manifest.json +8 -0
- package/src/clipen/skills/builtin/template-skills/clipen-shorts-highlight/SKILL.md +38 -0
- package/src/clipen/skills/builtin/template-skills/clipen-shorts-highlight/manifest.json +8 -0
- package/src/clipen/skills/builtin/template-skills/clipen-travel-highlight/SKILL.md +34 -0
- package/src/clipen/skills/builtin/template-skills/clipen-travel-highlight/manifest.json +8 -0
- package/src/clipen/skills/builtin/template-skills/clipen-travel-vlog/SKILL.md +37 -0
- package/src/clipen/skills/builtin/template-skills/clipen-travel-vlog/manifest.json +8 -0
- package/src/clipen/skills/builtin/templates.json +284 -0
- package/src/clipen/skills/builtin/visual_styles.json +1074 -0
- package/src/clipen/skills/catalog.py +218 -0
- package/src/clipen/skills/library.py +131 -0
- package/src/clipen/skills/package.py +231 -0
- package/src/clipen/skills/visual_styles.py +44 -0
- package/src/clipen/workspace.py +210 -0
- package/uninstall +25 -0
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
"""On-demand local source speech jobs, independent of the legacy preparation stage."""
|
|
2
|
+
from fractions import Fraction
|
|
3
|
+
import json
|
|
4
|
+
import hashlib
|
|
5
|
+
import math
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
import threading
|
|
8
|
+
import time
|
|
9
|
+
import wave
|
|
10
|
+
|
|
11
|
+
from clipen.domain import TrackKind
|
|
12
|
+
from clipen.projects import ProjectError
|
|
13
|
+
from clipen.projects.storage import utc_now
|
|
14
|
+
from .agent_models import ToolResult, encoded, make_id
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class EvidenceTools:
|
|
18
|
+
def _production_prepare_local_speech(self,args):
|
|
19
|
+
session=self._session_value()
|
|
20
|
+
if not session['intent'].get('allow_local_model_downloads'):
|
|
21
|
+
raise ProjectError('local_model_grant_required','這次製作尚未授權準備本機模型。',status_code=409)
|
|
22
|
+
return self._start_evidence('setup',{'target':args['target'],'release':'clipen-local-speech-v1'},None)
|
|
23
|
+
|
|
24
|
+
def _production_transcribe_source_range(self, args):
|
|
25
|
+
candidate = self._candidate(args['candidate_id'])
|
|
26
|
+
span = candidate.source
|
|
27
|
+
duration = float(span.duration_pts*Fraction(span.time_base.numerator,span.time_base.denominator))
|
|
28
|
+
if duration>60:
|
|
29
|
+
raise ProjectError('speech_range_too_large', '單次按需語音分析最多 60 秒,請縮小來源範圍。', status_code=422)
|
|
30
|
+
binding = getattr(self, 'transcriber_binding', None)
|
|
31
|
+
if binding is None or (runtime:=binding()) is None:
|
|
32
|
+
raise ProjectError('asr_unavailable', '本機語音辨識尚未就緒,請先安裝或修復本機語音環境。', status_code=409)
|
|
33
|
+
request = {'source':span.to_storage(), 'language':args.get('language','zh'),
|
|
34
|
+
'align_words':args.get('align_words',True), 'model':runtime[1]}
|
|
35
|
+
if request['align_words']:
|
|
36
|
+
from .alignment import REVISION
|
|
37
|
+
request['alignment_revision']=REVISION
|
|
38
|
+
return self._start_evidence('transcribe', request, runtime[0])
|
|
39
|
+
|
|
40
|
+
def _production_align_source_speech(self, args):
|
|
41
|
+
job = self._evidence_job(args['transcript_job_id'])
|
|
42
|
+
if job['state']!='succeeded' or job['kind']!='transcribe':
|
|
43
|
+
raise ProjectError('transcript_job_required', '請指定已完成的來源轉寫工作。', status_code=422)
|
|
44
|
+
from .alignment import REVISION
|
|
45
|
+
request = {**job['request'], 'transcript_job_id':job['job_id'], 'alignment_revision':REVISION}
|
|
46
|
+
return self._start_evidence('align', request, None)
|
|
47
|
+
|
|
48
|
+
def _production_retry_evidence_job(self,args):
|
|
49
|
+
job=self._evidence_job(args['job_id'])
|
|
50
|
+
if job['state'] not in {'failed','cancelled','interrupted'}:
|
|
51
|
+
raise ProjectError('evidence_retry_invalid','只能重試已失敗、取消或中斷的本機工作。',status_code=409)
|
|
52
|
+
request={**job['request'],'retry_request_id':args['request_id']}
|
|
53
|
+
factory=None
|
|
54
|
+
if job['kind']=='transcribe':
|
|
55
|
+
binding=getattr(self,'transcriber_binding',None)
|
|
56
|
+
runtime=binding() if binding else None
|
|
57
|
+
if runtime is None:raise ProjectError('asr_unavailable','請先準備本機語音環境。',status_code=409)
|
|
58
|
+
factory=runtime[0];request['model']=runtime[1]
|
|
59
|
+
return self._start_evidence(job['kind'],request,factory)
|
|
60
|
+
|
|
61
|
+
def _production_revise_source_speech(self,args):
|
|
62
|
+
job=self._evidence_job(args['transcript_job_id'])
|
|
63
|
+
if job['state']!='succeeded' or job['kind'] not in {'transcribe','align'}:
|
|
64
|
+
raise ProjectError('transcript_job_required','請指定已完成的來源口語工作。',status_code=422)
|
|
65
|
+
index=args['segment_ordinal']
|
|
66
|
+
if index>=len(job['result']['segments']):
|
|
67
|
+
raise ProjectError('speech_segment_missing','指定口語段落不存在。',status_code=422)
|
|
68
|
+
from .alignment import REVISION
|
|
69
|
+
request={**job['request'],'transcript_job_id':job['job_id'],'alignment_revision':REVISION,
|
|
70
|
+
'correction':{key:args[key] for key in ('segment_ordinal','text','evidence')}}
|
|
71
|
+
return self._start_evidence('align',request,None)
|
|
72
|
+
|
|
73
|
+
def _evidence_job(self, job_id):
|
|
74
|
+
with self.repository.projects.connect(self.project_id) as db:
|
|
75
|
+
row = db.execute('SELECT * FROM production_evidence_jobs WHERE job_id=? AND run_id=?', (job_id,self.run_id)).fetchone()
|
|
76
|
+
if row is None:
|
|
77
|
+
raise ProjectError('evidence_job_not_found','證據工作不屬於這次製作。',status_code=404)
|
|
78
|
+
return {'job_id':row['job_id'], 'kind':row['kind'], 'state':row['state'],
|
|
79
|
+
'request':json.loads(row['request_json']), 'result':json.loads(row['result_json']) if row['result_json'] else None,
|
|
80
|
+
'error_code':row['error_code']}
|
|
81
|
+
|
|
82
|
+
def _start_evidence(self, kind, request, factory):
|
|
83
|
+
from clipen.analysis import transcription
|
|
84
|
+
recipe=hashlib.sha256()
|
|
85
|
+
for path in (Path(__file__),Path(__file__).with_name('alignment.py'),Path(__file__).with_name('alignment_worker.py'),
|
|
86
|
+
Path(transcription.__file__),Path(transcription.__file__).with_name('qwen_worker.py')):
|
|
87
|
+
recipe.update(path.read_bytes())
|
|
88
|
+
key = make_id('evidence_', [kind,request,recipe.hexdigest()])
|
|
89
|
+
identifier = make_id('speech_', [self.run_id,key])
|
|
90
|
+
with self.repository.projects.connect(self.project_id) as db:
|
|
91
|
+
db.execute('BEGIN IMMEDIATE')
|
|
92
|
+
existing = db.execute('SELECT job_id FROM production_evidence_jobs WHERE run_id=? AND cache_key=?', (self.run_id,key)).fetchone()
|
|
93
|
+
if existing:
|
|
94
|
+
db.rollback()
|
|
95
|
+
return ToolResult({'job':self._evidence_job(existing['job_id']), 'reused':True})
|
|
96
|
+
cached=db.execute("SELECT job_id,run_id,result_json FROM production_evidence_jobs WHERE cache_key=? AND state='succeeded' AND kind!='setup' ORDER BY rowid DESC LIMIT 1",(key,)).fetchone()
|
|
97
|
+
if cached is not None:
|
|
98
|
+
result={**json.loads(cached['result_json']),'cache_provenance':{'job_id':cached['job_id'],'run_id':cached['run_id']}}
|
|
99
|
+
db.execute('INSERT INTO production_evidence_jobs VALUES(?,?,?,?,?,?,?,?,?)',
|
|
100
|
+
(identifier,self.run_id,key,kind,'succeeded',encoded(request),encoded(result),None,utc_now()))
|
|
101
|
+
db.commit()
|
|
102
|
+
return ToolResult({'job':self._evidence_job(identifier),'reused':True})
|
|
103
|
+
if db.execute("SELECT 1 FROM production_evidence_jobs WHERE run_id=? AND state='running'", (self.run_id,)).fetchone():
|
|
104
|
+
raise ProjectError('evidence_busy', '已有本機語音工作執行中,請先讀取或取消。', status_code=409)
|
|
105
|
+
db.execute('INSERT INTO production_evidence_jobs VALUES(?,?,?,?,?,?,?,?,?)',
|
|
106
|
+
(identifier,self.run_id,key,kind,'running',encoded(request),None,None,utc_now()))
|
|
107
|
+
db.commit()
|
|
108
|
+
cancel = threading.Event()
|
|
109
|
+
if not hasattr(self,'_evidence_jobs'):self._evidence_jobs={}
|
|
110
|
+
worker = threading.Thread(target=self._run_evidence,args=(identifier,factory,cancel),daemon=True,name='clipen-source-speech')
|
|
111
|
+
self._evidence_jobs[identifier]=(cancel,worker)
|
|
112
|
+
worker.start()
|
|
113
|
+
return ToolResult({'job':self._evidence_job(identifier),'reused':False})
|
|
114
|
+
|
|
115
|
+
def _run_evidence(self, identifier, factory, cancel):
|
|
116
|
+
transcriber = None
|
|
117
|
+
try:
|
|
118
|
+
from clipen.analysis.audio import PreparedAudio
|
|
119
|
+
from clipen.media import MediaPreviewRepository
|
|
120
|
+
from clipen.finishing.audio import run_process
|
|
121
|
+
from .alignment import REVISION, run_alignment, validate_alignment
|
|
122
|
+
job = self._evidence_job(identifier)
|
|
123
|
+
if job['kind']=='setup':
|
|
124
|
+
def progress(value):
|
|
125
|
+
with self.repository.projects.connect(self.project_id) as db:
|
|
126
|
+
db.execute("UPDATE production_evidence_jobs SET result_json=? WHERE job_id=? AND state='running'",(encoded(value),identifier))
|
|
127
|
+
if job['request']['target']=='alignment':
|
|
128
|
+
from .alignment_setup import install_runtime
|
|
129
|
+
result=install_runtime(getattr(self,'local_data_root',None),cancel,progress)
|
|
130
|
+
else:
|
|
131
|
+
setup=getattr(self,'asr_setup_manager',None)
|
|
132
|
+
if setup is None:raise ProjectError('asr_unavailable','語音環境尚未設定。',status_code=409)
|
|
133
|
+
from clipen.asr_release import NOTICE_VERSION
|
|
134
|
+
setup.start_install(NOTICE_VERSION)
|
|
135
|
+
while setup.status().state.value=='installing':
|
|
136
|
+
if cancel.wait(.5):
|
|
137
|
+
setup.cancel_install()
|
|
138
|
+
raise ProjectError('user_cancelled','已取消本機語音環境準備。',status_code=409)
|
|
139
|
+
if setup.status().state.value!='ready':raise ProjectError('asr_setup_failed','本機語音環境準備失敗。',status_code=409)
|
|
140
|
+
result={'ready':True,'target':'transcription'}
|
|
141
|
+
with self.repository.projects.connect(self.project_id) as db:
|
|
142
|
+
db.execute("UPDATE production_evidence_jobs SET state='succeeded',result_json=? WHERE job_id=? AND state='running'",(encoded(result),identifier))
|
|
143
|
+
return
|
|
144
|
+
request = job['request'];span=request['source']
|
|
145
|
+
unit=Fraction(span['time_base']['num'],span['time_base']['den'])
|
|
146
|
+
start=float(int(span['start_pts'])*unit);duration=float((int(span['end_pts'])-int(span['start_pts']))*unit)
|
|
147
|
+
directory=self._workdir('evidence')/identifier
|
|
148
|
+
directory.mkdir(mode=0o700,exist_ok=True)
|
|
149
|
+
audio=directory/'source.wav'
|
|
150
|
+
media=(getattr(self,'media',None) or MediaPreviewRepository(self.repository.projects)).open(self.project_id,span['version_id'])
|
|
151
|
+
try:
|
|
152
|
+
if not media.audio_stream_indices:
|
|
153
|
+
raise ProjectError('source_audio_missing','指定素材沒有音訊。',status_code=422)
|
|
154
|
+
stream=span['stream_index'] if span['stream_index'] in media.audio_stream_indices else media.audio_stream_indices[0]
|
|
155
|
+
run_process(['ffmpeg','-v','error','-nostdin','-y','-seek_timestamp','1','-ss',str(start),'-i',f'/dev/fd/{media.descriptor}',
|
|
156
|
+
'-map',f'0:{stream}','-t',str(duration),'-ac','1','-ar','16000','-c:a','pcm_s16le',str(audio)],
|
|
157
|
+
cancel,pass_fds=(media.descriptor,),timeout=90)
|
|
158
|
+
finally:media.close()
|
|
159
|
+
with wave.open(str(audio),'rb') as wav:
|
|
160
|
+
prepared=PreparedAudio(audio,wav.getframerate(),wav.getnchannels(),wav.getsampwidth(),wav.getnframes())
|
|
161
|
+
if job['kind']=='transcribe':
|
|
162
|
+
transcriber=factory()
|
|
163
|
+
transcript_output=directory/'transcript.json'
|
|
164
|
+
transcript_output.touch(mode=0o600,exist_ok=False)
|
|
165
|
+
result=transcriber.transcribe(prepared,transcript_output,language=request['language'],cancel=cancel)
|
|
166
|
+
segments=[{'text':seg.text,'start_seconds':seg.start_sample/16000,
|
|
167
|
+
'end_seconds':seg.end_sample/16000} for seg in result.segments]
|
|
168
|
+
else:
|
|
169
|
+
segments=self._evidence_job(request['transcript_job_id'])['result']['segments']
|
|
170
|
+
correction=request.get('correction')
|
|
171
|
+
if correction:
|
|
172
|
+
segment=segments[correction['segment_ordinal']]
|
|
173
|
+
segment.update({'source_asr_text':segment.get('source_asr_text',segment['text']),
|
|
174
|
+
'text':correction['text'],'wording_authority':'model_proposed_correction',
|
|
175
|
+
'correction_evidence':correction['evidence']})
|
|
176
|
+
segment.pop('words',None)
|
|
177
|
+
alignment_error=None
|
|
178
|
+
if job['kind']=='align' or request.get('align_words'):
|
|
179
|
+
for index,segment in enumerate(segments):
|
|
180
|
+
if job['kind']=='align' and request.get('correction') and index!=request['correction']['segment_ordinal']:continue
|
|
181
|
+
if not segment['text'].strip():continue
|
|
182
|
+
chunk=directory/f'align-{index}.wav'
|
|
183
|
+
length=segment['end_seconds']-segment['start_seconds']
|
|
184
|
+
run_process(['ffmpeg','-v','error','-nostdin','-y','-ss',str(segment['start_seconds']),'-i',str(audio),'-t',str(length),
|
|
185
|
+
'-ac','1','-ar','16000','-c:a','pcm_s16le',str(chunk)],cancel,timeout=30)
|
|
186
|
+
try:
|
|
187
|
+
raw=run_alignment(getattr(self,'local_data_root',None),chunk,segment['text'],request['language'],directory/f'words-{index}.json',cancel)
|
|
188
|
+
words=validate_alignment(raw,segment['text'],length)
|
|
189
|
+
segment['words']=[{**word,'start_seconds':segment['start_seconds']+word['start_seconds'],
|
|
190
|
+
'end_seconds':segment['start_seconds']+word['end_seconds']} for word in words]
|
|
191
|
+
except ProjectError as error:
|
|
192
|
+
if job['kind']=='align':raise
|
|
193
|
+
alignment_error=error.code
|
|
194
|
+
payload={'source':span,'segments':segments,'verification':'asr_draft',
|
|
195
|
+
'timing_basis':'forced_alignment' if segments and all(s.get('words') for s in segments) else 'asr_segment',
|
|
196
|
+
'alignment_revision':REVISION if any(s.get('words') for s in segments) else None,
|
|
197
|
+
'alignment_error':alignment_error,'audio_listened':False,'source_start_seconds':start,
|
|
198
|
+
'coverage_seconds':float(prepared.duration_seconds)}
|
|
199
|
+
if cancel.is_set() or self._cancel_event().is_set():
|
|
200
|
+
raise ProjectError('user_cancelled','已取消來源證據工作。',status_code=409)
|
|
201
|
+
with self.repository.projects.connect(self.project_id) as db:
|
|
202
|
+
db.execute("UPDATE production_evidence_jobs SET state='succeeded',result_json=? WHERE job_id=? AND state='running'", (encoded(payload),identifier))
|
|
203
|
+
except Exception as error:
|
|
204
|
+
with self.repository.projects.connect(self.project_id) as db:
|
|
205
|
+
db.execute('UPDATE production_evidence_jobs SET state=?,error_code=? WHERE job_id=? AND state=\'running\'',
|
|
206
|
+
('cancelled' if cancel.is_set() or self._cancel_event().is_set() else 'failed',getattr(error,'code','source_evidence_failed'),identifier))
|
|
207
|
+
finally:
|
|
208
|
+
if transcriber is not None:transcriber.close()
|
|
209
|
+
|
|
210
|
+
def _production_read_evidence_job(self, args):
|
|
211
|
+
deadline=time.monotonic()+args.get('wait_seconds',0)
|
|
212
|
+
while (job:=self._evidence_job(args['job_id']))['state']=='running' and time.monotonic()<deadline:
|
|
213
|
+
time.sleep(.1)
|
|
214
|
+
return ToolResult({'job':job})
|
|
215
|
+
|
|
216
|
+
def _production_cancel_evidence_job(self, args):
|
|
217
|
+
job=self._evidence_job(args['job_id'])
|
|
218
|
+
token=getattr(self,'_evidence_jobs',{}).get(args['job_id'])
|
|
219
|
+
if token:token[0].set()
|
|
220
|
+
with self.repository.projects.connect(self.project_id) as db:
|
|
221
|
+
db.execute("UPDATE production_evidence_jobs SET state='cancelled' WHERE job_id=? AND run_id=? AND state='running'",(args['job_id'],self.run_id))
|
|
222
|
+
return ToolResult({'job':self._evidence_job(job['job_id'])})
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
def local_cues(tools, timeline, *, include_drafts):
|
|
226
|
+
"""Map exact source word evidence into the selected cut, not ASR window fractions."""
|
|
227
|
+
from .production_media import digest
|
|
228
|
+
with tools.repository.projects.connect(tools.project_id) as db:
|
|
229
|
+
rows=db.execute("SELECT job_id,result_json FROM production_evidence_jobs WHERE run_id=? AND state='succeeded' AND kind IN ('transcribe','align') ORDER BY created_at DESC,rowid DESC",(tools.run_id,)).fetchall()
|
|
230
|
+
cues=[];limitations=[];seen=set()
|
|
231
|
+
fps=Fraction(timeline.frame_rate.numerator,timeline.frame_rate.denominator)
|
|
232
|
+
for track in timeline.tracks:
|
|
233
|
+
if track.kind is not TrackKind.VIDEO:continue
|
|
234
|
+
for item in track.items:
|
|
235
|
+
if any(e.effect_id=='audio.source' and e.parameters['mode']=='mute' for e in item.effects):continue
|
|
236
|
+
if any(e.effect_id=='video.speed_ramp' for e in item.effects):
|
|
237
|
+
limitations.append({'item_id':item.item_id,'reason':'retimed_speech_mapping_unavailable'})
|
|
238
|
+
continue
|
|
239
|
+
span=item.source.span;unit=Fraction(span.time_base.numerator,span.time_base.denominator)
|
|
240
|
+
cut_left=float(int(span.start_pts)*unit);cut_right=float(int(span.end_pts)*unit)
|
|
241
|
+
# A fresh, fully covering transcription supersedes older overlapping
|
|
242
|
+
# windows. Combining both produces duplicate/conflicting captions.
|
|
243
|
+
covering=[]
|
|
244
|
+
for row in rows:
|
|
245
|
+
value=json.loads(row['result_json'])
|
|
246
|
+
if value['source']['version_id']!=span.version_id:continue
|
|
247
|
+
origin=value['source_start_seconds']
|
|
248
|
+
if origin<=cut_left+.5/float(fps) and int(value['source']['end_pts'])*value['source']['time_base']['num']/value['source']['time_base']['den']>=cut_right-.5/float(fps):covering.append(row)
|
|
249
|
+
if covering:
|
|
250
|
+
first=json.loads(covering[0]['result_json'])
|
|
251
|
+
corrected=any('wording_authority' in s for s in first['segments'])
|
|
252
|
+
def aligned_for_cut(row):
|
|
253
|
+
value=json.loads(row['result_json']);origin=value['source_start_seconds']
|
|
254
|
+
return all(s.get('words') for s in value['segments'] if origin+s['start_seconds']<cut_right and cut_left<origin+s['end_seconds'])
|
|
255
|
+
chosen=covering[0] if corrected else next((r for r in covering if aligned_for_cut(r)),covering[0])
|
|
256
|
+
selected_rows=[chosen]
|
|
257
|
+
else:selected_rows=rows
|
|
258
|
+
for row in selected_rows:
|
|
259
|
+
result=json.loads(row['result_json'])
|
|
260
|
+
if result['source']['version_id']!=span.version_id:continue
|
|
261
|
+
origin=result['source_start_seconds']
|
|
262
|
+
for n,segment in enumerate(result['segments']):
|
|
263
|
+
left=origin+segment['start_seconds'];right=origin+segment['end_seconds']
|
|
264
|
+
identity=(item.item_id,round(left,4),round(right,4))
|
|
265
|
+
if identity in seen or right<=cut_left or left>=cut_right:continue
|
|
266
|
+
partial=left<cut_left-.5/float(fps) or right>cut_right+.5/float(fps)
|
|
267
|
+
original_text=segment['text']
|
|
268
|
+
if partial:
|
|
269
|
+
selected=[w for w in segment.get('words',[]) if origin+w['start_seconds']>=cut_left-.5/float(fps)
|
|
270
|
+
and origin+w['end_seconds']<=cut_right+.5/float(fps)]
|
|
271
|
+
if not selected:
|
|
272
|
+
limitations.append({'item_id':item.item_id,'reason':'partial_utterance_requires_alignment','text':segment['text']})
|
|
273
|
+
continue
|
|
274
|
+
first,last=selected[0]['char_start'],selected[-1]['char_end']
|
|
275
|
+
# Retain only complete aligned words. Display punctuation
|
|
276
|
+
# belongs to the source text, never invented speech.
|
|
277
|
+
from .alignment import significant
|
|
278
|
+
while last<len(original_text) and not significant(original_text[last]):last+=1
|
|
279
|
+
segment={**segment,'text':original_text[first:last],
|
|
280
|
+
'words':[{**w,'char_start':w['char_start']-first,'char_end':w['char_end']-first} for w in selected]}
|
|
281
|
+
left=origin+selected[0]['start_seconds'];right=origin+selected[-1]['end_seconds']
|
|
282
|
+
seen.add(identity)
|
|
283
|
+
if not include_drafts:continue
|
|
284
|
+
begin=item.start_frame+max(0,math.floor((left-cut_left)*fps))
|
|
285
|
+
end=min(item.start_frame+item.duration_frames,item.start_frame+math.ceil((right-cut_left)*fps))
|
|
286
|
+
words=[{**w,'start_frame':item.start_frame+max(0,round((origin+w['start_seconds']-cut_left)*fps)),
|
|
287
|
+
'end_frame':min(item.start_frame+item.duration_frames,item.start_frame+round((origin+w['end_seconds']-cut_left)*fps))} for w in segment.get('words',[])]
|
|
288
|
+
cues.append({'cue_id':digest([item.item_id,row['job_id'],n])[:24], 'item_id':item.item_id,
|
|
289
|
+
'start_frame':begin,'duration_frames':end-begin,'text':segment['text'],
|
|
290
|
+
'verification':'asr_draft','source_revision_id':row['job_id'],'segment_id':str(n),
|
|
291
|
+
'source_utterance_partial':partial,'source_utterance_text':original_text,
|
|
292
|
+
**{key:segment[key] for key in ('wording_authority','source_asr_text','correction_evidence') if key in segment},
|
|
293
|
+
'timing_basis':'forced_alignment' if words else 'asr_segment','words':words,
|
|
294
|
+
'source':{**span.to_storage(),'start_pts':str(round(left/float(unit))),'end_pts':str(round(right/float(unit)))}})
|
|
295
|
+
return sorted(cues,key=lambda c:c['start_frame']),limitations
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"""What changed between two versions of a film, said the way a person would say it.
|
|
2
|
+
|
|
3
|
+
Compares stored timeline payloads, so it works for every version ever saved,
|
|
4
|
+
whoever made the change.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
def _components(payload):
|
|
8
|
+
return {item['item_id']: item for track in payload['tracks']
|
|
9
|
+
if track['track_id'] == 'program-components' or track['track_id'].startswith('program-components-')
|
|
10
|
+
for item in track['items']}
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def _lanes(payload):
|
|
14
|
+
"""Which component lane each graphic is on; a higher lane is drawn on top."""
|
|
15
|
+
tracks = [t for t in payload['tracks'] if t['track_id'] == 'program-components' or t['track_id'].startswith('program-components-')]
|
|
16
|
+
return {item['item_id']: n for n, track in enumerate(tracks) for item in track['items']}
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def _subtitles(payload):
|
|
20
|
+
return {item['item_id']: item for track in payload['tracks'] if track['track_id'] == 'agent-subtitles' for item in track['items']}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _media(payload, kind):
|
|
24
|
+
return [item for track in payload['tracks'] if track['kind'] == kind for item in track['items'] if item.get('kind') == 'media']
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _name(item):
|
|
28
|
+
first = (item.get('text') or '').split('\n', 1)[0].strip()
|
|
29
|
+
return f'「{first[:18]}{"…" if len(first) > 18 else ""}」' if first else '一個元件'
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def _clock(frames, payload):
|
|
33
|
+
rate = payload['frame_rate']
|
|
34
|
+
seconds = round(frames * rate['den'] / rate['num'])
|
|
35
|
+
return f'{seconds // 60}:{seconds % 60:02d}'
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _graphic_change(before, after, styles, recut=False):
|
|
39
|
+
"""One sentence for one graphic that is in both versions, or None when it did not change."""
|
|
40
|
+
if before.get('text') != after.get('text'):
|
|
41
|
+
old, new = (item.get('text', '').split('\n', 1)[0] for item in (before, after))
|
|
42
|
+
return f'把「{old}」改成「{new}」' if old != new else f'改了{_name(after)}的補充文字'
|
|
43
|
+
if before.get('style_id') != after.get('style_id'):
|
|
44
|
+
old, new = styles.get(before.get('style_id'), {}), styles.get(after.get('style_id'), {})
|
|
45
|
+
old_look, new_look = old.get('look') or {}, new.get('look') or {}
|
|
46
|
+
if new_look and old_look.get('look_id') != new_look.get('look_id') and old.get('html') == new.get('html'):
|
|
47
|
+
return f'把{_name(after)}換成「{new_look["name"]}」外觀'
|
|
48
|
+
if new_look and old_look != new_look and old.get('html') == new.get('html'):
|
|
49
|
+
# Said once per look, not once per graphic that follows it.
|
|
50
|
+
return ('look', new_look['name'], old_look.get('fonts') != new_look.get('fonts'), old_look.get('colors') != new_look.get('colors'))
|
|
51
|
+
if old.get('html') != new.get('html') and new.get('html'):
|
|
52
|
+
return f'重新設計{_name(after)}'
|
|
53
|
+
if old.get('edits') != new.get('edits') and new.get('html'):
|
|
54
|
+
before_edits, after_edits = old.get('edits') or {}, new.get('edits') or {}
|
|
55
|
+
words = (before_edits.get('texts') or {}) != (after_edits.get('texts') or {})
|
|
56
|
+
colours = (before_edits.get('colors') or {}) != (after_edits.get('colors') or {})
|
|
57
|
+
return f'改了{_name(after)}的' + ('文字和顏色' if words and colours else '文字' if words else '顏色')
|
|
58
|
+
if (old.get('x'), old.get('y')) != (new.get('x'), new.get('y')) and old and new:
|
|
59
|
+
return f'移動{_name(after)}'
|
|
60
|
+
if old.get('scale', 1) != new.get('scale', 1):
|
|
61
|
+
return f'{"放大" if new.get("scale", 1) > old.get("scale", 1) else "縮小"}{_name(after)}'
|
|
62
|
+
if old.get('colors') != new.get('colors'):
|
|
63
|
+
return f'換了{_name(after)}的顏色'
|
|
64
|
+
if old.get('visual_style_id') != new.get('visual_style_id'):
|
|
65
|
+
return f'{_name(after)}換了樣式'
|
|
66
|
+
if old.get('font_style_id') != new.get('font_style_id'):
|
|
67
|
+
return f'{_name(after)}換了字體'
|
|
68
|
+
if (old.get('start_offset_frames'), old.get('anchor_item_id')) == (new.get('start_offset_frames'), new.get('anchor_item_id')) and not recut:
|
|
69
|
+
return f'調整{_name(after)}'
|
|
70
|
+
# After a new cut every graphic shifts with its shot; that is part of the cut, not news of its own.
|
|
71
|
+
if not recut and (before['start_frame'], before['duration_frames']) != (after['start_frame'], after['duration_frames']):
|
|
72
|
+
return f'調整{_name(after)}出現的時間'
|
|
73
|
+
return None
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def describe(before, after, styles=None):
|
|
77
|
+
"""Short sentences, most noticeable first. Empty when the pictures are the same."""
|
|
78
|
+
styles = styles or {}
|
|
79
|
+
changes = []
|
|
80
|
+
old_cut, new_cut = _media(before, 'video'), _media(after, 'video')
|
|
81
|
+
recut = [(i['start_frame'], i['duration_frames'], i.get('source')) for i in old_cut] != [(i['start_frame'], i['duration_frames'], i.get('source')) for i in new_cut]
|
|
82
|
+
if [(i['start_frame'], i['duration_frames'], i.get('source')) for i in old_cut] != [(i['start_frame'], i['duration_frames'], i.get('source')) for i in new_cut]:
|
|
83
|
+
if before['duration_frames'] != after['duration_frames']:
|
|
84
|
+
changes.append(f'重新剪輯,片長 {_clock(before["duration_frames"], before)} → {_clock(after["duration_frames"], after)}')
|
|
85
|
+
else:
|
|
86
|
+
changes.append('調整剪輯')
|
|
87
|
+
elif [[e for e in i.get('effects', []) if not e.get('effect_id', '').startswith('audio.')] for i in old_cut] != \
|
|
88
|
+
[[e for e in i.get('effects', []) if not e.get('effect_id', '').startswith('audio.')] for i in new_cut]:
|
|
89
|
+
changes.append('調整畫面效果或轉場')
|
|
90
|
+
def music(cut):
|
|
91
|
+
return sorted({layer.get('asset_id') for i in cut for e in i.get('effects', []) if e.get('effect_id') == 'audio.layers'
|
|
92
|
+
for layer in e.get('parameters', {}).get('layers', [])} - {None})
|
|
93
|
+
def sound(cut):
|
|
94
|
+
return [[e for e in i.get('effects', []) if e.get('effect_id', '').startswith('audio.') and e.get('effect_id') != 'audio.layers'] for i in cut]
|
|
95
|
+
# A new cut moves the music with it; only a different song, or new levels on the same cut, is news.
|
|
96
|
+
if music(old_cut) != music(new_cut):
|
|
97
|
+
changes.append('換了配樂')
|
|
98
|
+
elif not changes and (sound(old_cut) != sound(new_cut) or [e for i in old_cut for e in i.get('effects', []) if e.get('effect_id') == 'audio.layers']
|
|
99
|
+
!= [e for i in new_cut for e in i.get('effects', []) if e.get('effect_id') == 'audio.layers']):
|
|
100
|
+
changes.append('調整配樂或聲音')
|
|
101
|
+
old, new = _components(before), _components(after)
|
|
102
|
+
for key in new.keys() - old.keys():
|
|
103
|
+
changes.append(f'新增{_name(new[key])}')
|
|
104
|
+
for key in old.keys() - new.keys():
|
|
105
|
+
changes.append(f'刪除{_name(old[key])}')
|
|
106
|
+
looks = {}
|
|
107
|
+
for key in sorted(old.keys() & new.keys(), key=lambda k: new[k]['start_frame']):
|
|
108
|
+
sentence = _graphic_change(old[key], new[key], styles, recut)
|
|
109
|
+
if isinstance(sentence, tuple):
|
|
110
|
+
_, name, fonts, colours = sentence
|
|
111
|
+
if name not in looks:
|
|
112
|
+
looks[name] = True
|
|
113
|
+
changes.append(f'換了「{name}」外觀的' + ('字型和配色' if fonts and colours else '字型' if fonts else '配色'))
|
|
114
|
+
continue
|
|
115
|
+
if sentence is None and not recut and _lanes(before)[key] != _lanes(after)[key]:
|
|
116
|
+
sentence = f'把{_name(new[key])}移到另一軌'
|
|
117
|
+
if sentence:
|
|
118
|
+
changes.append(sentence)
|
|
119
|
+
old_subtitles, new_subtitles = _subtitles(before), _subtitles(after)
|
|
120
|
+
if old_subtitles != new_subtitles:
|
|
121
|
+
changed = len(old_subtitles.keys() ^ new_subtitles.keys()) + sum(
|
|
122
|
+
old_subtitles[k] != new_subtitles[k] for k in old_subtitles.keys() & new_subtitles.keys())
|
|
123
|
+
changes.append(f'修改 {changed} 句字幕' if changed else '調整字幕')
|
|
124
|
+
return changes
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def summary(changes, limit=2):
|
|
128
|
+
if not changes:
|
|
129
|
+
return None
|
|
130
|
+
shown = '、'.join(changes[:limit])
|
|
131
|
+
return shown + (f',還有 {len(changes) - limit} 處' if len(changes) > limit else '')
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"""Display-only grouping of imported music; rendering and asset IDs stay intact."""
|
|
2
|
+
from clipen.finishing.models import digest
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def music_choices(store):
|
|
6
|
+
result = []
|
|
7
|
+
for record in store.records():
|
|
8
|
+
asset = record['asset']
|
|
9
|
+
if asset['role'] != 'music':
|
|
10
|
+
continue
|
|
11
|
+
public = {k: v for k, v in asset.items() if k not in {'relative_path', 'fingerprint', 'mtime_ns', 'size_bytes'}}
|
|
12
|
+
rights = {k: v for k, v in asset.get('provenance', {}).items() if k not in {'retrieved_at', 'changes'}}
|
|
13
|
+
public['duplicate_group'] = digest([asset.get('fingerprint') or asset['asset_id'], asset['duration_seconds'], rights])
|
|
14
|
+
result.append(public)
|
|
15
|
+
return result
|