Does anyone out there have experience including YouTube videos as enclosures in their RSS feed?
Every now and then I post YouTube videos to various sites and would love to update my feed generation scripts to convert them to enclosures in my feeds.
The RSS 2.0 Specification says that the <enclosure> element "has three required attributes. url says where the enclosure is located, length says how big it is in bytes, and type says what its type is, a standard MIME type."
Setting the url (URL of the YouTube video) and type (application/x-shockwave-flash) attributes is easy, but how do I figure out the correct length in bytes? Can I just put something arbitrary in there and hope that most feed readers are smart enough to grab the content correctly anyway?
I suppose I could do some experimentation, but just 'cause it works or doesn't work in Bloglines doesn't necessarily mean it works or doesn't work in other feed readers.
I'd love to get some advice from anyone who's gone down this path before. Please leave a comment or contact me if comments aren't your cup of tea. Thanks!
Comments
Ian, that's the problem. Right now I include them as (X)HTML as part of the rest of the <item> content. In order to get Bloglines (and presumably other feed readers) to display the video inside the feed reader itself, I apparently need to figure out how to use the <enclosure> method.
One (probably overly complicated) way of doing it is to "wget" whatever movie to see the length. For instance (line breaks added for clarity)
wget --spider http://www.youtube.com/player2.swf?video_id=sdUUx5FdySs
&l=189&t=OEgsToPDskJCyqlKgtkwxzLf-aIx6oxR
&s=E2C6F0E5ACEED150:76A794B33E6DFF0B
returns a size of 23508.
I guess you could actually do it automatically with php using cURL.
// urlSize checks the remote file's header to see what size it is.
function urlSize($url) {
ob_start();
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_NOBODY, 1);
$curlCheck = curl_exec($ch);
curl_close($ch);
$header = ob_get_contents();
ob_end_clean();
$regex = '/Content-Length:s([0-9].+?)s/';
$regexCheck = preg_match($regex, $header, $matches);
return isset($matches[1]) ? $matches[1] : null;
}
?>
Post Comments
If you feel like commenting on the above item, use the form below. Your email address will be used for personal contact reasons only, and will not be shown on this website.
I don't think I've ever seen them done with the enclosure tag. All I've seen is them included in the as CDATA and then the regular html (object tag).
Permalink