Skip to content

Commit 60eaf02

Browse files
committed
Keep the stored caption file until Generate finishes
Generate marked the transcript as Central's as soon as a job started, so while the job ran, or after it failed, the caption sync saw an unlisted Central copy and removed the uploaded file the video used. Generate now marks a running job central-pending: the stored file is kept and played as an upload until Central reports a ready default, which then replaces it and marks it central. Every write of Central's transcript (sync, callback, godam_get_transcript_path) now marks it central too, so the address check only decides for transcripts stored before 2.8.0. The rtgodam_transcoder_file_hosts docblock says so. Regenerate godam.pot for the shifted line references.
1 parent 1682c73 commit 60eaf02

7 files changed

Lines changed: 307 additions & 52 deletions

File tree

‎admin/class-rtgodam-transcoder-rest-routes.php‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,10 +669,11 @@ public function handle_transcription_callback( WP_REST_Request $request ) {
669669
// language. Cache the default caption from the full list instead,
670670
// and leave a transcript the user uploaded in WordPress alone.
671671
\RTGODAM\Inc\REST_API\Transcription::sync_cached_transcript( (int) $attachment_id, $caption_tracks, false );
672-
} elseif ( ! \RTGODAM\Inc\REST_API\Transcription::is_wordpress_upload( get_post_meta( $attachment_id, 'rtgodam_transcript_path', true ), get_post_meta( $attachment_id, 'rtgodam_transcript_source', true ) ) ) {
672+
} elseif ( \RTGODAM\Inc\REST_API\Transcription::takes_central_transcript( get_post_meta( $attachment_id, 'rtgodam_transcript_path', true ), get_post_meta( $attachment_id, 'rtgodam_transcript_source', true ) ) ) {
673673
// Older Central: only the one transcript path is sent.
674674
// The transcript_path parameter is already sanitized by the REST API framework via esc_url_raw sanitize_callback.
675675
update_post_meta( $attachment_id, 'rtgodam_transcript_path', $transcript_path );
676+
update_post_meta( $attachment_id, 'rtgodam_transcript_source', \RTGODAM\Inc\REST_API\Transcription::SOURCE_CENTRAL );
676677
}
677678

