Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion admin/class-rtgodam-transcoder-rest-routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ public function handle_transcription_callback( WP_REST_Request $request ) {
// language. Cache the default caption from the full list instead,
// and leave a transcript the user uploaded in WordPress alone.
\RTGODAM\Inc\REST_API\Transcription::sync_cached_transcript( (int) $attachment_id, $caption_tracks, false );
} elseif ( 'upload' !== get_post_meta( $attachment_id, 'rtgodam_transcript_source', true ) ) {
} 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 ) ) ) {
// Older Central: only the one transcript path is sent.
// The transcript_path parameter is already sanitized by the REST API framework via esc_url_raw sanitize_callback.
update_post_meta( $attachment_id, 'rtgodam_transcript_path', $transcript_path );
Expand Down
4 changes: 2 additions & 2 deletions inc/classes/class-seo.php
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ public function get_transcript_excerpt( $attachment_id, $allow_remote = false )
do_action( 'rtgodam_before_attachment_lookup' );
$transcript_path = (string) get_post_meta( $attachment_id, 'rtgodam_transcript_path', true );
$is_deleted = (bool) get_post_meta( $attachment_id, 'rtgodam_transcript_deleted', true );
$is_upload = 'upload' === get_post_meta( $attachment_id, 'rtgodam_transcript_source', true );
$source = get_post_meta( $attachment_id, 'rtgodam_transcript_source', true );
$checked_at = (int) get_post_meta( $attachment_id, 'rtgodam_transcript_checked_at', true );
$cache = get_post_meta( $attachment_id, self::TRANSCRIPT_EXCERPT_META_KEY, true );
do_action( 'rtgodam_after_attachment_lookup' );
Expand All @@ -643,7 +643,7 @@ public function get_transcript_excerpt( $attachment_id, $allow_remote = false )
// The transcript may be a cached copy of GoDAM Central's default caption,
// which can change in Central's own dashboard without telling WordPress.
// Re-check it in the background at most every 12 hours.
if ( ! $is_upload && class_exists( '\RTGODAM\Inc\REST_API\Transcription' ) ) {
if ( class_exists( '\RTGODAM\Inc\REST_API\Transcription' ) && ! \RTGODAM\Inc\REST_API\Transcription::is_wordpress_upload( $transcript_path, $source ) ) {
\RTGODAM\Inc\REST_API\Transcription::maybe_schedule_refresh( $attachment_id, $checked_at );
}

Expand Down
53 changes: 47 additions & 6 deletions inc/classes/rest-api/class-transcription.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,24 @@ class Transcription extends Base {
* the user uploaded in WordPress, rather than a cached copy of GoDAM
* Central's default caption. An uploaded file never reaches Central, so the
* player plays it ahead of Central's tracks and Central updates never
* overwrite it. Cleared on generate and on delete.
* overwrite it. Set to `central` (SOURCE_CENTRAL) on generate, cleared on
* delete. Unset on transcripts stored before 2.8.0: see is_wordpress_upload().
*
* @since 2.8.0
*
* @var string
*/
const SOURCE_META = 'rtgodam_transcript_source';

/**
* SOURCE_META value for a transcript generated by GoDAM Central.
*
* @since 2.8.0
*
* @var string
*/
const SOURCE_CENTRAL = 'central';

/**
* Meta holding when the cached transcript was last checked against GoDAM
* Central's caption list (a Unix timestamp), whether or not Central answered.
Expand Down Expand Up @@ -566,15 +576,17 @@ public function generate_transcription( \WP_REST_Request $request ) {
if ( ! empty( $path ) ) {
// A (re)generated transcript supersedes any prior delete or upload.
delete_post_meta( $attachment_id, self::DELETED_META );
delete_post_meta( $attachment_id, self::SOURCE_META );
update_post_meta( $attachment_id, self::SOURCE_META, self::SOURCE_CENTRAL );
update_post_meta( $attachment_id, 'rtgodam_transcript_path', $path );
update_post_meta( $attachment_id, self::STATUS_META, 'Transcribed' );
} elseif ( '' !== $current_status || '' !== $status ) {
// A job is genuinely in progress — clear the delete marker and
// remember the in-flight status so the editor keeps polling. On a
// hard error we leave the delete marker intact.
// Marked as Central's, so the finished transcript replaces an upload
// still stored from before 2.8.0 (see is_wordpress_upload()).
delete_post_meta( $attachment_id, self::DELETED_META );
delete_post_meta( $attachment_id, self::SOURCE_META );
update_post_meta( $attachment_id, self::SOURCE_META, self::SOURCE_CENTRAL );
Comment thread
subodhr258 marked this conversation as resolved.
Resolved
$track = $current_status ? $current_status : $status;
update_post_meta( $attachment_id, self::STATUS_META, $track );
}
Expand Down Expand Up @@ -816,6 +828,32 @@ private function write_caption( $attachment_id, $method, $body ) {
return $response;
}

/**
* Whether the attachment's stored transcript is a caption file the user
* uploaded in WordPress, which GoDAM Central does not have.
*
* From 2.8.0 on, {@see self::SOURCE_META} says which it is: `upload`, or
* `central` after Generate. Earlier versions left no mark, so an unmarked
* transcript counts as an upload when it is not on Central's CDN: Central
* serves its caption files only from there, so any other address is a file
* the site holds itself.
*
* @since 2.8.0
*
* @param mixed $path Value of the `rtgodam_transcript_path` meta.
* @param mixed $source Value of the {@see self::SOURCE_META} meta.
* @return bool
*/
public static function is_wordpress_upload( $path, $source ) {
if ( 'upload' === $source ) {
return true;
}

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

return '' === $source && '' !== $path && ! rtgodam_is_transcoder_file_url( $path );
Comment thread
subodhr258 marked this conversation as resolved.
Resolved
}

/**
* Point the attachment's cached transcript (`rtgodam_transcript_path`) at
* the default caption track Central reports, so the editor's Transcription
Expand Down Expand Up @@ -857,9 +895,9 @@ public static function sync_cached_transcript( $attachment_id, $captions, $switc
do_action( 'rtgodam_before_attachment_lookup' );
}
delete_post_meta( $attachment_id, self::DELETED_META );
if ( 'upload' !== get_post_meta( $attachment_id, self::SOURCE_META, true ) ) {
$cached_path = (string) get_post_meta( $attachment_id, 'rtgodam_transcript_path', true );
if ( ! self::is_wordpress_upload( $cached_path, get_post_meta( $attachment_id, self::SOURCE_META, true ) ) ) {
update_post_meta( $attachment_id, self::CHECKED_META, time() );
$cached_path = (string) get_post_meta( $attachment_id, 'rtgodam_transcript_path', true );
if ( '' !== $default_path ) {
update_post_meta( $attachment_id, 'rtgodam_transcript_path', $default_path );
update_post_meta( $attachment_id, self::STATUS_META, 'Transcribed' );
Expand Down Expand Up @@ -906,7 +944,10 @@ public static function refresh_cached_default( $attachment_id ) {
/** This action is documented in inc/classes/rest-api/class-transcription.php */
do_action( 'rtgodam_before_attachment_lookup' );
$is_deleted = (bool) get_post_meta( $attachment_id, self::DELETED_META, true );
$is_upload = 'upload' === get_post_meta( $attachment_id, self::SOURCE_META, true );
$is_upload = self::is_wordpress_upload(
get_post_meta( $attachment_id, 'rtgodam_transcript_path', true ),
get_post_meta( $attachment_id, self::SOURCE_META, true )
);
$job_id = get_post_meta( $attachment_id, 'rtgodam_transcoding_job_id', true );
if ( empty( $job_id ) ) {
$job_id = get_post_meta( $attachment_id, '_godam_original_id', true );
Expand Down
4 changes: 4 additions & 0 deletions inc/templates/godam-player.php
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,10 @@ function ( $godam_layer ) {
$godam_transcript_url = (string) ( $godam_attachment_data['transcript_path'] ?? '' );
$godam_transcript_deleted = ! empty( $godam_attachment_data['transcript_deleted'] );
$godam_transcript_source = (string) ( $godam_attachment_data['transcript_source'] ?? '' );
// An upload from before 2.8.0 carries no source mark; recognise it by its address.
if ( \RTGODAM\Inc\REST_API\Transcription::is_wordpress_upload( $godam_transcript_url, $godam_transcript_source ) ) {
$godam_transcript_source = 'upload';
}

$godam_attachment_title = '';

Expand Down
42 changes: 21 additions & 21 deletions languages/godam.pot
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ msgstr ""
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"POT-Creation-Date: 2026-11-09T12:09:21+00:00\n"
"POT-Creation-Date: 2026-11-10T09:05:46+00:00\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"X-Generator: WP-CLI 2.12.0\n"
"X-Domain: godam\n"
Expand Down Expand Up @@ -14023,83 +14023,83 @@ msgstr ""
msgid "%1$s (ID %2$d) transcoding request was sent successfully"
msgstr ""

#: inc/classes/rest-api/class-transcription.php:161
#: inc/classes/rest-api/class-transcription.php:171
msgid "The video attachment ID."
msgstr ""

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

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

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

#: inc/classes/rest-api/class-transcription.php:234
#: inc/classes/rest-api/class-transcription.php:244
msgid "URL of the uploaded .vtt / .srt caption file."
msgstr ""

#: inc/classes/rest-api/class-transcription.php:309
#: inc/classes/rest-api/class-transcription.php:319
msgid "BCP 47 language tag for the caption track."
msgstr ""

#: inc/classes/rest-api/class-transcription.php:317
#: inc/classes/rest-api/class-transcription.php:327
msgid "Label shown in the subtitle menu. Unique on the video."
msgstr ""

#: inc/classes/rest-api/class-transcription.php:324
#: inc/classes/rest-api/class-transcription.php:334
msgid "Track kind: subtitles or captions."
msgstr ""

#: inc/classes/rest-api/class-transcription.php:330
#: inc/classes/rest-api/class-transcription.php:340
msgid "Make this the default caption track."
msgstr ""

#: inc/classes/rest-api/class-transcription.php:340
#: inc/classes/rest-api/class-transcription.php:350
msgid "Caption file text (VTT or SRT)."
msgstr ""

#: inc/classes/rest-api/class-transcription.php:349
#: inc/classes/rest-api/class-transcription.php:359
msgid "Format of the uploaded caption text."
msgstr ""

#: inc/classes/rest-api/class-transcription.php:367
#: inc/classes/rest-api/class-transcription.php:377
msgid "Caption track handle returned by the list endpoint."
msgstr ""

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

#: inc/classes/rest-api/class-transcription.php:510
#: inc/classes/rest-api/class-transcription.php:520
msgid "Connect your GoDAM account to generate transcriptions."
msgstr ""

#: inc/classes/rest-api/class-transcription.php:543
#: inc/classes/rest-api/class-transcription.php:553
msgid "Could not reach the transcription service. Please try again."
msgstr ""

#: inc/classes/rest-api/class-transcription.php:609
#: inc/classes/rest-api/class-transcription.php:621
msgid "Only .vtt or .srt caption files are supported."
msgstr ""

#: inc/classes/rest-api/class-transcription.php:1054
#: inc/classes/rest-api/class-transcription.php:1095
msgid "Connect your GoDAM account to manage captions."
msgstr ""

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

#: inc/classes/rest-api/class-transcription.php:1107
#: inc/classes/rest-api/class-transcription.php:1148
msgid "Could not reach the caption service. Please try again."
msgstr ""

#: inc/classes/rest-api/class-transcription.php:1128
#: inc/classes/rest-api/class-transcription.php:1169
msgid "The caption service rejected the request."
msgstr ""

Expand Down
36 changes: 25 additions & 11 deletions tests/php/TranscriptionCaptionRefreshTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected function setUp(): void {
$GLOBALS['rtgodam_stub'] = array(
'post_meta' => array(
'rtgodam_transcoding_job_id' => 'job-1',
'rtgodam_transcript_path' => 'https://cdn.example/job/en.vtt',
'rtgodam_transcript_path' => 'https://n8e0ka87m9.gdcdn.us/job/en.vtt',
),
'options' => array( 'rtgodam-api-key' => 'key' ),
'scheduled' => array(),
Expand Down Expand Up @@ -62,12 +62,12 @@ private function central_default_is_spanish() {
'captions' => array(
array(
'language' => 'en',
'vtt_path' => 'https://cdn.example/job/en.vtt',
'vtt_path' => 'https://n8e0ka87m9.gdcdn.us/job/en.vtt',
'is_default' => false,
),
array(
'language' => 'es',
'vtt_path' => 'https://cdn.example/job/es.vtt',
'vtt_path' => 'https://n8e0ka87m9.gdcdn.us/job/es.vtt',
'is_default' => true,
),
),
Expand All @@ -88,7 +88,7 @@ public function test_follows_a_default_changed_in_central() {
$this->assertTrue( Transcription::refresh_cached_default( 7 ) );

$meta = $GLOBALS['rtgodam_stub']['post_meta'];
$this->assertSame( 'https://cdn.example/job/es.vtt', $meta['rtgodam_transcript_path'] );
$this->assertSame( 'https://n8e0ka87m9.gdcdn.us/job/es.vtt', $meta['rtgodam_transcript_path'] );
$this->assertGreaterThan( time() - 5, $meta[ Transcription::CHECKED_META ] );
$this->assertStringEndsWith( 'godam_core.api.captions.list_captions', $GLOBALS['rtgodam_stub']['posts'][0]['url'] );
}
Expand All @@ -109,7 +109,21 @@ public function test_leaves_uploads_and_deletes_alone( $key, $value ) {
$this->assertFalse( Transcription::refresh_cached_default( 7 ) );

$this->assertSame( array(), $GLOBALS['rtgodam_stub']['posts'] );
$this->assertSame( 'https://cdn.example/job/en.vtt', $GLOBALS['rtgodam_stub']['post_meta']['rtgodam_transcript_path'] );
$this->assertSame( 'https://n8e0ka87m9.gdcdn.us/job/en.vtt', $GLOBALS['rtgodam_stub']['post_meta']['rtgodam_transcript_path'] );
}

/**
* An upload from before 2.8.0 carries no source mark. Its address is not
* on Central's CDN, so Central is not asked and the file stays.
*/
public function test_leaves_an_unmarked_upload_from_before_2_8_alone() {
$GLOBALS['rtgodam_stub']['post_meta']['rtgodam_transcript_path'] = 'https://site.example/wp-content/uploads/fixed.vtt';
$this->central_default_is_spanish();

$this->assertFalse( Transcription::refresh_cached_default( 7 ) );

$this->assertSame( array(), $GLOBALS['rtgodam_stub']['posts'] );
$this->assertSame( 'https://site.example/wp-content/uploads/fixed.vtt', $GLOBALS['rtgodam_stub']['post_meta']['rtgodam_transcript_path'] );
}

/**
Expand Down Expand Up @@ -154,7 +168,7 @@ public function test_keeps_the_cache_when_the_default_has_no_file() {
array(
array(
'language' => 'en',
'vtt_path' => 'https://cdn.example/job/en.vtt',
'vtt_path' => 'https://n8e0ka87m9.gdcdn.us/job/en.vtt',
'is_default' => false,
),
array(
Expand All @@ -167,7 +181,7 @@ public function test_keeps_the_cache_when_the_default_has_no_file() {
);

$this->assertTrue( Transcription::refresh_cached_default( 7 ) );
$this->assertSame( 'https://cdn.example/job/en.vtt', $GLOBALS['rtgodam_stub']['post_meta']['rtgodam_transcript_path'] );
$this->assertSame( 'https://n8e0ka87m9.gdcdn.us/job/en.vtt', $GLOBALS['rtgodam_stub']['post_meta']['rtgodam_transcript_path'] );
}

/**
Expand All @@ -176,12 +190,12 @@ public function test_keeps_the_cache_when_the_default_has_no_file() {
* transcript is still the same file and stays.
*/
public function test_keeps_a_signed_cache_when_the_default_has_no_file() {
$GLOBALS['rtgodam_stub']['post_meta']['rtgodam_transcript_path'] = 'https://cdn.example/job/en.vtt?token=A&expires=1';
$GLOBALS['rtgodam_stub']['post_meta']['rtgodam_transcript_path'] = 'https://n8e0ka87m9.gdcdn.us/job/en.vtt?token=A&expires=1';
$this->central_lists(
array(
array(
'language' => 'en',
'vtt_path' => 'https://cdn.example/job/en.vtt?token=B&expires=2',
'vtt_path' => 'https://n8e0ka87m9.gdcdn.us/job/en.vtt?token=B&expires=2',
'is_default' => false,
),
array(
Expand All @@ -194,7 +208,7 @@ public function test_keeps_a_signed_cache_when_the_default_has_no_file() {
);

$this->assertTrue( Transcription::refresh_cached_default( 7 ) );
$this->assertSame( 'https://cdn.example/job/en.vtt?token=A&expires=1', $GLOBALS['rtgodam_stub']['post_meta']['rtgodam_transcript_path'] );
$this->assertSame( 'https://n8e0ka87m9.gdcdn.us/job/en.vtt?token=A&expires=1', $GLOBALS['rtgodam_stub']['post_meta']['rtgodam_transcript_path'] );
}

/**
Expand Down Expand Up @@ -250,7 +264,7 @@ public function test_keeps_the_cache_when_central_fails() {
};

$this->assertFalse( Transcription::refresh_cached_default( 7 ) );
$this->assertSame( 'https://cdn.example/job/en.vtt', $GLOBALS['rtgodam_stub']['post_meta']['rtgodam_transcript_path'] );
$this->assertSame( 'https://n8e0ka87m9.gdcdn.us/job/en.vtt', $GLOBALS['rtgodam_stub']['post_meta']['rtgodam_transcript_path'] );
}

/**
Expand Down
Loading
Loading