An alternative would be to use WordPress’s build in auto embed, the following line in core is responsible for auto embed:
add_filter( 'the_content', array(&$this, 'autoembed'), 8 );
Which means: Whenever we are about to display content try to auto embed all url’s with a priority of 8.
You could add a custom filter before this one to add the youtube url’s, like so:
add_filter( 'the_content', 'prefix_add_youtube_videos', 7 );
function prefix_add_youtube_videos( $content ) {
$video = get_post_meta( get_the_ID(), 'video_url', true );
if ( ! empty( $video ) ) {
$content .= $video;
}
return $content;
}
So we add our function with priority 7 so it’s before WordPress’s auto embed and so WordPress will embed the video for us. That is less code you’ll have to maintain.
PS Embedding is good! Don’t freeboot!