def self.from_xml(xml,flickr=nil)
att = xml.attributes
phid = att['id']
photo = flickr.photo_cache_lookup(phid) if flickr
photo ||= Flickr::Photo.new(flickr,phid)
photo.owner_id ||= att['owner'] || (xml.elements['owner'] &&
xml.elements['owner'].attributes['nsid'])
photo.secret = att['secret'] if att['secret']
photo.originalformat = att['originalformat'] if
att['originalformat']
photo.server = att['server'].to_i if att['server']
photo.title = att['title'] || cond_text(xml.elements,'title')
photo.license_id = att['license']
photo.rotation = att['rotation'].to_i if att['rotation']
photo.ispublic = (att['ispublic'].to_i == 1) if att['ispublic']
photo.isfriend = (att['isfriend'].to_i == 1) if att['isfriend']
photo.isfamily = (att['isfamily'].to_i == 1) if att['isfamily']
photo.ownername = att['ownername'] || (xml.elements['owner'] &&
xml.elements['owner'].attributes['username'])
photo.description = cond_text(xml.elements,'description')
photo.dateadded = Time.at(att['dateadded'].to_i) if
att['dateadded']
if xml.elements['exif']
list = []
xml.elements.each('exif') do |el|
exif = Flickr::Exif.from_xml(el)
list << exif
end
photo.exif = list
end
if xml.elements['visibility']
att = xml.elements['visibility'].attributes
photo.ispublic = (att['ispublic'].to_i == 1)
photo.isfriend = (att['isfriend'].to_i == 1)
photo.isfamily = (att['isfamily'].to_i == 1)
end
if xml.elements['dates']
att = xml.elements['dates'].attributes
dates = {}
dates[:posted] = Time.at(att['posted'].to_i)
dates[:taken] = Time.gm(*ParseDate.parsedate(att['taken']))
dates[:lastupdate] = Time.at(att['lastupdate'].to_i)
dates[:takengranularity] = att['takengranularity'].to_i
photo.dates = dates
end
if xml.elements['editability']
att = xml.elements['editability'].attributes
photo.cancomment = (att['cancomment'].to_i == 1)
photo.canaddmeta = (att['canaddmeta'].to_i == 1)
end
photo.comments = cond_text(xml.elements,'comments')
photo.comments &&= photo.comments.to_i
if xml.elements['notes']
notes = []
xml.elements['notes'].each_element do |el|
notes << Flickr::Note.from_xml(el,photo)
end
photo.notes = notes
end
if xml.elements['tags']
tags = []
xml.elements['tags'].each_element do |el|
tags << Flickr::Tag.from_xml(el,photo)
end
photo.tags = tags
end
if xml.elements['urls']
urls = {}
xml.elements['urls'].each_element do |el|
att = el.attributes
urls[att['type'].intern] = el.text
end
photo.urls = urls
end
flickr.photo_cache_store(photo) if flickr
return photo
end