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 #296

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
970ef51
refactor: update dependencies and webpack configuration to modern sta…
pranvinit Nov 8, 2024
3c83e8a
feature: add rt-player block
pranvinit Nov 8, 2024
319757b
fix: add dynamic video type in save.js
pranvinit Nov 8, 2024
ec4b1dc
enhance: add post meta transcoded url as video source and fallback to…
pranvinit Nov 12, 2024
0b7ded9
feature: add meta field for transcoded URL and option to toggle it
pranvinit Nov 13, 2024
9ad669d
fix: phpcs comments
pranvinit Nov 13, 2024
59ab2b9
chore: remove build from phpcs
pranvinit Nov 13, 2024
aed778d
enhance: extend webpack config to minify admin scripts and styles
pranvinit Nov 14, 2024
58fc8eb
feature: add real-time transcoding progress to media uploads
pranvinit Nov 18, 2024
54095d7
enhance: add progress count and show progress bar for existing media
pranvinit Nov 18, 2024
1db432e
fix: empty progress bar on page load
pranvinit Nov 19, 2024
3ca7e25
fix: make meta field publicly queryable
pranvinit Nov 19, 2024
5cb6b57
fix: frontend quality selector not working
pranvinit Nov 20, 2024
9808a21
feature: add watermark settings for paid users
pranvinit Nov 20, 2024
4e03d60
feature: add support for image watermarks
pranvinit Nov 21, 2024
f4fa7f8
fix: has_access var and scripts enqueue
pranvinit Nov 22, 2024
1e1ee7b
Update the watermark checkbox UI and move the admin page under media …
Nov 25, 2024
ca062ee
Pass the ABS and watermark argument on wp_media_transcoding request
Nov 26, 2024
b5cff1e
Implement the responisve media player block called EasyDAM Player usi…
Nov 29, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/phpcs_on_pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- name: Run PHPCS inspection
uses: rtCamp/action-phpcs-code-review@master
env:
SKIP_FOLDERS: "tests,.github"
SKIP_FOLDERS: "tests,.github,assets/build"
GH_BOT_TOKEN: ${{ secrets.RTBOT_TOKEN }}
with:
args: WordPress,WordPress-Core,WordPress-Docs
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
20 changes: 20 additions & 0 deletions admin/css/rt-progress-bar.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.transcoder-progress-bar {
position: absolute;
left: 0;
right: 0;
bottom: -10px;
height: 10px;
background: rgba(0, 0, 0, 0.1);
}
.transcoder-progress-bar .progress {
height: 100%;
background: #21759b;
transition: width 0.3s ease;
display: flex;
align-items: center;
justify-content: flex-end;
}

.transcoder-progress-bar .progress .progress-text {
color: #fff;
}
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.

99 changes: 99 additions & 0 deletions admin/js/rt-transcoder-uploader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
(function($) {
$(document).ready(function() {
if (typeof wp === 'undefined' || typeof wp.Uploader === 'undefined') {
console.error('wp.Uploader is not available.');
return;
}

const progressBars = new Map();

// Check for existing video files in the media library.
setTimeout(checkExistingVideoProgress, 500);

// Listen for new files added to the queue.
wp.Uploader.queue.on('add', function(file) {
wp.Uploader.queue.on('reset', function() {
// Only show progress bar for video files.
if (file.attributes.type !== 'video') return;

attachmentId = file.id;
initializeProgressBar(attachmentId);
});
});

/**
* Initialize progress bar for the given attachment.
*
* @param {number} attachmentId
*/
function initializeProgressBar(attachmentId) {
const progressBar = $(
`<div class="transcoder-progress-bar" style="display: none;">
<div class="progress" style="width: 0%;">
<span class="progress-text">0%</span>
</div>
</div>`
);

const mediaItemPreview = $(`.attachments .attachment[data-id="${attachmentId}"] .attachment-preview`);
if (!mediaItemPreview.length) return;

mediaItemPreview.append(progressBar);
progressBars.set(attachmentId, progressBar);
monitorProgress(attachmentId);
}


/**
* Check for existing video files in the media.
*
*/
function checkExistingVideoProgress() {
const videoQuery = wp.media.query({
type: 'video',
posts_per_page: -1,
});

videoQuery.more().done(function() {
const videoAttachments = videoQuery.models;
videoAttachments.forEach(function(attachment) {
const attachmentId = attachment.id;
initializeProgressBar(attachmentId);
})
});
}


/**
* Monitor the transcoding progress of the given attachment.
*
* @param {number} attachmentId
*/
function monitorProgress(attachmentId) {
const progressBar = progressBars.get(attachmentId);
if (!progressBar) return;

$.ajax({
url: `${transcoderSettings.restUrl}/${attachmentId}`,
method: 'GET',
beforeSend: xhr => xhr.setRequestHeader('X-WP-Nonce', transcoderSettings.nonce),
success: function(data) {
const progress = parseFloat(data.progress) || 0;
progressBar.show();
progressBar.find('.progress').css('width', `${progress}%`);
progressBar.find('.progress-text').text(`${progress}%`);

if (progress < 100) {
setTimeout(() => monitorProgress(attachmentId), 5000);
} else {
progressBar.remove();
progressBars.delete(attachmentId);
}
},
error: function() {
setTimeout(() => monitorProgress(attachmentId), 5000);
}
});
}
});
})(jQuery);
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
79 changes: 79 additions & 0 deletions admin/rt-transcoder-actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,82 @@ 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( 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' );
// }
pranvinit marked this conversation as resolved.
Show resolved Hide resolved

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;
// }
pranvinit marked this conversation as resolved.
Show resolved Hide resolved

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 );

/**
* Register the transcoded URL meta field.
*/
function register_rt_transcoded_url_meta() {
register_post_meta(
'attachment',
'_rt_transcoded_url',
array(
'type' => 'string',
'single' => true,
'show_in_rest' => true,
'auth_callback' => function () {
return current_user_can( 'edit_posts' );
},
)
);
}
add_action( 'init', 'register_rt_transcoded_url_meta' );
Loading
Loading