<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xml:base="http://labs.echoditto.com" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
 <title>EchoDitto Labs - Using Blip.tv With FeedAPI - Comments</title>
 <link>http://labs.echoditto.com/feedapi-and-bliptv</link>
 <description>Comments for &quot;Using Blip.tv With FeedAPI&quot;</description>
 <language>en</language>
<item>
 <title>That empty array index is</title>
 <link>http://labs.echoditto.com/feedapi-and-bliptv#comment-3943</link>
 <description>&lt;p&gt;That empty array index is actually a namespace URL... for RSS 2.0. Since RSS 2.0 doesn&#039;t have a namespace, and SimplePie does a lot of indexing with namespaces, that&#039;s just how it ended up coming out. :(&lt;/p&gt;
</description>
 <pubDate>Sat, 03 May 2008 12:48:42 -0700</pubDate>
 <dc:creator>Ryan Parman</dc:creator>
 <guid isPermaLink="false">comment 3943 at http://labs.echoditto.com</guid>
</item>
<item>
 <title>Thanks for the thoughtful</title>
 <link>http://labs.echoditto.com/feedapi-and-bliptv#comment-3910</link>
 <description>&lt;p&gt;Thanks for the thoughtful reply, Ryan.  I don&#039;t mean to just bitch about SimplePie, although I&#039;m sure that&#039;s how it came off -- SP really is a great project.  And in fact the sanitization I complained about is not happening in SimplePie: it&#039;s definitely Drupal that&#039;s killing the data somewhere along the way.&lt;/p&gt;
&lt;p&gt;It&#039;s interesting to hear that the custom tag data is already available in the [data] object of... the parser?  I definitely did a print_r on the item objects, and thought I probably would&#039;ve done the same for the parser.  Perhaps I forgot to.  It&#039;s definitely not available in the item object, though, which seems like the logical place for it.&lt;/p&gt;
&lt;p&gt;In any case, I do have to stick by my complaint about the variability of the data structures returned by the custom-tag-grabbing routine, particularly when retrieving an item with nested subelements.  Check out how you access an FLV included by the widely-supported MediaRSS namespace:&lt;/p&gt;
&lt;p&gt;$item[0][&#039;child&#039;][&#039;http://search.yahoo.com/mrss/&#039;][&#039;content&#039;][0][&#039;attribs&#039;][&#039;&#039;][&#039;url&#039;]&lt;/p&gt;
&lt;p&gt;Using an empty string to index an array is pretty awful.  Ick.&lt;/p&gt;
</description>
 <pubDate>Mon, 24 Mar 2008 09:07:31 -0700</pubDate>
 <dc:creator>Tom</dc:creator>
 <guid isPermaLink="false">comment 3910 at http://labs.echoditto.com</guid>
</item>
<item>
 <title>&quot;This is SimplePie&#039;s fault.</title>
 <link>http://labs.echoditto.com/feedapi-and-bliptv#comment-3909</link>
 <description>&lt;p&gt;&lt;cite&gt;&quot;This is SimplePie&#039;s fault. Rather than simply walking the XML structure of the feed and throwing it all into data structures, SimplePie decides it&#039;s smarter than the feed author. If you want an item attribute from a custom RSS namespace, you have to ask for it.&quot;&lt;/cite&gt;&lt;/p&gt;
&lt;p&gt;Or, you could walk the data structure, which is stored in the SimplePie::data property. The API methods are just a simplified way of accessing more commonly used/requested data.&lt;/p&gt;
&lt;p&gt;&lt;cite&gt;&quot;...the data structures returned by SimplePie vary pretty wildly by tag.&quot;&lt;/cite&gt;&lt;/p&gt;
&lt;p&gt;I could be mistaken, but if you&#039;re talking about the data structures that map to the XML, we have a consistent format for noting the XML attributes and child data. In particular, Media RSS is not as clear a spec as I&#039;d hoped, the spec was broken for over a year, and there are numerous sites implementing both correct and broken Media RSS all over the web. We&#039;ve done our best to normalize this data so that our users don&#039;t have to do as much hacking. Some of the things you&#039;re trying to do might be simpler if you used SimplePie&#039;s enclosure-related methods which normalize data between RSS enclosures, Media RSS, and iTunes RSS. &lt;/p&gt;
&lt;p&gt;&lt;cite&gt;&quot;Worse, somewhere along the line ... the data is sanitized and some tags are stripped, making it necessary to urlencode() fields like the video embed tag.&quot;&lt;/cite&gt;&lt;/p&gt;
&lt;p&gt;By default SimplePie does sanitize data and strip out potentially &quot;dangerous&quot; tags and attributes, as per suggestions from Mark Pilgrim on how to consume RSS safely . This sanitization can be turned off pretty simply using a SimplePie config option, and I believe that the guys who do Drupal&#039;s SimpleFeed module do this and use Drupal&#039;s internal sanitizer instead.&lt;/p&gt;
&lt;p&gt;In the end, we have a support forum/list as well as an IRC chat available for asking these very kinds of questions, and complete API documentation in our wiki. We probably could have answered your questions relatively quickly and saved you some headache. :)&lt;/p&gt;
</description>
 <pubDate>Sun, 23 Mar 2008 21:37:09 -0700</pubDate>
 <dc:creator>Ryan Parman</dc:creator>
 <guid isPermaLink="false">comment 3909 at http://labs.echoditto.com</guid>
