/* --------------------------------------------------------------------------
libcoverart - Client library to access MusicBrainz
Copyright (C) 2012 Andrew Hawkins
This file is part of libcoverart.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
libcoverart is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library. If not, see .
$Id$
----------------------------------------------------------------------------*/
#include
#include
#include
#include
#include "coverart/caa_c.h"
int main(int argc, const char *argv[])
{
if (argc==2)
{
const char *ReleaseID=argv[1];
CaaCoverArt CoverArt=caa_coverart_new("c-example-1.0");
if (CoverArt)
{
CaaReleaseInfo ReleaseInfo;
CaaImageData ImageData=caa_coverart_fetch_front(CoverArt,ReleaseID);
if (ImageData)
{
if (0!=caa_imagedata_size(ImageData))
{
int size;
char *FileName;
FILE *fptr;
size=snprintf(NULL,0,"%s-front.jpg",ReleaseID);
FileName=malloc((size+1) * sizeof(char));
sprintf(FileName,"%s-front.jpg",ReleaseID);
printf("Saving front to '%s'\n",FileName);
fptr=fopen(FileName,"wb");
if (fptr)
{
fwrite(caa_imagedata_data(ImageData),caa_imagedata_size(ImageData),1,fptr);
fclose(fptr);
printf("Saved front to '%s'\n",FileName);
}
free(FileName);
}
else
{
printf("No front image found\n");
}
caa_imagedata_delete(ImageData);
}
ImageData=caa_coverart_fetch_back(CoverArt,ReleaseID);
if (ImageData)
{
if (0!=caa_imagedata_size(ImageData))
{
int size;
char *FileName;
FILE *fptr;
size=snprintf(NULL,0,"%s-back.jpg",ReleaseID);
FileName=malloc((size+1) * sizeof(char));
sprintf(FileName,"%s-back.jpg",ReleaseID);
printf("Saving back to '%s'\n",FileName);
fptr=fopen(FileName,"wb");
if (fptr)
{
fwrite(caa_imagedata_data(ImageData),caa_imagedata_size(ImageData),1,fptr);
fclose(fptr);
printf("Saved back to '%s'\n",FileName);
}
free(FileName);
}
else
{
printf("No back image found\n");
}
caa_imagedata_delete(ImageData);
}
ReleaseInfo=caa_coverart_releaseinfo(CoverArt,ReleaseID);
if (ReleaseInfo)
{
CaaImageList ImageList=caa_releaseinfo_get_imagelist(ReleaseInfo);
if (ImageList)
{
int ImageNum;
printf("Found %d images\n",caa_image_list_size(ImageList));
for (ImageNum=0;ImageNum