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