libmtp  1.1.18
playlists.c
#include "common.h"
#include <stdlib.h>
static void dump_plinfo(LIBMTP_mtpdevice_t *device, LIBMTP_playlist_t *pl)
{
uint32_t i;
printf("Playlist ID: %d\n", pl->playlist_id);
if (pl->name != NULL)
printf(" Name: %s\n", pl->name);
printf(" Parent ID: %d\n", pl->parent_id);
printf(" Tracks:\n");
for (i = 0; i < pl->no_tracks; i++) {
track = LIBMTP_Get_Trackmetadata(device, pl->tracks[i]);
if (track != NULL) {
printf(" %u: %s - %s\n", pl->tracks[i], track->artist, track->title);
} else {
printf(" %u: INVALID TRACK REFERENCE!\n", pl->tracks[i]);
}
}
}
int main (int argc, char **argv)
{
LIBMTP_playlist_t *playlists;
fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n");
if (device == NULL) {
printf("No devices.\n");
exit (0);
}
// Get playlist listing.
playlists = LIBMTP_Get_Playlist_List(device);
if (playlists == NULL) {
printf("No playlists.\n");
} else {
LIBMTP_playlist_t *pl, *tmp;
pl = playlists;
while (pl != NULL) {
dump_plinfo(device, pl);
tmp = pl;
pl = pl->next;
}
}
printf("OK.\n");
exit (0);
}