libmtp: getplaylist.c

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

# 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   // We need file ID
    00055   if ( argc != 2 ) {
    00056     fprintf(stderr, "Just a playlist ID is required\n");
    00057     return 1;
    00058   }
    00059
    00060   // Sanity check playlist ID
    00061   id = strtoul(argv[1], &endptr, 10);
    00062   if ( *endptr != 0 ) {
    00063     fprintf(stderr, "illegal value %s\n", argv[1]);
    00064     return 1;
    00065   } else if ( ! id ) {
    00066     fprintf(stderr, "bad playlist id %u\n", id);
    00067     return 1;
    00068  }
    00069
    00070   LIBMTP_Init();
    00071   device = LIBMTP_Get_First_Device();
    00072   if (device == NULL) {
    00073     printf("No devices. Connect/replug device and try again.\n");
    00074     exit (0);
    00075   }
    00076
    00077   playlist = LIBMTP_Get_Playlist(device,id);
    00078
    00079   if (playlist != NULL) {
    00080     dump_playlist(device,playlist);
    00081   }
    00082
    00083   LIBMTP_destroy_playlist_t(playlist);
    00084
    00085   LIBMTP_Release_Device(device);
    00086   printf("OK.\n");
    00087   exit (0);
    00088 }
    00089