Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(182)

Side by Side Diff: examples/sendtr.c

Issue 2364793002: Revert "Uprev libmtp to 1.1.12" (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/libmtp@master
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « examples/folders.c ('k') | examples/thumb.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /** 1 /**
2 * \file sendtr.c 2 * \file sendtr.c
3 * Example program to send a music track to a device. 3 * Example program to send a music track to a device.
4 * This program is derived from the exact equivalent in libnjb. 4 * This program is derived from the exact equivalent in libnjb.
5 * based on Enrique Jorreto Ledesma's work on the original program by 5 * based on Enrique Jorreto Ledesma's work on the original program by
6 * Shaun Jackman and Linus Walleij. 6 * Shaun Jackman and Linus Walleij.
7 * 7 *
8 * Copyright (C) 2003-2010 Linus Walleij <triad@df.lth.se> 8 * Copyright (C) 2003-2010 Linus Walleij <triad@df.lth.se>
9 * Copyright (C) 2003-2005 Shaun Jackman 9 * Copyright (C) 2003-2005 Shaun Jackman
10 * Copyright (C) 2003-2005 Enrique Jorrete Ledesma 10 * Copyright (C) 2003-2005 Enrique Jorrete Ledesma
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 } else { 179 } else {
180 printf("success!\n"); 180 printf("success!\n");
181 } 181 }
182 return ret; 182 return ret;
183 } 183 }
184 184
185 int sendtrack_function(char * from_path, char * to_path, char *partist, char *pa lbumartist, char *ptitle, char *pgenre, char *palbum, char *pcomposer, uint16_t tracknum, uint16_t length, uint16_t year, uint32_t storageid, uint16_t quiet) 185 int sendtrack_function(char * from_path, char * to_path, char *partist, char *pa lbumartist, char *ptitle, char *pgenre, char *palbum, char *pcomposer, uint16_t tracknum, uint16_t length, uint16_t year, uint32_t storageid, uint16_t quiet)
186 { 186 {
187 char *filename, *parent; 187 char *filename, *parent;
188 char artist[80], albumartist[80], title[80], genre[80], album[80], composer[80 ]; 188 char artist[80], albumartist[80], title[80], genre[80], album[80], composer[80 ];
189 char *to_path_copy = NULL;
190 char num[80]; 189 char num[80];
191 uint64_t filesize; 190 uint64_t filesize;
192 uint32_t parent_id = 0; 191 uint32_t parent_id = 0;
193 struct stat sb; 192 struct stat sb;
194 LIBMTP_track_t *trackmeta; 193 LIBMTP_track_t *trackmeta;
195 LIBMTP_album_t *albuminfo; 194 LIBMTP_album_t *albuminfo;
196 int ret; 195 int ret;
197 196
198 printf("Sending track %s to %s\n", from_path, to_path); 197 printf("Sending track %s to %s\n", from_path, to_path);
199 198
200 to_path_copy = strdup(to_path); 199 trackmeta = LIBMTP_new_track_t();
201 parent = dirname(to_path_copy); 200 albuminfo = LIBMTP_new_album_t();
201
202 parent = dirname(strdup(to_path));
203 filename = basename(strdup(to_path));
202 parent_id = parse_path (parent,files,folders); 204 parent_id = parse_path (parent,files,folders);
203 if (parent_id == -1) { 205 if (parent_id == -1) {
204 free (to_path_copy);
205 printf("Parent folder could not be found, skipping\n"); 206 printf("Parent folder could not be found, skipping\n");
206 return 1; 207 return 1;
207 } 208 }
208 strcpy (to_path_copy,to_path);
209 filename = basename(to_path_copy);
210 209
211 if (stat(from_path, &sb) == -1) { 210 if (stat(from_path, &sb) == -1) {
212 fprintf(stderr, "%s: ", from_path); 211 fprintf(stderr, "%s: ", from_path);
213 perror("stat"); 212 perror("stat");
214 free (to_path_copy);
215 return 1; 213 return 1;
216 } 214 }
217 215
218 if (!S_ISREG(sb.st_mode)) { 216 if (!S_ISREG(sb.st_mode))
219 free (to_path_copy);
220 return 0; 217 return 0;
221 }
222 218
223 filesize = sb.st_size; 219 filesize = sb.st_size;
224
225 trackmeta = LIBMTP_new_track_t();
226 trackmeta->filetype = find_filetype (from_path); 220 trackmeta->filetype = find_filetype (from_path);
227 if (!LIBMTP_FILETYPE_IS_TRACK(trackmeta->filetype)) { 221 if (!LIBMTP_FILETYPE_IS_TRACK(trackmeta->filetype)) {
228 printf("Not a valid track codec: \"%s\"\n", LIBMTP_Get_Filetype_Description( trackmeta->filetype)); 222 printf("Not a valid track codec: \"%s\"\n", LIBMTP_Get_Filetype_Description( trackmeta->filetype));
229 LIBMTP_destroy_track_t(trackmeta);
230 free (to_path_copy);
231 return 1; 223 return 1;
232 } 224 }
233 225
234 if ((ptitle == NULL) && (quiet == 0)) { 226 if ((ptitle == NULL) && (quiet == 0)) {
235 if ( (ptitle = prompt("Title", title, 80, 0)) != NULL ) 227 if ( (ptitle = prompt("Title", title, 80, 0)) != NULL )
236 if (!strlen(ptitle)) ptitle = NULL; 228 if (!strlen(ptitle)) ptitle = NULL;
237 } 229 }
238 230
239 if ((palbum == NULL) && (quiet == 0)) { 231 if ((palbum == NULL) && (quiet == 0)) {
240 if ( (palbum = prompt("Album", album, 80, 0)) != NULL ) 232 if ( (palbum = prompt("Album", album, 80, 0)) != NULL )
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 else 276 else
285 length = strtoul(pnum, 0, 10); 277 length = strtoul(pnum, 0, 10);
286 } 278 }
287 279
288 printf("Sending track:\n"); 280 printf("Sending track:\n");
289 printf("Codec: %s\n", LIBMTP_Get_Filetype_Description(trackmeta->filetype) ); 281 printf("Codec: %s\n", LIBMTP_Get_Filetype_Description(trackmeta->filetype) );
290 if (ptitle) { 282 if (ptitle) {
291 printf("Title: %s\n", ptitle); 283 printf("Title: %s\n", ptitle);
292 trackmeta->title = strdup(ptitle); 284 trackmeta->title = strdup(ptitle);
293 } 285 }
294
295 albuminfo = LIBMTP_new_album_t();
296
297 if (palbum) { 286 if (palbum) {
298 printf("Album: %s\n", palbum); 287 printf("Album: %s\n", palbum);
299 trackmeta->album = strdup(palbum); 288 trackmeta->album = strdup(palbum);
300 albuminfo->name = strdup(palbum); 289 albuminfo->name = strdup(palbum);
301 } 290 }
302 if (palbumartist) { 291 if (palbumartist) {
303 printf("Album artist: %s\n", palbumartist); 292 printf("Album artist: %s\n", palbumartist);
304 albuminfo->artist = strdup(palbumartist); 293 albuminfo->artist = strdup(palbumartist);
305 } 294 }
306 if (partist) { 295 if (partist) {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 } else { 364 } else {
376 printf("New track ID: %d\n", trackmeta->item_id); 365 printf("New track ID: %d\n", trackmeta->item_id);
377 } 366 }
378 367
379 /* Add here add to album call */ 368 /* Add here add to album call */
380 if (palbum) 369 if (palbum)
381 ret = add_track_to_album(albuminfo, trackmeta); 370 ret = add_track_to_album(albuminfo, trackmeta);
382 371
383 LIBMTP_destroy_album_t(albuminfo); 372 LIBMTP_destroy_album_t(albuminfo);
384 LIBMTP_destroy_track_t(trackmeta); 373 LIBMTP_destroy_track_t(trackmeta);
385 free (to_path_copy);
386 374
387 return ret; 375 return ret;
388 } 376 }
389 377
390 int sendtrack_command (int argc, char **argv) { 378 int sendtrack_command (int argc, char **argv) {
391 int opt, ret; 379 int opt;
392 extern int optind; 380 extern int optind;
393 extern char *optarg; 381 extern char *optarg;
394 char *partist = NULL; 382 char *partist = NULL;
395 char *palbumartist = NULL; 383 char *palbumartist = NULL;
396 char *pcomposer = NULL; 384 char *pcomposer = NULL;
397 char *ptitle = NULL; 385 char *ptitle = NULL;
398 char *pgenre = NULL; 386 char *pgenre = NULL;
399 char *pcodec = NULL; 387 char *pcodec = NULL;
400 char *palbum = NULL; 388 char *palbum = NULL;
401 uint16_t tracknum = 0; 389 uint16_t tracknum = 0;
402 uint16_t length = 0; 390 uint16_t length = 0;
403 uint16_t year = 0; 391 uint16_t year = 0;
404 uint16_t quiet = 0; 392 uint16_t quiet = 0;
405 uint32_t storageid = 0; 393 uint32_t storageid = 0;
406 while ( (opt = getopt(argc, argv, "qD:t:a:A:w:l:c:g:n:d:y:s:")) != -1 ) { 394 while ( (opt = getopt(argc, argv, "qD:t:a:A:w:l:c:g:n:d:y:s:")) != -1 ) {
407 switch (opt) { 395 switch (opt) {
408 case 't': 396 case 't':
409 free (ptitle);
410 ptitle = strdup(optarg); 397 ptitle = strdup(optarg);
411 break; 398 break;
412 case 'a': 399 case 'a':
413 free (partist);
414 partist = strdup(optarg); 400 partist = strdup(optarg);
415 break; 401 break;
416 case 'A': 402 case 'A':
417 free (palbumartist);
418 palbumartist = strdup(optarg); 403 palbumartist = strdup(optarg);
419 break; 404 break;
420 case 'w': 405 case 'w':
421 free (pcomposer);
422 pcomposer = strdup(optarg); 406 pcomposer = strdup(optarg);
423 break; 407 break;
424 case 'l': 408 case 'l':
425 free (palbum);
426 palbum = strdup(optarg); 409 palbum = strdup(optarg);
427 break; 410 break;
428 case 'c': 411 case 'c':
429 free (pcodec);
430 pcodec = strdup(optarg); // FIXME: DSM check for MP3, WAV or WMA 412 pcodec = strdup(optarg); // FIXME: DSM check for MP3, WAV or WMA
431 break; 413 break;
432 case 'g': 414 case 'g':
433 free (pgenre);
434 pgenre = strdup(optarg); 415 pgenre = strdup(optarg);
435 break; 416 break;
436 case 'n': 417 case 'n':
437 tracknum = atoi(optarg); 418 tracknum = atoi(optarg);
438 break; 419 break;
439 case 's': 420 case 's':
440 storageid = (uint32_t) strtoul(optarg, NULL, 0); 421 storageid = (uint32_t) strtoul(optarg, NULL, 0);
441 break; 422 break;
442 case 'd': 423 case 'd':
443 length = atoi(optarg); 424 length = atoi(optarg);
444 break; 425 break;
445 case 'y': 426 case 'y':
446 year = atoi(optarg); 427 year = atoi(optarg);
447 break; 428 break;
448 case 'q': 429 case 'q':
449 quiet = 1; 430 quiet = 1;
450 break; 431 break;
451 default: 432 default:
452 sendtrack_usage(); 433 sendtrack_usage();
453 } 434 }
454 } 435 }
455 argc -= optind; 436 argc -= optind;
456 argv += optind; 437 argv += optind;
457 438
458 if ( argc != 2 ) { 439 if ( argc != 2 ) {
459 printf("You need to pass a filename and destination.\n"); 440 printf("You need to pass a filename and destination.\n");
460 sendtrack_usage(); 441 sendtrack_usage();
461 ret = 0; 442 return 0;
462 } else {
463 checklang();
464 printf("%s,%s,%s,%s,%s,%s,%s,%s,%d%d,%d,%u,%d\n",argv[0],argv[1],partist,pal bumartist,ptitle,pgenre,palbum,pcomposer,tracknum, length, year, storageid, quie t);
465 ret = sendtrack_function(argv[0],argv[1],partist,palbumartist,ptitle,pgenre, palbum,pcomposer, tracknum, length, year, storageid, quiet);
466 } 443 }
467 free (ptitle); 444
468 free (partist); 445 checklang();
469 free (palbumartist); 446
470 free (pcomposer); 447 printf("%s,%s,%s,%s,%s,%s,%s,%s,%d%d,%d,%u,%d\n",argv[0],argv[1],partist,palbu martist,ptitle,pgenre,palbum,pcomposer,tracknum, length, year, storageid, quiet) ;
471 free (palbum); 448 return sendtrack_function(argv[0],argv[1],partist,palbumartist,ptitle,pgenre,p album,pcomposer, tracknum, length, year, storageid, quiet);
472 free (pcodec);
473 free (pgenre);
474 return ret;
475 } 449 }
OLDNEW
« no previous file with comments | « examples/folders.c ('k') | examples/thumb.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698