Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add transcoded url meta #295

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
35 changes: 0 additions & 35 deletions .babelrc

This file was deleted.

1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
**/*.build.js
**/node_modules/**
**/vendor/**
assets/**
build
node_modules
Gruntfile.js
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ sftp-config.json
*.sublime-workspace
.editorconfig
.cache/
package-lock.json
12 changes: 9 additions & 3 deletions admin/css/rt-transcoder-admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,14 @@
.transcoder-setting-form .form-table td {
font-size: 13px;
padding: 0 0 5px;
vertical-align: top;
}
display: inline-flex;
align-items: center;
flex-wrap: wrap;

& > p {
margin: 0;
}
}

.rtm-button-container {
margin-left: -20px;
Expand Down Expand Up @@ -167,7 +173,7 @@
.transcoder-setting-form .dashicons-info {
color: #aaa;
font-size: 14px;
height: 26px;
height: 100%;
line-height: 14px;
position: relative;
}
Expand Down
3 changes: 2 additions & 1 deletion admin/css/rt-transcoder-admin.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions admin/partials/rt-transcoder-admin-display.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,33 @@
</span>
</td>
</tr>
<tr valign="top">
<td scope="row">
<?php esc_html_e( 'Enable Adaptive Bitrate Streaming', 'transcoder' ); ?>
</td>
<td>
<?php
$rtt_enable_adaptive_bitrate = get_option( 'rtt_adaptive_bitrate_streaming', false );

// Check if the user has an active paid subscription.
$usage_details = get_site_option( 'rt-transcoding-usage' );
$has_access = isset( $usage_details[ $this->api_key ]->sub_status ) && $usage_details[ $this->api_key ]->sub_status;
?>
<input type="checkbox" name="rtt_adaptive_bitrate_streaming" value="1" <?php checked( $rtt_enable_adaptive_bitrate, 1 ); ?> <?php disabled( ! $has_access ); ?> />
<span class="rtm-tooltip">
<i class="dashicons dashicons-info" style="padding-top:3px"></i>
<span class="rtm-tip">
<?php
esc_html_e( 'If enabled, Transcoder will generate multiple video files with different bitrates for adaptive streaming. This will improve video streaming performance on slow internet connections.', 'transcoder' );
?>
</span>
</span>
<?php if ( ! $has_access ) : ?>
<br/>
<p class="description"><?php esc_html_e( 'This feature is available for paid members only.', 'transcoder' ); ?></p>
<?php endif; ?>
</td>
</tr>
</table>
<p>
<?php
Expand Down
60 changes: 60 additions & 0 deletions admin/rt-transcoder-actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,63 @@ function rtt_update_wp_media_thumbnail( $thumb_url, $attachment_id ) {
}

add_action( 'transcoded_thumb_added', 'rtt_update_wp_media_thumbnail', 10, 2 );

/**
* Add a field for the transcoded URL to the media attachment edit screen.
*
* @param array $form_fields An array of attachment form fields.
* @param object $post The attachment post object.
* @return array The modified array of attachment form fields.
*/
function add_transcoded_url_field( $form_fields, $post ) {
$transcoded_url = get_post_meta( $post->ID, '_rt_transcoded_url', true );

// Check if adaptive bitrate streaming is enabled.
$adaptive_bitrate_enabled = get_option( 'rtt_adaptive_bitrate_streaming', false );

// Add the transcoded URL field.
$form_fields['transcoded_url'] = array(
'label' => __( 'Transcoded MPD URL', 'transcoder' ),
'input' => 'html',
'html' => '<input type="text" name="attachments[' . $post->ID . '][transcoded_url]" id="attachments-' . $post->ID . '-transcoded_url" value="' . esc_url( $transcoded_url ) . '" ' . disabled( ! $adaptive_bitrate_enabled, true, false ) . ' />',
'value' => esc_url( $transcoded_url ),
'helps' => __( 'Enter or edit the URL of the transcoded .mpd file stored on Amazon S3.', 'transcoder' ),
);

// Add a note if adaptive bitrate streaming is disabled.
if ( ! $adaptive_bitrate_enabled ) {
$form_fields['transcoded_url']['helps'] = __( 'This feature is available only when adaptive bitrate streaming is enabled.', 'transcoder' );
}

return $form_fields;
}

add_filter( 'attachment_fields_to_edit', 'add_transcoded_url_field', 10, 2 );

/**
* Save the transcoded URL field when the attachment is saved.
*
* @param array $post The post data for the attachment.
* @param array $attachment The attachment data.
* @return array The post data for the attachment.
*/
function save_transcoded_url_field( $post, $attachment ) {
// Check if adaptive bitrate streaming is enabled.
$adaptive_bitrate_enabled = get_option( 'rtt_adaptive_bitrate_streaming', false );
if ( ! $adaptive_bitrate_enabled ) {
return $post;
}

if ( isset( $attachment['transcoded_url'] ) ) {
// Check the user's permissions.
if ( ! current_user_can( 'edit_post', $post['ID'] ) ) {
return $post;
}
// Update the post meta with the new value.
update_post_meta( $post['ID'], '_rt_transcoded_url', esc_url_raw( $attachment['transcoded_url'] ) );
}

return $post;
}

add_filter( 'attachment_fields_to_save', 'save_transcoded_url_field', 10, 2 );
36 changes: 36 additions & 0 deletions admin/rt-transcoder-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,42 @@ public function register_transcoder_settings() {
register_setting( 'rt-transcoder-settings-group', 'number_of_thumbs' );
register_setting( 'rt-transcoder-settings-group', 'rtt_override_thumbnail' );
register_setting( 'rt-transcoder-settings-group', 'rtt_client_check_status_button' );

// Check if the user has an active paid subscription.
$usage_details = get_site_option( 'rt-transcoding-usage' );
$has_access = isset( $usage_details[ $this->api_key ]->sub_status ) && $usage_details[ $this->api_key ]->sub_status;

// Register adaptive bitrate streaming setting with conditional default.
register_setting(
'rt-transcoder-settings-group',
'rtt_adaptive_bitrate_streaming',
array(
'type' => 'boolean',
'description' => __( 'Enable adaptive bitrate streaming for videos.', 'transcoder' ),
'sanitize_callback' => array( $this, 'sanitize_adaptive_bitrate' ),
'default' => $has_access,
)
);
}

/**
* Sanitize adaptive bitrate streaming setting.
*
* @since 1.0.0
*
* @param bool $value The value to sanitize.
* @return bool
*/
public function sanitize_adaptive_bitrate( $value ) {
$usage_details = get_site_option( 'rt-transcoding-usage' );
$has_access = isset( $usage_details[ $this->api_key ]->sub_status ) && $usage_details[ $this->api_key ]->sub_status;

if ( ! $has_access ) {
add_settings_error( 'rt-transcoder-settings-group', 'rtt_adaptive_bitrate_streaming', __( 'You need to have an active subscription to enable adaptive bitrate streaming.', 'transcoder' ), 'error' );
return false;
}

return isset( $value ) && ( '1' === $value || 1 === $value || true === $value );
}

/**
Expand Down
Loading
Loading