3 * Example program to send and associate album art to an entity
6 * Copyright (C) 2006 Robert Reardon <rreardon@monkshatch.vispa.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
31 #include <sys/types.h>
37 static void usage(void) {
38 printf("Usage: thumb -i <fileid/trackid> <imagefile>\n");
42 int main (int argc, char **argv) {
46 LIBMTP_mtpdevice_t *device = NULL;
50 char *imagedata = NULL;
56 fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n");
58 while ( (opt = getopt(argc, argv, "hi:")) != -1 ) {
63 id = strtoul(optarg, &rest, 0);
73 printf("You need to pass a filename.\n");
79 if ( stat(path, &statbuff) == -1 ) {
80 fprintf(stderr, "%s: ", path);
84 filesize = statbuff.st_size;
85 imagedata = malloc(filesize);
88 if ( (fd = open(path, O_RDONLY|O_BINARY) == -1) ) {
90 if ( (fd = open(path, O_RDONLY)) == -1) {
92 printf("Couldn't open image file %s (%s)\n",path,strerror(errno));
95 ret = read(fd, imagedata, filesize);
96 if (ret == -1) perror("read thumb data");
101 device = LIBMTP_Get_First_Device();
102 if (device == NULL) {
103 printf("No devices.\n");
107 LIBMTP_filesampledata_t *thumb = LIBMTP_new_filesampledata_t();
108 thumb->data = imagedata;
109 thumb->size = filesize;
110 thumb->filetype = LIBMTP_FILETYPE_JPEG;
111 ret = LIBMTP_Send_Representative_Sample(device,id,thumb);
113 printf("Couldn't send thumbnail\n");
114 LIBMTP_Dump_Errorstack(device);
115 LIBMTP_Clear_Errorstack(device);
118 LIBMTP_destroy_filesampledata_t(thumb);
120 LIBMTP_Release_Device(device);