M.Efe Ozer’s Weblog

March 10, 2009

Create Data File for SlideShow2 From Picasa Web Albums

Filed under: .Net, BlogEngineNet, Code Stuff — Tags: , , , , , — Mehmet Efe Ozer @ 6:56 pm

I was using SlideShow extension of Danny Douglas. I installed, changed it into xml data provider and used with local photo files.  But after start to thinking about membership system, necessity occurred  uploading and crud operations on albums. Even i coded some management features for local data and photo files. But storage of files,web traffic and one developer dependant management system were other issues that make me stop. So first i start to use Flickr Api. It gives options what i want to do, but for current project i start to work on Picasa Web Albums Data API.

For BlogEngine application that i modified i tried first Rtur.Net’s Picasa Extension.

When you login with your email as in extension’s admin panel you are authenticate to do CRUD options on your albums. But also i was looking for something without login (so no CRUD ) and show it in SlideShow2 which also support Flickr and xml data files.

I like SlideShow2 because customization is so easy in its project structure.

I saw some works for Picasa data provider on project discussions. But this time for some reasons i want to use XML data file for show photos.

So long story short what i did is below. It is based on read Picasa feeds with Google.GData methods and create a xml file with XLinq. I didn’t filter any album or photo, but you can do with using  XLinq.

We need Google.GData.Apps, Google.GData.Client, Google.GData.Extensions, Google.GData.Photos

from here : http://code.google.com/p/google-gdata/downloads/list

Public Shared Sub CreatePicasaSlideShowData()

        Dim service As PicasaService = New PicasaService("myapplicationname")

        dim PicasaUserID as string = "mypicasauserid"

        Dim query As AlbumQuery = New AlbumQuery(PicasaQuery.CreatePicasaUri(PicasaUserID))
        Dim albumfeed As PicasaFeed = service.Query(query)

        Dim xdoc As New XDocument

        xdoc.Declaration = New XDeclaration("1.0", "utf-8", "")
        xdoc.Add(<data startalbumindex="0" transition="CrossFadeTransition"></data>)

        xdoc.Element("data").Add(From albumentry In albumfeed.Entries _
         Let albumAccessor As AlbumAccessor = New AlbumAccessor(CType(albumentry, PicasaEntry)) _
         Let photoquery As PhotoQuery = New PhotoQuery(PicasaQuery.CreatePicasaUri(PicasaUserID, albumAccessor.Id)) _
         Let photofeed As PicasaFeed = service.Query(photoquery) _
             Select New XElement("album" _
                , New XAttribute("title", albumAccessor.AlbumTitle) _
                , New XAttribute("description", albumAccessor.AlbumSummary) _
                , New XAttribute("source", CType(albumentry, PicasaEntry).Media.Thumbnails(0).Attributes("url")) _
                , New XAttribute("transition", "CrossFadeTransition") _
                    , From photoentry In photofeed.Entries _
           Let photoAccessor As PhotoAccessor = New PhotoAccessor(CType(photoentry, PicasaEntry)) _
                        Let photoe As PicasaEntry = CType(photoentry, PicasaEntry) _
                    Select New XElement("slide" _
                        , New XAttribute("title", photoAccessor.PhotoTitle) _
                        , New XAttribute("description", photoAccessor.PhotoSummary) _
                        , New XAttribute("source", photoe.Content.AbsoluteUri) _
                      , New XAttribute("thumbnail", photoe.Media.Thumbnails(1).Attributes("url")) _
                      , New XAttribute("link", String.Empty) _
                      , New XAttribute("datetaken", photoe.Updated.ToShortDateString))))

        xdoc.Save("mydata.xml")
End Sub

You can change thumbnail formats, add “link” for pictures ( i left empty), and find a sensible date field from feed for “datetaken” field or change transition type.


No Comments Yet »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.