Playing with YouTube feeds

This is a followup to my Simplepie post a while back. YouTube offers Atom feeds, great – you’d think. However the data that YouTube outputs in its Atom feeds is…a bit different to what you might expect from a standard RSS feed in that it contains a lot of escaped HTML. Essentially for each item’s descripton in the feed YouTube outputs something like the following:

<div style="font-size: 12px; margin: 3px 0px;"><span></span></div></td>
<td style="font-size: 11px; line-height: 1.4em; padding-left: 20px;             padding-top: 1px;" width="146" valign="top"><div><span style="color: #666666; font-size: 11px;">From:</span>
<a href="http://www.youtube.com/profile?user=YouTube">YouTube</a></div>
<div><span style="color: #666666; font-size: 11px;">Views:</span>
15774</div>

Which is basically a div that contains a table and is pretty intrusive if included in it’s native form. A rough and ready solution to just getting the bits you want (or at least I want) is to grab each item’s description and echo it via the substr function, this function allows you to specify which parts of a string you want to echo. It did rely a little bit of counting characters and I’m sure that there are far more efficient ways of doing it but if you, say, wanted the screenshot of the video linked to the video’s location on YouTube then your substr function would look something like this:

<?php $description=$item->get_description(); ?>

<?php echo substr($description,113,145); ?>

Which essentially tells the function to starting echoing from character 114 in the string (the count, as always, starts from 0) and to echo out the 145 characters from that point – which is the portion of the string involved in referencing the video’s screenshot and location.

There are a few other ways I can immediately think of using this particular set of data, will post them when I get a minute.

EDIT –

To produce embedded videos from the Atom feed then something like this will work:

<?php $description=$item->get_description(); ?>

<iframe title=”YouTube video player” width=”480″ height=”390″ src=”http://www.youtube.com/embed/<?php echo substr($description,155,11); ?>” frameborder=”0″ allowfullscreen></iframe>

Simplepie and integrating/parsing RSS feeds

Wow, how’s that for a snappy blog title!

Ok, I realise it sounds slightly dull but utilising RSS feeds can be a useful and relatively straight-forward way to include dynamic information within a site.

I’ve searched far and wide for various RSS integration tools and my favourite is by far and away a RSS parsing class written in php called Simplepie (http://simplepie.org/). Although this hasn’t been developed since version 1.2 was released in 2009 it remains the most straightforward and robust solution I’ve found.

Once you’ve downloaded and included the simplepie.inc file it’s so simple (excuse the pun) to use (here is a very good tutorial on how to set up a simple page featuring one feed). If you want to include multiple feeds there is some helpful info here.

But this is the best solution I’ve found to this particular problem – if you’ve got other solutions then please recommend!

Flickr API – what I’ve learnt

I’ve never really paid a huge amount of attention to Flickr, and even less to the Flickr API. I’ve had to rectify this recently as a site I’m working on needs to have an easily updatable slideshow as a fairly prominent element.

Flickr was the platform that we decided to go with to upload the photos to due to the fact it’s pretty nice and easy to use and there are a huge range of pre-existing apps etc that you can exploit to do pretty much anything you can imagine.

Flickr provides a standard way of embedding photos/photostreams, although it is via an i-frame, is fairly clunky and not very customisable – it also looks pretty crap if you want to make it sit with the rest of the site’s design. I explored various methods of calling the relevant photostream to the site via php and the Flickr API but really it was all becoming far more complicated than I suspected it needed to be. If you are a php-lover then the very clever Dan Coulter has written the phpFlickr class to act as a wrapper for the Flickr API and make interacting with it via PHP relatively easy – check it out here http://phpflickr.com/ there is also a very useful-looking tutorial over at Nettuts+ which details how to create a very nice photo gallery using phpFlickr – you can check that out here http://net.tutsplus.com/tutorials/php/how-to-create-a-photo-gallery-using-the-flickr-api/

As I’ve already mentioned all this was looking to be slightly too cumbersome for what I was needing – all I really needed was to be able to call the photostream (perhaps with the option to display photos within that stream with a specific tag) and for the embedded call to be style-able. If there were some nice, sexy transitions etc than that’d be a bonus.

I thought that there would probably be a jQuery-related solution out there, and unsurprisingly there was, loads of them. Once again I came up against solutions that did far more singing and dancing than I would ever need or want. I just wanted a lightweight, simple solution goddamnit – why does everything need to be so bloody complicated!?

Then I stumbled upon flickrshow, “a simple, lightweight javascript slideshow for Flickr”. Only slight problem was that it was still in public beta testing mode so there wasn’t any documentation available. However the demos that they’ve provided give you more than enough of an idea how to use the script and which variables do what. You can check it out here http://www.flickrshow.com/ – it’s absolutely perfect for what I need you can call photos from a particular user, using a particular tag or from a particular photo set and it’s all lightweight, easily customisable and ace. Excellent.

I must stress that there are numerous other Flickr solutions out there, flickrshow just suited my needs and spec – hence me highlighting it. There seems to be a vast range of possibilities using things such as phpFlickr – however I haven’t spent the time looking more closely at these yet as they weren’t required for this project.

But my interest has been piqued so I think that the Flickr API is something I’m going to properly re-visit soon.

Anyways, hope that this was in some way useful – feedback and comments would be very welcome – I’m still trying to work out what people would find interesting.

Ash

Ben Cotton’s life(stream)

The ‘lifestream’ (his description, not mine) that I’ve been working on for Ben Cotton has gone live www.ben-cotton.com.

Ben had asked me to develop a 1-page site that pulled together all of his online activity in one place.

The new site uses Simple Pie (http://simplepie.org/) to aggregate the rss feed from Ben’s ‘Social Web Thing’ blog and also uses Twitter’s standard JSON call to display all Ben’s latest Twitter activity (although this script is a little temperamental as it relies a little to heavily on Twitter’s sometimes unreliable servers – i’m looking at alternatives.

The site also links directly to Ben’s LinkedIn, TwitPic, Twitter, Scribd and Flickr accounts as well as using the Google Maps API to produce a location map of Edelman’s London office (where Ben works).

Last but not least I’ve also included the ever-present Google Analytics to give Ben some decent stats.

Phase two of the development will see me combining all of Ben’s rss feeds into one ‘master’ feed and providing Ben with a simple CMS to control certain elements (such as meta data) of the site.

Words and Pictures and Work

So as you may or may not I do an occasional podcast (www.tapes-online.co.uk) with a chap called Cameron who also happens to be an exceptionally good illustrator/designer/drawer of ace things (http://twoducksdisco.blogspot.com/).

As you also may or may not know I also do web design outside of the 9-5 (under the title of ‘big things and little things’) and am currently doing Cam a website, I’m also working on a new site for the Jane Tomlinson Appeal (you may remember a mention from an earlier post, but probably not so here it is http://ashmannblogs.wordpress.com/2009/01/19/bike-rides-and-vans/) and a site for my brother who does things like talk about sport (http://tristanmann.wordpress.com).

If anyone else wants a web site doing then drop me a line, i’m an (x)html/css/php chap really.

Oh I am also going to try to keep up my music recommending, today it’s mirador by efterklang from their album ‘parades’ http://hypem.com/track/968772/Efterklang+-+Mirador+Live+ which is bloody lovely, it’s joyful, orchestral, beautiful and generally ace.