678679
return new WP_REST_Response(

‎inc/classes/class-seo.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ public function get_transcript_excerpt( $attachment_id, $allow_remote = false )
643643
// The transcript may be a cached copy of GoDAM Central's default caption,
644644
// which can change in Central's own dashboard without telling WordPress.
645645
// Re-check it in the background at most every 12 hours.
646-
if ( class_exists( '\RTGODAM\Inc\REST_API\Transcription' ) && ! \RTGODAM\Inc\REST_API\Transcription::is_wordpress_upload( $transcript_path, $source ) ) {
646+
if ( class_exists( '\RTGODAM\Inc\REST_API\Transcription' ) && \RTGODAM\Inc\REST_API\Transcription::takes_central_transcript( $transcript_path, $source ) ) {
647647
\RTGODAM\Inc\REST_API\Transcription::maybe_schedule_refresh( $attachment_id, $checked_at );
648648
}
649649

‎inc/classes/rest-api/class-transcription.php‎

Lines changed: 59 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@ class Transcription extends Base {
4848
* the user uploaded in WordPress, rather than a cached copy of GoDAM
4949
* Central's default caption. An uploaded file never reaches Central, so the
5050
* player plays it ahead of Central's tracks and Central updates never
51-
* overwrite it. Set to `central` (SOURCE_CENTRAL) on generate, cleared on
52-
* delete. Unset on transcripts stored before 2.8.0: see is_wordpress_upload().
51+
* overwrite it. `central-pending` (SOURCE_PENDING) while a Generate job
52+
* runs, `central` (SOURCE_CENTRAL) once Central's transcript is stored,
53+
* cleared on delete. Unset on transcripts stored before 2.8.0: see
54+
* is_wordpress_upload().
5355
*
5456
* @since 2.8.0
5557
*
@@ -66,6 +68,17 @@ class Transcription extends Base {
6668
*/
6769
const SOURCE_CENTRAL = 'central';
6870

71+
/**
72+
* SOURCE_META value while a Generate job runs. The file stored before it
73+
* (often an upload) is kept and played until Central has a ready default
74+
* caption, so a job that is slow or fails never leaves the video without one.
75+
*
76+
* @since 2.8.0
77+
*
78+
* @var string
79+
*/
80+
const SOURCE_PENDING = 'central-pending';
81+
6982
/**
7083
* Meta holding when the cached transcript was last checked against GoDAM
7184
* Central's caption list (a Unix timestamp), whether or not Central answered.
@@ -583,10 +596,10 @@ public function generate_transcription( \WP_REST_Request $request ) {
583596
// A job is genuinely in progress — clear the delete marker and
584597
// remember the in-flight status so the editor keeps polling. On a
585598
// hard error we leave the delete marker intact.
586-
// Marked as Central's, so the finished transcript replaces an upload
587-
// still stored from before 2.8.0 (see is_wordpress_upload()).
599+
// Marked pending: the stored file stays until Central reports a ready
600+
// default, which then replaces it (see sync_cached_transcript()).
588601
delete_post_meta( $attachment_id, self::DELETED_META );
589-
update_post_meta( $attachment_id, self::SOURCE_META, self::SOURCE_CENTRAL );
602+
update_post_meta( $attachment_id, self::SOURCE_META, self::SOURCE_PENDING );
590603
$track = $current_status ? $current_status : $status;
591604
update_post_meta( $attachment_id, self::STATUS_META, $track );
592605
}
@@ -833,7 +846,9 @@ private function write_caption( $attachment_id, $method, $body ) {
833846
* uploaded in WordPress, which GoDAM Central does not have.
834847
*
835848
* From 2.8.0 on, {@see self::SOURCE_META} says which it is: `upload`, or
836-
* `central` after Generate. Earlier versions left no mark, so an unmarked
849+
* `central` for Central's transcript. While a Generate job runs
850+
* (`central-pending`), the stored file is kept and played like an upload
851+
* until Central's transcript is ready. Earlier versions left no mark, so an unmarked
837852
* transcript counts as an upload when it is not on Central's CDN: Central
838853
* serves its caption files only from there, so any other address is a file
839854
* the site holds itself.
@@ -851,9 +866,28 @@ public static function is_wordpress_upload( $path, $source ) {
851866

852867
$path = is_string( $path ) ? $path : '';
853868

869+
if ( self::SOURCE_PENDING === $source ) {
870+
return '' !== $path;
871+
}
872+
854873
return '' === $source && '' !== $path && ! rtgodam_is_transcoder_file_url( $path );
855874
}
856875

876+
/**
877+
* Whether Central's caption list may update the stored transcript: it is
878+
* Central's copy, nothing is stored, or a Generate job is waiting for
879+
* Central's transcript. False only for a file uploaded in WordPress.
880+
*
881+
* @since 2.8.0
882+
*
883+
* @param mixed $path Value of the `rtgodam_transcript_path` meta.
884+
* @param mixed $source Value of the {@see self::SOURCE_META} meta.
885+
* @return bool
886+
*/
887+
public static function takes_central_transcript( $path, $source ) {
888+
return self::SOURCE_PENDING === $source || ! self::is_wordpress_upload( $path, $source );
889+
}
890+
857891
/**
858892
* Point the attachment's cached transcript (`rtgodam_transcript_path`) at
859893
* the default caption track Central reports, so the editor's Transcription
@@ -896,22 +930,28 @@ public static function sync_cached_transcript( $attachment_id, $captions, $switc
896930
}
897931
delete_post_meta( $attachment_id, self::DELETED_META );
898932
$cached_path = (string) get_post_meta( $attachment_id, 'rtgodam_transcript_path', true );
899-
if ( ! self::is_wordpress_upload( $cached_path, get_post_meta( $attachment_id, self::SOURCE_META, true ) ) ) {
933+
$source = get_post_meta( $attachment_id, self::SOURCE_META, true );
934+
if ( self::takes_central_transcript( $cached_path, $source ) ) {
900935
update_post_meta( $attachment_id, self::CHECKED_META, time() );
901936
if ( '' !== $default_path ) {
902937
update_post_meta( $attachment_id, 'rtgodam_transcript_path', $default_path );
903938
update_post_meta( $attachment_id, self::STATUS_META, 'Transcribed' );
904-
} elseif ( '' !== $cached_path && in_array( $file_key( $cached_path ), $listed_files, true ) ) {
905-
// The default has no file yet (an AI transcript still pending, or one
906-
// that failed). Keep the transcript WordPress has while Central still
907-
// lists it, so the Transcription tab and the player don't lose it.
908-
update_post_meta( $attachment_id, self::STATUS_META, 'Transcribed' );
909-
} else {
910-
delete_post_meta( $attachment_id, 'rtgodam_transcript_path' );
911-
// Keep an in-flight status (such as "Transcribing") so the tab still
912-
// shows the job in progress; only a finished one goes with the file.
913-
if ( 'Transcribed' === get_post_meta( $attachment_id, self::STATUS_META, true ) ) {
914-
delete_post_meta( $attachment_id, self::STATUS_META );
939+
update_post_meta( $attachment_id, self::SOURCE_META, self::SOURCE_CENTRAL );
940+
} elseif ( self::SOURCE_PENDING !== $source ) {
941+
// While Generate runs, or after it failed, the stored file and status
942+
// stay as they are until Central has a ready default caption.
943+
if ( '' !== $cached_path && in_array( $file_key( $cached_path ), $listed_files, true ) ) {
944+
// The default has no file yet (an AI transcript still pending, or one
945+
// that failed). Keep the transcript WordPress has while Central still
946+
// lists it, so the Transcription tab and the player don't lose it.
947+
update_post_meta( $attachment_id, self::STATUS_META, 'Transcribed' );
948+
} else {
949+
delete_post_meta( $attachment_id, 'rtgodam_transcript_path' );
950+
// Keep an in-flight status (such as "Transcribing") so the tab still
951+
// shows the job in progress; only a finished one goes with the file.
952+
if ( 'Transcribed' === get_post_meta( $attachment_id, self::STATUS_META, true ) ) {
953+
delete_post_meta( $attachment_id, self::STATUS_META );
954+
}
915955
}
916956
}
917957
}
@@ -944,7 +984,7 @@ public static function refresh_cached_default( $attachment_id ) {
944984
/** This action is documented in inc/classes/rest-api/class-transcription.php */
945985
do_action( 'rtgodam_before_attachment_lookup' );
946986
$is_deleted = (bool) get_post_meta( $attachment_id, self::DELETED_META, true );
947-
$is_upload = self::is_wordpress_upload(
987+
$is_upload = ! self::takes_central_transcript(
948988
get_post_meta( $attachment_id, 'rtgodam_transcript_path', true ),
949989
get_post_meta( $attachment_id, self::SOURCE_META, true )
950990
);

‎inc/helpers/custom-functions.php‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2172,6 +2172,9 @@ function godam_get_transcript_path( $attachment_id, $job_id = null ) {
21722172
*/
21732173
do_action( 'rtgodam_before_attachment_lookup' );
21742174
update_post_meta( $attachment_id, 'rtgodam_transcript_path', $transcript_path );
2175+
// Marked as Central's, so only transcripts stored before 2.8.0 need the
2176+
// address check in Transcription::is_wordpress_upload().
2177+
update_post_meta( $attachment_id, 'rtgodam_transcript_source', 'central' );
21752178
do_action( 'rtgodam_after_attachment_lookup' );
21762179
}
21772180

@@ -3560,6 +3563,11 @@ function rtgodam_get_transcoder_file_hosts() {
35603563
* A name matches that host and any subdomain of it. Add the CDN domain of a
35613564
* self-hosted or staging GoDAM Central here, or a domain the CDN is served from.
35623565
*
3566+
* Since 2.8.0 these hosts also tell a caption file uploaded in WordPress apart
3567+
* from a copy of Central's caption, for transcripts stored before 2.8.0 (which
3568+
* carry no `rtgodam_transcript_source`): a file on any other host is kept as
3569+
* an upload and never replaced by Central's caption list.
3570+
*
35633571
* @since 2.7.0
35643572
*
35653573
* @param string[] $hosts Host names, such as `gdcdn.us`.

‎languages/godam.pot‎

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ msgstr ""
99
"MIME-Version: 1.0\n"
1010
"Content-Type: text/plain; charset=UTF-8\n"
1111
"Content-Transfer-Encoding: 8bit\n"
12-
"POT-Creation-Date: 2026-11-10T09:05:46+00:00\n"
12+
"POT-Creation-Date: 2026-11-10T09:36:25+00:00\n"
1313
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1414
"X-Generator: WP-CLI 2.12.0\n"
1515
"X-Domain: godam\n"
@@ -11512,26 +11512,26 @@ msgstr ""
1151211512
msgid "Video attachment not found for the provided job ID."
1151311513
msgstr ""
1151411514

11515-
#: admin/class-rtgodam-transcoder-rest-routes.php:681
11515+
#: admin/class-rtgodam-transcoder-rest-routes.php:682
1151611516
msgid "Transcript path saved successfully."
1151711517
msgstr ""
1151811518

11519-
#: admin/class-rtgodam-transcoder-rest-routes.php:691
11519+
#: admin/class-rtgodam-transcoder-rest-routes.php:692
1152011520
msgid "Transcription callback received."
1152111521
msgstr ""
1152211522

11523-
#: admin/class-rtgodam-transcoder-rest-routes.php:732
11523+
#: admin/class-rtgodam-transcoder-rest-routes.php:733
1152411524
#: admin/godam-transcoder-functions.php:607
1152511525
#: inc/classes/rest-api/class-media-library.php:652
1152611526
#: inc/classes/rest-api/class-transcoding.php:481
1152711527
msgid "API key is required."
1152811528
msgstr ""
1152911529

11530-
#: admin/class-rtgodam-transcoder-rest-routes.php:736
11530+
#: admin/class-rtgodam-transcoder-rest-routes.php:737
1153111531
msgid "API key not configured on the site."
1153211532
msgstr ""
1153311533

11534-
#: admin/class-rtgodam-transcoder-rest-routes.php:740
11534+
#: admin/class-rtgodam-transcoder-rest-routes.php:741
1153511535
#: inc/classes/rest-api/class-media-library.php:659
1153611536
#: inc/classes/rest-api/class-settings.php:192
1153711537
#: inc/classes/rest-api/class-transcoding.php:487
@@ -14023,83 +14023,83 @@ msgstr ""
1402314023
msgid "%1$s (ID %2$d) transcoding request was sent successfully"
1402414024
msgstr ""
1402514025

14026-
#: inc/classes/rest-api/class-transcription.php:171
14026+
#: inc/classes/rest-api/class-transcription.php:184
1402714027
msgid "The video attachment ID."
1402814028
msgstr ""
1402914029

14030-
#: inc/classes/rest-api/class-transcription.php:192
14030+
#: inc/classes/rest-api/class-transcription.php:205
1403114031
msgid "Re-read the default caption from GoDAM Central first, so changes made in Central show."
1403214032
msgstr ""
1403314033

14034-
#: inc/classes/rest-api/class-transcription.php:218
14034+
#: inc/classes/rest-api/class-transcription.php:231
1403514035
msgid "BCP 47 language code to transcribe in, or \"auto\"/\"multi\" for Deepgram detection. Omitted falls back to the org/default language."
1403614036
msgstr ""
1403714037

14038-
#: inc/classes/rest-api/class-transcription.php:224
14038+
#: inc/classes/rest-api/class-transcription.php:237
1403914039
msgid "Audio stream to transcribe on a multi-audio asset. Omitted transcribes the default track."
1404014040
msgstr ""
1404114041

14042-
#: inc/classes/rest-api/class-transcription.php:244
14042+
#: inc/classes/rest-api/class-transcription.php:257
1404314043
msgid "URL of the uploaded .vtt / .srt caption file."
1404414044
msgstr ""
1404514045

14046-
#: inc/classes/rest-api/class-transcription.php:319
14046+
#: inc/classes/rest-api/class-transcription.php:332
1404714047
msgid "BCP 47 language tag for the caption track."
1404814048
msgstr ""
1404914049

14050-
#: inc/classes/rest-api/class-transcription.php:327
14050+
#: inc/classes/rest-api/class-transcription.php:340
1405114051
msgid "Label shown in the subtitle menu. Unique on the video."
1405214052
msgstr ""
1405314053

14054-
#: inc/classes/rest-api/class-transcription.php:334
14054+
#: inc/classes/rest-api/class-transcription.php:347
1405514055
msgid "Track kind: subtitles or captions."
1405614056
msgstr ""
1405714057

14058-
#: inc/classes/rest-api/class-transcription.php:340
14058+
#: inc/classes/rest-api/class-transcription.php:353
1405914059
msgid "Make this the default caption track."
1406014060
msgstr ""
1406114061

14062-
#: inc/classes/rest-api/class-transcription.php:350
14062+
#: inc/classes/rest-api/class-transcription.php:363
1406314063
msgid "Caption file text (VTT or SRT)."
1406414064
msgstr ""
1406514065

14066-
#: inc/classes/rest-api/class-transcription.php:359
14066+
#: inc/classes/rest-api/class-transcription.php:372
1406714067
msgid "Format of the uploaded caption text."
1406814068
msgstr ""
1406914069

14070-
#: inc/classes/rest-api/class-transcription.php:377
14070+
#: inc/classes/rest-api/class-transcription.php:390
1407114071
msgid "Caption track handle returned by the list endpoint."
1407214072
msgstr ""
1407314073

14074-
#: inc/classes/rest-api/class-transcription.php:511
14074+
#: inc/classes/rest-api/class-transcription.php:524
1407514075
msgid "This video has not been transcoded yet, so it cannot be transcribed."
1407614076
msgstr ""
1407714077

14078-
#: inc/classes/rest-api/class-transcription.php:520
14078+
#: inc/classes/rest-api/class-transcription.php:533
1407914079
msgid "Connect your GoDAM account to generate transcriptions."
1408014080
msgstr ""
1408114081

14082-
#: inc/classes/rest-api/class-transcription.php:553
14082+
#: inc/classes/rest-api/class-transcription.php:566
1408314083
msgid "Could not reach the transcription service. Please try again."
1408414084
msgstr ""
1408514085

14086-
#: inc/classes/rest-api/class-transcription.php:621
14086+
#: inc/classes/rest-api/class-transcription.php:634
1408714087
msgid "Only .vtt or .srt caption files are supported."
1408814088
msgstr ""
1408914089

14090-
#: inc/classes/rest-api/class-transcription.php:1095
14090+
#: inc/classes/rest-api/class-transcription.php:1135
1409114091
msgid "Connect your GoDAM account to manage captions."
1409214092
msgstr ""
1409314093

14094-
#: inc/classes/rest-api/class-transcription.php:1116
14094+
#: inc/classes/rest-api/class-transcription.php:1156
1409514095
msgid "This video has not been transcoded yet, so it has no captions."
1409614096
msgstr ""
1409714097

14098-
#: inc/classes/rest-api/class-transcription.php:1148
14098+
#: inc/classes/rest-api/class-transcription.php:1188
1409914099
msgid "Could not reach the caption service. Please try again."
1410014100
msgstr ""
1410114101

14102-
#: inc/classes/rest-api/class-transcription.php:1169
14102+
#: inc/classes/rest-api/class-transcription.php:1209
1410314103
msgid "The caption service rejected the request."
1410414104
msgstr ""
1410514105

@@ -14769,23 +14769,23 @@ msgstr ""
1476914769
msgid "s"
1477014770
msgstr ""
1477114771

14772-
#: inc/helpers/custom-functions.php:2474
14772+
#: inc/helpers/custom-functions.php:2477
1477314773
msgid "Oops! We could not locate your video"
1477414774
msgstr ""
1477514775

14776-
#: inc/helpers/custom-functions.php:2485
14776+
#: inc/helpers/custom-functions.php:2488
1477714777
msgid "Note: This is a simple image preview. The image and its layers may display differently when added to a page based on theme styles."
1477814778
msgstr ""
1477914779

14780-
#: inc/helpers/custom-functions.php:2487
14780+
#: inc/helpers/custom-functions.php:2490
1478114781
msgid "Note: This is a simple audio preview. The player may display differently when added to a page based on theme styles."
1478214782
msgstr ""
1478314783

14784-
#: inc/helpers/custom-functions.php:2489
14784+
#: inc/helpers/custom-functions.php:2492
1478514785
msgid "Note: This is a simple video preview. The video player may display differently when added to a page based on theme styles."
1478614786
msgstr ""
1478714787

14788-
#: inc/helpers/custom-functions.php:2679
14788+
#: inc/helpers/custom-functions.php:2682
1478914789
msgid "Video not found"
1479014790
msgstr ""
1479114791

‎tests/php/TranscriptionCaptionSyncTest.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ public function upload_cases() {
185185
'unmarked offloaded file' => array( $offload, '', true ),
186186
'unmarked Central copy' => array( $central, '', false ),
187187
'generated, old file still set' => array( $site, 'central', false ),
188+
'Generate running, file stored' => array( $site, 'central-pending', true ),
189+
'Generate running, nothing' => array( '', 'central-pending', false ),
188190
'nothing stored' => array( '', '', false ),
189191
);
190192
}

0 commit comments

Comments
 (0)