libmtp: getplaylist.c

- Main Page
- Modules
- Data Structures
- Files
- Directories
- Examples

# getplaylist.c

    00001 #include "common.h"
    00002
    00003 static uint32_t dump_playlist(LIBMTP_mtpdevice_t *device, uint32_t playlist_id)
    00004 {
    00005   uint32_t *items;
    00006   uint32_t len, ret;
    00007   uint32_t i;
    00008
    00009   ret = LIBMTP_Get_Object_References (device, playlist_id, &items, &len);
    00010   if (ret != 0) {
    00011     printf("dump_playlist: Could not get object references\n");
    00012     return -1;
    00013   }
    00014
    00015   printf("Number of items: %u\n", len);
    00016   if(len > 0) {
    00017     for(i=0;i<len;i++) {
    00018       LIBMTP_track_t *track;
    00019
    00020       track = LIBMTP_Get_Trackmetadata(device, items[i]);
    00021       if (track != NULL) {
    00022         printf("   %u: %s - %s\n", items[i], track->artist, track->title);
    00023         LIBMTP_destroy_track_t(track);
    00024       } else {
    00025         printf("   %u: INVALID TRACK REFERENCE!\n", items[i]);
    00026       }
    00027     }
    00028     free(items);
    00029   }
    00030   return 0;
    00031 }
    00032
    00033 int main (int argc, char **argv)
    00034 {
    00035   LIBMTP_mtpdevice_t *device;
    00036   u_int32_t id;
    00037   char *endptr;
    00038
    00039   // We need file ID
    00040   if ( argc != 2 ) {
    00041     fprintf(stderr, "Just a playlist ID is required\n");
    00042     return 1;
    00043   }
    00044
    00045   // Sanity check playlist ID
    00046   id = strtoul(argv[1], &endptr, 10);
    00047   if ( *endptr != 0 ) {
    00048     fprintf(stderr, "illegal value %s\n", argv[1]);
    00049     return 1;
    00050   } else if ( ! id ) {
    00051     fprintf(stderr, "bad playlist id %u\n", id);
    00052     return 1;
    00053  }
    00054
    00055   LIBMTP_Init();
    00056   device = LIBMTP_Get_First_Device();
    00057   if (device == NULL) {
    00058     printf("No devices. Connect/replug device and try again.\n");
    00059     exit (0);
    00060   }
    00061
    00062   if(dump_playlist(device, id) != 0) {
    00063     printf("Error getting playlist from MTP device.\n");
    00064   }
    00065
    00066   LIBMTP_Release_Device(device);
    00067   printf("OK.\n");
    00068   exit (0);
    00069 }
    00070