</item>
<item>
 <title>Using Blip.tv With FeedAPI</title>
 <link>http://labs.echoditto.com/feedapi-and-bliptv</link>
 <description>&lt;p&gt;Yesterday &lt;a href=&quot;http://www.developmentseed.org&quot;&gt;Development Seed&lt;/a&gt; was kind enough to give Chris &amp;amp; me a rundown of &lt;a href=&quot;http://groups.drupal.org/soc-2008&quot;&gt;how the Drupal community is organizing its participation&lt;/a&gt; in the &lt;a href=&quot;http://code.google.com/soc/2008/&quot;&gt;Google Summer of Code&lt;/a&gt; program.  Along the way I got a chance to chat with Alex and Ian about FeedAPI and FeedAPI Mapper, two excellent projects that DevSeed ushered into being through last year&#039;s Summer of Code and now continues to maintain and extend.&lt;/p&gt;

&lt;p&gt;I&#039;ve just begun using &lt;a href=&quot;http://drupal.org/project/feedapi&quot;&gt;FeedAPI&lt;/a&gt; for the first time in a project destined for production, and so far I&#039;m very pleased with it.  It offers a more fully-considered alternative to aggregator.module &amp;mdash; and with the addition of the optional &lt;a href=&quot;http://drupal.org/project/feedapi_mapper&quot;&gt;Mapper&lt;/a&gt; module it becomes simple to turn aggregated RSS items into Drupal nodes, with the items&#039; attributes stuck in whatever CCK fields you care to create.  It&#039;s really slick.&lt;/p&gt;

&lt;p&gt;In my case I&#039;m using it as an integration point for &lt;a href=&quot;http://www.blip.tv&quot;&gt;Blip.tv&lt;/a&gt;.  Our client needs video capabilities, but I saw no reason why we should mess around with transcoding, customizing an FLV player and all the rest of the headaches that come with web video (been there, &lt;a href=&quot;http://labs.echoditto.com/heywatch-and-cck&quot;&gt;done that&lt;/a&gt;).  Blip does all of that stuff very well, and has social features baked in, too.  I&#039;d rather just have the client upload their videos there, then count on FeedAPI to turn them into nodes that can be exposed through Views.  Any configuration that we can&#039;t get from the Blip RSS feed can be manually handled by an editor &amp;mdash; &lt;a href=&quot;http://drupal.org/project/workflow_ng&quot;&gt;Workflow-NG&lt;/a&gt; fires off a &quot;please come edit and publish me!&quot; email whenever a new video node is created.&lt;/p&gt;

&lt;p&gt;But there&#039;s an awful lot of data available in the Blip RSS feed.  In addition to things like tags and titles there&#039;s the source FLV, the embed code for the flash player, the video&#039;s runtime and the thumbnail graphic URL (if any).  The problem was that the SimplePie parser module included with FeedAPI wasn&#039;t picking any of these attributes up.&lt;/p&gt;

&lt;p&gt;This is SimplePie&#039;s fault.  Rather than simply walking the XML structure of the feed and throwing it all into data structures, SimplePie decides it&#039;s smarter than the feed author.  If you want an item attribute from a custom RSS namespace, &lt;a href=&quot;http://simplepie.org/wiki/tutorial/grab_custom_tags_or_attributes&quot;&gt;you have to ask for it&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Right now, there&#039;s not a good way to do this.  The good news, though, is that the DevSeed guys are aware of this limitation and are thinking hard about how future versions of SimplePie should be designed to accommodate custom feed item attributes.  I&#039;m hopeful that I&#039;ll be able to contribute to that effort, but unfortunately it&#039;s one that involves larger questions about FeedAPI&#039;s architecture and place in the Drupal project.  It&#039;s not something that&#039;s going to be fixed right away, in other words.&lt;/p&gt;

&lt;p&gt;But I was on a deadline, so a stopgap was in order.  What to do?  I could try to add to the hooks exposed by the parser_simplepie submodule.  But that would be adding a module system to a module system employed by a module.  That&#039;s a pretty deep rabbit hole.  Besides, it&#039;s a lot of work that would probably be discarded in favor of something smarter by the bright folks maintaining the project.  And this is just a one-off requirement.&lt;/p&gt;

&lt;p&gt;Next I considered adding a configuration page to the parser_simplepie module, where a user could specify the namespaces and tags that they&#039;d like retrieved for each feed item.  But this is a no-go: the data structures returned by SimplePie vary pretty wildly by tag.  Worse, somewhere along the line (CCK? I haven&#039;t looked) the data is sanitized and some tags are stripped, making it necessary to urlencode() fields like the video embed tag.  Yeah, you could include a block for eval&#039;ed PHP on the aforementioned settings page.  But at that point, what are you really buying yourself?  You&#039;ll still need expert knowledge to use it.  At that point the difference between putting the code in an admin page or in the module basically winds up being that, in the case of the former, a curious administrator can accidentally break things.&lt;/p&gt;

