I came across this entry the other week and decided to play around a bit myself with it. I don't nearly get as much time as I would like to "play" with coding these days so this was a nice escape for me.
Over on hackdiary, Matt Biddulph came up with a very cool flickr integration to Second Life the problem I had though was that I could not get it to work against his server (he even states he might shut it down if bandwidth and all of that) so I decided to do something similar to what he did...
I've spent a few hours hacking on some toy objects with this new capability, starting with the mashup de rigeur: Flickr integration. My home in SL now sports a simple picture frame. Touch it and it looks up your avatar name to see what your favourite Flickr tag is, picks a random picture with that tag from Flickr and displays it on its surface. If it hasn't met you before, it asks you to tell it what tag to use.
Source: hackdiary: Alas, Second Life! Web 2.0 in a virtual world
What I did though was pull a basic 10 image slide show based on a requested tag instead of the coolness that he came up with avatar aware and all of that.
The whole thing was rather easy to do and was a simple "hack" of what Matt did as well as some slight modification to "getflickr.php" from Tim Bishop and Eacosta.
<?php
/*
* getflickr.php uses the MagpieRSS Parser to fetch and parse a
* tag, user or group pool RSS feed from the photo sharing site www.flickr.com,
* and display the pictures.
*
* V 0.6 renamed back to getflickr.php, and fixed up to account for new flickr
* url structure by Tim Bishop (http://www.timbishop.com).
*
* V 0.5 of flickrrss.php written and released under GPL by
* Dave Kellam (http://www.eightface.com)
*
* V 0.2 of getflickr.php written and released under GPL by
* Tim Bishop, http://www.timbishop.com
*
* This script requires the lastest version of MagpieRSS, which
* can be obtained from: http://magpierss.sourceforge.net
*
* Thanks to Kellan Elliott-McCrea, author of MagpieRSS, and
* cip at acme.sinless.org, who wrote the first version of this
* script. And Tim Bishop (http://www.timbishop.com) who wrote
* the getflickr.php script that I used as a base.
*
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
* KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
* OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#################################
## User configurable variables ##
#################################
# set what type of tag you're pulling from flickr
# 0 = tag; 1 = user; 2 = group pool
$tagtype = 0;
# set the tag to pull from flickr (tag, user or group pool)
# example: "cats", "44124462494@N01", "circle"
//$tag = "55589891@N00";
//$tag = "sapphire07";
$tag = $_REQUEST["tag"];
# set default value for number of pictures to show
# (flickr show maximum of 10 photos in feed)
$num_items = 10;
# set to true to use medium pics, otherwise it uses small
$mediumPics = true;
# set location of Magpie RSS files
# require_once('magpierss/rss_fetch.inc');
# require_once('magpierss/rss_utils.inc');
require_once('./rss_fetch.inc');
require_once('./rss_utils.inc');
################################################################
## End of user defined variables, except for some html cruft ##
################################################################
// get the feeds
if ($tagtype == 0) { define('RSS_URL','http://www.flickr.com/services/feeds/photos_public.gne?tags=' . $tag . '&format=rss_200'); }
elseif ($tagtype == 1) { define('RSS_URL','http://www.flickr.com/services/feeds/photos_public.gne?id=' . $tag . '&format=rss_200'); }
elseif ($tagtype == 2) { define('RSS_URL','http://www.flickr.com/groups/' . $tag . '/pool/feed/?format=rss_200'); }
else { Print "Invalid tagtype"; }
# get rss file
$rss = fetch_rss(RSS_URL);
if ($rss) {
# HTML formatting of results
$imgurl = "";
# specifies number of pictures
$items = array_slice($rss->items, 0, $num_items);
# builds html from array
foreach ( $items as $item ) {
if(preg_match('<img src="([^"]*)" [^/]*/>', $item['description'],$imgUrlMatches)) {
$imgurl = $imgUrlMatches[1];
# change to smaller pictures
if (!$mediumPics) {
$imgurl = str_replace("m.jpg", "s.jpg", $imgurl);
}
$title = $item['title'];
$url = $item['link'];
# Changed due to flickr changing urls
# preg_match('<http://photos[0-9]\.flickr\.com/([^.]*)_(m|s)\.jpg>', $imgurl, $flickrSlugMatches);
# preg_match('<http://photos\d\d?\.flickr\.com/([^.]*)_(m|s)\.jpg>', $imgurl, $flickrSlugMatches);
preg_match('<http://static.flickr\.com/\d\d?\/([^.]*)\.jpg>', $imgurl, $flickrSlugMatches);
$flickrSlug = $flickrSlugMatches[1];
print "$imgurl|";
}
}
} else {
echo magpie_error();
}
?>
Follow that with this simple LSL script inside of an object in Second Life.
// A place to remember the ID for the latest http request we made, so the callback doesn't process out-of-order responses
key http_id;
// Test pattern - Used as default video texture when one is missing in parcel media
key VIDEO_DEFAULT = "6e0f05ad-1809-4edc-df29-fae3d2a6c9b8";
//Change this to change where the image will be displayed
integer DISPLAY_ON_SIDE = ALL_SIDES;
// Time delay before next photo
float delay = 120.0;
// Set the texture to the jpeg provided by url
seturl(string url)
{
key video_texture = llList2Key(llParcelMediaQuery( [PARCEL_MEDIA_COMMAND_TEXTURE]), 0);
if(video_texture == NULL_KEY)
{
video_texture = VIDEO_DEFAULT;
llParcelMediaCommandList([PARCEL_MEDIA_COMMAND_TEXTURE, VIDEO_DEFAULT]);
}
llSetTexture(video_texture,ALL_SIDES);
llScaleTexture(1, 1, DISPLAY_ON_SIDE);
llOffsetTexture(0, 0, DISPLAY_ON_SIDE);
llParcelMediaCommandList([PARCEL_MEDIA_COMMAND_URL,url]);
llParcelMediaCommandList([PARCEL_MEDIA_COMMAND_PLAY]);
llParcelMediaCommandList([PARCEL_MEDIA_COMMAND_AUTO_ALIGN,TRUE]);
}
default
{
state_entry()
{
// start listening for nearby speech
llListen(9,"",NULL_KEY,"");
llScaleTexture(1, 1, DISPLAY_ON_SIDE);
llOffsetTexture(0, 0, DISPLAY_ON_SIDE);
}
listen(integer channel, string name, key id, string message)
{
llWhisper(0,"Flickr Film starting for photos tagged with: "+message);
string url = " http://yourwebsite.com/flickr_parser.php?tag="+message;
llParcelMediaCommandList([PARCEL_MEDIA_COMMAND_STOP]);
http_id = llHTTPRequest(url,[],"");
}
touch_start(integer total_number)
{
// ask the server for a jpeg appropriate to the agent who touched us
llWhisper(0,"Flickr Film simply type '/9 tag' and enter a tag you wish to see");
}
http_response(key request_id, integer status, list metadata, string body) {
integer i;
// make sure we're processing a response we care about
if(request_id == http_id) {
// only on request success
if(status == 200) {
// data is coming back as pipe-delimited
list data = llParseString2List(body,["|"],[]);
for( i = 0; i < 10; ++i ) {
// url is the first field
string url = llList2String(data,i);
if(url == "UNKNOWN") {
llWhisper(0,"I don't know what kind of picture to show you.
Type '/9 tag' to tell me what tag to search for on flickr");
} else {
//llWhisper(0,url);
seturl(url);
}
// Now pause before next photo
llSetTimerEvent(delay);
}
}
}
}
timer()
{
llSetTimerEvent(0.0); // Set the timer to 0.0 to turn it off
}
}
You can of course come by my office in Second Life and purchase a working copy of the "flickr TV" if you like but why not just save yourself the money and DIY :-) besides you can do so much more with the code by itself :-) and I don't support it which is why the "working" copy is so expensive.



0 comments:
Post a Comment