User login

Using the BlipTV flash video player for Blip.TV videos

Drupal and BlipTV: Using RSS and Xpath anything that works to get the Blip.TV Player

$myFile = "testFile.txt";
$fh = fopen($myFile, 'r');
$theData = fread($fh, filesize($myFile));
fclose($fh);
echo $theData;

<?php
 $foo = system('wget http://www.myserver.com/file.txt ~',$output);
?>

This is what I really want:

// retrieve the file into a string
$file = file_get_contents('http://example.com/file.ext');

$item['embed']
gets me the file path, the kind with the number: http://blip.tv/file/687915/

http://us2.php.net/manual/en/function.xpath-eval.php

$objXP = xpath_new_context($objDom)
$objTest = &xpath_eval($objXP,"//lalala");
$objTest->nodeset[0]->set_attribute("test","test data");

Conclusion: XPath looks a little like hell, but more complicated.

// get dom object
$xmldoc = domxml_open_mem($rss);

// init xpath
$xpath = xpath_new_context($xmldoc);
$xpresult = xpath_eval($xpath, "/rss/channel/item/media:player");

Expected result, php won't have these functions installed, mwahahahahahaha:

Fatal error: Call to undefined function domxml_open_mem() in /var/www/livingcon_test/sites/livingconversations.com/themes/sky/template.php on line 221

http://devzone.zend.com/article/651-PHP-101-part-11-Sinfully-Simple

<?php
// set name of XML file
$file = "pet.xml";

// load file
$xml = simplexml_load_file($file) or die ("Unable to load XML file!");

// access XML data
echo "Name: " . $xml->name . "\n";
echo "Age: " . $xml->age . "\n";
echo "Species: " . $xml->species . "\n";
echo "Parents: " . $xml->parents->mother . " and " .  $xml->parents->father . "\n";
?>

That's more like it!

This is what we're looking for:

<media:player url="http://blip.tv/file/687915"><![CDATA[<embed src="http://blip.tv/play/k2mqri8" type="application/x-shockwave-flash" width="480" height="360" allowscriptaccess="always" allowfullscreen="true" /> ]]> </media:player>

Should just be:

$file = $embed . '?skin=rss';
$xml = simplexml_load_file($file) or die ("Unable to load XML file!");
// print $xml->media:player
print $xml->xpath('/rss/channel/item/media:player');

Putting it all together (turns out the theme function gets the blip url handed to it as $embed)

Wrong output!

It's just giving me a simplexml object with the old numeric path, not ... hmmm

print $xml->media:player;

$file = $embed . '?skin=rss';

$xml = simplexml_load_file(rawurlencode($file)) or die ("Unable to load XML file!");
print $xml->description;

print file_get_contents($file);

/*
print '

';
print_r($xml);
print '

';

print '

';
print_r($xml->xpath('/rss/channel/item/media:player'));
print '

';

print '

';
print_r($xml->xpath('/rss/channel/item/media:content'));
print '

';
*/

Bottom line: nowhere in the SimpleXML parsing of skin is the data I need. It just isn't getting grabbed.

So we turn to the dirtiest of dirty hacks! Running string functions in the theme layer.

Ebony-II:sky ben$ svn commit -m "the whole thing refactored with the dirty hack of PHP string functions. To hell with you, XML."

<?php
function phptemplate_video_cck_bliptv_flash($embed, $width, $height, $field, $item, $autoplay, $flv, $thumbnail) {

/*
print "<p>Develepment code:
<br />embed = $embed
<br />width = $width
<br />height = $height
<br />field = <pre> " . print_r($field, TRUE) . "</pre>
<br />item = <pre> " . print_r($item, TRUE) . "</pre>
<br />autoplay = $autoplay
<br />flv = $flv
<br />thumbnail = $thumbnail
";
/*

  if ($embed) {
    $autoplay = $autoplay ? 'autoStart=true' : 'autoStart=false';
    $output .= '<object type="application/x-shockwave-flash" height="' . $height . '" width="' .$width . '" data="http://blip.tv/scripts/flash/blipplayer.swf?' . $autoplay . '&amp;file=' . $flv . '%3Fsource%3D3"  >
      <param name="movie" value="http://blip.tv/scripts/flash/blipplayer.swf?' . $autoplay . '&amp;file=' . $flv . '%3Fsource%3D3"  />
      <param name="allowScriptAcess" value="always" />
      <param name="allowFullScreen" value="true" />
      <param name="quality" value="high" />
      <param name="bgcolor" value="#FFFFFF" />
      <param name="scale" value="noScale" />
      <param name="salign" value="TL" />
      <param name="wmode" value="transparent" />
    </object>';
  }
*/

// $rss = file_get_contents($embed . '?skin=rss');

/* Here's an example of what we're after:
<media:player url="http://blip.tv/file/687915"><![CDATA[<embed src="http://blip.tv/play/k2mqri8"
*/

$file = $embed . '?skin=rss';
$rss = file_get_contents($file);

$needle = '<media:player url="' . $embed . '"><![CDATA[<embed src="http://blip.tv/play/';
$needle_length = strlen($needle);
// will it always be 7 characters?  k2mqri8
// if not we'll need to use a regular expression

// we know there's a lot of unnecessary stuff in the rss file
// so we can skip the first 2,200 characters or so
$loc = strpos($rss, $needle, 2200);
$playcode = substr($rss, $loc + $needle_length, 7);

// Reconstruct the code now that we have full control

    $output = '<embed src="http://blip.tv/play/' . $playcode . '" type="application/x-shockwave-flash" width="480" height="360" allowscriptaccess="always" allowfullscreen="true" />';

  return $output;
}
?>

That's for historical purposes. In the more condensed form (which will also soon be history) the theme override function looks like this.

Resolution

Overriding the video CCK module's BlipTV viewing options in the theme layer to use the BlipTV provided embed code (way harder to get than it should be!)

<?php
function phptemplate_video_cck_bliptv_flash($embed, $width, $height, $field, $item, $autoplay, $flv, $thumbnail) {

  /* Here's an example of what we're after:
  <media:player url="http://blip.tv/file/687915"><![CDATA[<embed src="http://blip.tv/play/k2mqri8"
  */

  $file = $embed . '?skin=rss';
  $rss = file_get_contents($file);

  $needle = '<media:player url="' . $embed . '"><![CDATA[<embed src="http://blip.tv/play/';
  $needle_length = strlen($needle);
  // will it always be 7 characters?  k2mqri8
  // if not we'll need to use a regular expression

  // we know there's a lot of unnecessary stuff in the rss file
  // so we can skip the first 2,200 characters or so
  $loc = strpos($rss, $needle, 2200);
  $playcode = substr($rss, $loc + $needle_length, 7);

  // Reconstruct the code now that we have full control

    $output = '<embed src="http://blip.tv/play/' . $playcode . '" type="application/x-shockwave-flash" width="480" height="360" allowscriptaccess="always" allowfullscreen="true" />';

  return $output;
}
?>

(Repeat: this is a dirty hack, in so many ways.)

Searched words: 
php xpath php get file in variable php wget file as string

Comments

Video advice

Hi,

I need to embed video on my content pages and there seems to be about 10 different ways to do it in Drupal - swfobject, dash media player, etc, etc.

Do you have any suggestions or advice for a fairly straightforward way to do this. I need to include a poster frame on my flash videos as well.

Thanks,
Phil

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.