Game Development Reference
In-Depth Information
See also
F Downloading images from Flickr and Picasa
Downloading images from Flickr and Picasa
We have a list of images in the XML format, which we downloaded in the Fetching lists
of photos from Flickr and Picasa recipe. Let's download the actual photos from the
photo hosting.
Getting ready
Here, we need the image list from Flickr or Picasa to get started. Use the previous recipe to
download that list.
How to do it…
1.
Once we have retrieved the list, we extract individual image IDs from it. Having these
IDs allows us to form the URLs for individual images. Flickr uses a complicated
image URL formation process and Picasa stores the URLs directly. Both services can
generate responses in XML and JSON formats. We will show you how to parse XML
responses using our tiny ad hoc parser. However, if you already use some kind of XML
or JSON parsing library in your project, you are encouraged to use it for this task too.
2.
To parse the Flickr XML list, we use the following function:
void Flickr_ParseXMLResponse( const std::string& Response,
std::vector<std::string>& URLs )
{
using std::string::npos;
size_t begin = Response.find( "<photos" );
if ( begin == npos ) { return; }
begin = Response.find_first_of( '>', begin );
if ( begin == npos ) { return; }
size_t end = Response.find( "/photos>" );
if ( end == npos ) { return; }
size_t cur = begin;
size_t ResLen = Response.length();
3.
Parse the string in an ad-hoc way. You can use your favorite XML library instead of
this loop:
while ( cur < ResLen )
{
using std::string::npos;
 
Search WWH ::




Custom Search