getplaylist.c

00001 
00022 #include "common.h"
00023 
00024 static uint32_t dump_playlist(LIBMTP_mtpdevice_t *device, LIBMTP_playlist_t *pl)
00025 {
00026   uint32_t i;
00027 
00028   printf("Number of items: %u\n", pl->no_tracks);
00029   if(pl->no_tracks > 0) {
00030     for(i=0;i<pl->no_tracks;i++) {
00031       LIBMTP_track_t *track;
00032       
00033       track = LIBMTP_Get_Trackmetadata(device, pl->tracks[i]);
00034       if (track != NULL) {
00035         printf("   %u: %s - %s\n", pl->tracks[i], track->artist, track->title);
00036         LIBMTP_destroy_track_t(track);
00037       } else {
00038         printf("   %u: INVALID TRACK REFERENCE!\n", pl->tracks[i]);
00039         LIBMTP_Dump_Errorstack(device);
00040         LIBMTP_Clear_Errorstack(device);
00041       }
00042     }
00043   }
00044   return 0;
00045 }
00046 
00047 int main (int argc, char **argv)
00048 {
00049   LIBMTP_mtpdevice_t *device;
00050   LIBMTP_playlist_t *playlist;
00051   u_int32_t id;
00052   char *endptr;
00053 
00054   fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n");
00055 
00056   // We need file ID
00057   if ( argc != 2 ) {
00058     fprintf(stderr, "Just a playlist ID is required\n");
00059     return 1;
00060   }
00061 
00062   // Sanity check playlist ID
00063   id = strtoul(argv[1], &endptr, 10);
00064   if ( *endptr != 0 ) {
00065     fprintf(stderr, "illegal value %s\n", argv[1]);
00066     return 1;
00067   } else if ( ! id ) {
00068     fprintf(stderr, "bad playlist id %u\n", id);
00069     return 1;
00070  }
00071 
00072   LIBMTP_Init();
00073   device = LIBMTP_Get_First_Device();
00074   if (device == NULL) {
00075     printf("No devices. Connect/replug device and try again.\n");
00076     exit (0);
00077   }
00078 
00079   playlist = LIBMTP_Get_Playlist(device,id);  
00080 
00081   if (playlist != NULL) {
00082     dump_playlist(device,playlist);
00083   }
00084 
00085   LIBMTP_destroy_playlist_t(playlist);
00086   
00087   LIBMTP_Release_Device(device);
00088   printf("OK.\n");
00089   exit (0);
00090 }
00091 

Generated on Mon Aug 27 14:50:25 2007 for libmtp by  doxygen 1.5.3