NOTE: Assuming YouTube…
In part because of the way the plugin stores data, and also because YouTube has a variety of “creator” URLs, this isn’t going to be very easy, or at least not as simple as spitting out a custom field.
You MIGHT be able to get away with this for some…
<?php
$creator = get_post_meta($post->ID, 'tube_video_creator_name', true);
$url = 'https://www.youtube.com/user/' . $creator;
?>
If you wanted to be really ambitious, you could use the video ID to hit the YouTube API and get the creator’s Channel URL.
Below is sample code that gets the duration and stores it in a custom field for the video, which I’d imagine would be trivial to update to get the creator by revising the stuff starting after the “// extract the duration” comment.
add_action('added_post_meta', 'tube_maybe_get_youtube_duration', 10, 4);
add_action('updated_post_meta', 'tube_maybe_get_youtube_duration', 10, 4);
function tube_maybe_get_youtube_duration( $meta_id, $post_id, $meta_key='', $meta_value='' ){
// Do nothing unless correct key
if ( $meta_key != 'tube_video_site' ) return;
// only applied to youtube
if ( $meta_value != 'youtube' ) return;
// make sure it doesn't have duration already
$has_duration = get_post_meta( $post_id, 'tube_video_duration_hms', true );
if ( $has_duration ) return;
tube_get_youtube_duration( $post_id );
}
function tube_get_youtube_duration( $post_id ){
// get the video ID
$video_id = get_post_meta( $post_id, 'tube_video_id', true );
if ( ! $video_id ) return;
// get the API key
global $tube_video_curator;
$youtube_api_key = $tube_video_curator :: $tube_youtube_videos -> get_youtube_api_key();
if ( ! $youtube_api_key ) return;
// generate the endpoint
$endpoint = add_query_arg(
array(
'part' => 'contentDetails',
'id' => $video_id,
'key' => $youtube_api_key
),
'https://www.googleapis.com/youtube/v3/videos'
);
// get the raw results
$results_json = file_get_contents( $endpoint );
// decode the results
$results = json_decode( $results_json, true );
// extract the duration
$duration = $results['items'][0]['contentDetails']['duration'];
// get the duraton parts
preg_match_all( '/PT(\d+H)?(\d+M)?(\d+S)?/', $duration, $duration_parts );
// create HMS array
$time_hms = array(
'h' => (int) str_replace( 'H', '', $duration_parts[1][0] ),
'm' => (int) str_replace( 'M', '', $duration_parts[2][0] ),
's' => (int) str_replace( 'S', '', $duration_parts[3][0] )
);
// calculate total seconds
$time_total_seconds = ( $time_hms['h'] * 3600 ) + ( $time_hms['m'] * 60 ) + $time_hms['s'];
// update the post meta
add_post_meta( $post_id, 'tube_video_duration_hms', $time_hms );
add_post_meta( $post_id, 'tube_video_duration_seconds', $time_total_seconds );
// all done
return;
}