OLD | NEW |
1 /** | 1 /** |
2 * \file albumart.c | 2 * \file albumart.c |
3 * Example program to send album art. | 3 * Example program to send album art. |
4 * | 4 * |
5 * Copyright (C) 2006 Andy Kelk <andy@mopoke.co.uk> | 5 * Copyright (C) 2006 Andy Kelk <andy@mopoke.co.uk> |
6 * | 6 * |
7 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
8 * modify it under the terms of the GNU Lesser General Public | 8 * modify it under the terms of the GNU Lesser General Public |
9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
10 * version 2 of the License, or (at your option) any later version. | 10 * version 2 of the License, or (at your option) any later version. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 uint32_t *ids = NULL; | 48 uint32_t *ids = NULL; |
49 uint32_t *tmp = NULL; | 49 uint32_t *tmp = NULL; |
50 uint64_t filesize; | 50 uint64_t filesize; |
51 char *imagedata = NULL; | 51 char *imagedata = NULL; |
52 char *albumname = NULL; | 52 char *albumname = NULL; |
53 char *path = NULL; | 53 char *path = NULL; |
54 char *rest; | 54 char *rest; |
55 struct stat statbuff; | 55 struct stat statbuff; |
56 uint32_t storageid = 0; | 56 uint32_t storageid = 0; |
57 uint32_t parentid = 0; | 57 uint32_t parentid = 0; |
| 58 int ret; |
58 | 59 |
59 fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n"); | 60 fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n"); |
60 | 61 |
61 while ( (opt = getopt(argc, argv, "dhn:i:s:p:")) != -1 ) { | 62 while ( (opt = getopt(argc, argv, "dhn:i:s:p:")) != -1 ) { |
62 switch (opt) { | 63 switch (opt) { |
63 case 'h': | 64 case 'h': |
64 usage(); | 65 usage(); |
65 case 'd': | 66 case 'd': |
66 LIBMTP_Set_Debug(LIBMTP_DEBUG_PTP | LIBMTP_DEBUG_DATA); | 67 LIBMTP_Set_Debug(LIBMTP_DEBUG_PTP | LIBMTP_DEBUG_DATA); |
67 break; | 68 break; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 | 118 |
118 #ifdef __WIN32__ | 119 #ifdef __WIN32__ |
119 if ( (fd = open(path, O_RDONLY|O_BINARY) == -1) ) { | 120 if ( (fd = open(path, O_RDONLY|O_BINARY) == -1) ) { |
120 #else | 121 #else |
121 if ( (fd = open(path, O_RDONLY)) == -1) { | 122 if ( (fd = open(path, O_RDONLY)) == -1) { |
122 #endif | 123 #endif |
123 printf("Couldn't open image file %s (%s)\n",path,strerror(errno)); | 124 printf("Couldn't open image file %s (%s)\n",path,strerror(errno)); |
124 return 1; | 125 return 1; |
125 } | 126 } |
126 else { | 127 else { |
127 read(fd, imagedata, filesize); | 128 ret = read(fd, imagedata, filesize); |
| 129 if (ret == -1) perror("read"); |
128 close(fd); | 130 close(fd); |
129 } | 131 } |
130 | 132 |
131 LIBMTP_Init(); | 133 LIBMTP_Init(); |
132 device = LIBMTP_Get_First_Device(); | 134 device = LIBMTP_Get_First_Device(); |
133 if (device == NULL) { | 135 if (device == NULL) { |
134 printf("No devices.\n"); | 136 printf("No devices.\n"); |
135 return 0; | 137 return 0; |
136 } | 138 } |
137 | 139 |
138 LIBMTP_filesampledata_t *albumart = LIBMTP_new_filesampledata_t(); | 140 LIBMTP_filesampledata_t *albumart = LIBMTP_new_filesampledata_t(); |
139 albumart->data = imagedata; | 141 albumart->data = imagedata; |
140 albumart->size = filesize; | 142 albumart->size = filesize; |
141 albumart->filetype = LIBMTP_FILETYPE_JPEG; | 143 albumart->filetype = LIBMTP_FILETYPE_JPEG; |
142 | 144 |
143 LIBMTP_album_t *album = LIBMTP_new_album_t(); | 145 LIBMTP_album_t *album = LIBMTP_new_album_t(); |
144 album->name = albumname; | 146 album->name = albumname; |
145 album->no_tracks = idcount; | 147 album->no_tracks = idcount; |
146 album->tracks = ids; | 148 album->tracks = ids; |
147 album->parent_id = parentid; | 149 album->parent_id = parentid; |
148 album->storage_id = storageid; | 150 album->storage_id = storageid; |
149 int ret = LIBMTP_Create_New_Album(device,album); | 151 |
| 152 ret = LIBMTP_Create_New_Album(device,album); |
150 if (ret == 0) { | 153 if (ret == 0) { |
151 ret = LIBMTP_Send_Representative_Sample(device,album->album_id, albumart); | 154 ret = LIBMTP_Send_Representative_Sample(device,album->album_id, albumart); |
152 if (ret != 0) { | 155 if (ret != 0) { |
153 printf("Couldn't send album art\n"); | 156 printf("Couldn't send album art\n"); |
154 LIBMTP_Dump_Errorstack(device); | 157 LIBMTP_Dump_Errorstack(device); |
155 LIBMTP_Clear_Errorstack(device); | 158 LIBMTP_Clear_Errorstack(device); |
156 } | 159 } |
157 } | 160 } |
158 else { | 161 else { |
159 printf("Couldn't create album object\n"); | 162 printf("Couldn't create album object\n"); |
160 LIBMTP_Dump_Errorstack(device); | 163 LIBMTP_Dump_Errorstack(device); |
161 LIBMTP_Clear_Errorstack(device); | 164 LIBMTP_Clear_Errorstack(device); |
162 } | 165 } |
163 | 166 |
164 LIBMTP_destroy_filesampledata_t(albumart); | 167 LIBMTP_destroy_filesampledata_t(albumart); |
165 LIBMTP_destroy_album_t(album); | 168 LIBMTP_destroy_album_t(album); |
166 | 169 |
167 LIBMTP_Release_Device(device); | 170 LIBMTP_Release_Device(device); |
168 printf("OK.\n"); | 171 printf("OK.\n"); |
169 return 0; | 172 return 0; |
170 } | 173 } |
171 | 174 |
OLD | NEW |