&lt;p&gt;So, reluctantly, I ended up forking parser_simplepie and adding the following custom code to _parser_simplepie_feedapi_parse().  If you&#039;re trying to use Blip, maybe you&#039;ll find it useful (I&#039;ve also included a patch).  It grabs the video embed code, source FLV, graphic, runtime and description (the standard RSS description field gets the player stuffed into it, too; this way you don&#039;t have to strip it out yourself).  In the case of the graphic it actually downloads the file if it hasn&#039;t already &amp;mdash; handy if you&#039;re going to have to make thumbnails out of it with imagecache.  Of course for performance reasons this also means that if you need to update the graphic you&#039;ll need to make sure the new version you send to Blip has a unique filename &amp;mdash; a little hacky, I know.  A better solution would be to patch imagecache so that it can handle remote files, periodically redownloading and examining their md5&#039;s on the cron to determine if the local copy of the source file needs to be refreshed.  But that&#039;s a topic for another blog post.&lt;/p&gt;

&lt;blockquote&gt;&lt;pre&gt;
// BEGIN blip.tv-specific attribute-grabbing

// flv
if($tag_media = $simplepie_item-&amp;gt;get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS,&#039;group&#039;))
	$curr_item-&amp;gt;options-&amp;gt;mediarss_flv = $tag_media[0][&#039;child&#039;][&#039;http://search.yahoo.com/mrss/&#039;][&#039;content&#039;][0][&#039;attribs&#039;][&#039;&#039;][&#039;url&#039;];		

// player code
if($tag_media = $simplepie_item-&amp;gt;get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS,&#039;player&#039;))
	$curr_item-&amp;gt;options-&amp;gt;mediarss_player = urlencode($tag_media[0][&#039;data&#039;]);

// runtime
if($tag_media = $simplepie_item-&amp;gt;get_item_tags(&#039;http://blip.tv/dtd/blip/1.0&#039;,&#039;runtime&#039;))
	$curr_item-&amp;gt;options-&amp;gt;bliptv_runtime = intval($tag_media[0][&#039;data&#039;]);

// pure description
if($tag_media = $simplepie_item-&amp;gt;get_item_tags(&#039;http://blip.tv/dtd/blip/1.0&#039;,&#039;puredescription&#039;))
	$curr_item-&amp;gt;options-&amp;gt;bliptv_puredescription = intval($tag_media[0][&#039;data&#039;]);
	
// thumbnail
if($tag_media = $simplepie_item-&amp;gt;get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS,&#039;thumbnail&#039;))
{
	$curr_item-&amp;gt;options-&amp;gt;mediarss_thumbnail_remote = $tag_media[0][&#039;attribs&#039;][&#039;&#039;][&#039;url&#039;];
	$file_dst = preg_replace(&#039;/[^\w\.\-]/&#039;,&#039;_&#039;,str_replace(&#039;http://&#039;,&#039;&#039;,$curr_item-&amp;gt;options-&amp;gt;mediarss_thumbnail_remote));
	$d = file_directory_path() . &#039;/feedapi&#039;;
	if(!file_exists($d))
		mkdir($d);
	if(file_check_directory($d))
	{
		$file_dst = file_create_filename($file_dst,$d);
		if(!file_exists($file_dst))
			if($file_data = file_get_contents($curr_item-&amp;gt;options-&amp;gt;mediarss_thumbnail_remote))
				$file_dst = file_save_data($file_data,$file_dst,FILE_EXISTS_RENAME);
	}
	if(file_exists($file_dst))
		$curr_item-&amp;gt;options-&amp;gt;mediarss_thumbnail_local = $file_dst;
}		

// END blip.tv
&lt;/pre&gt;&lt;/blockquote&gt;

</description>
 <comments>http://labs.echoditto.com/feedapi-and-bliptv#comments</comments>
 <category domain="http://labs.echoditto.com/taxonomy/term/167">bliptv</category>
 <category domain="http://labs.echoditto.com/taxonomy/term/169">developmentseed</category>
 <category domain="http://labs.echoditto.com/taxonomy/term/46">drupal</category>
 <category domain="http://labs.echoditto.com/taxonomy/term/166">feedapi</category>
 <category domain="http://labs.echoditto.com/taxonomy/term/168">namespace</category>
 <category domain="http://labs.echoditto.com/taxonomy/term/17">rss</category>
 <category domain="http://labs.echoditto.com/taxonomy/term/20">simplepie</category>
 <category domain="http://labs.echoditto.com/taxonomy/term/44">xml</category>
 <enclosure url="http://labs.echoditto.com/files/parser_simplepie-bliptv.patch" length="2099" type="application/octet-stream" />
 <pubDate>Fri, 21 Mar 2008 08:42:22 -0700</pubDate>
 <dc:creator>Tom</dc:creator>
 <guid isPermaLink="false">68 at http://labs.echoditto.com</guid>
</item>
</channel>
</rss>
