libmtp 1.1.23

getplaylist.c
#include "common.h"
#include <stdlib.h>
#include <limits.h>
static uint32_t dump_playlist(LIBMTP_mtpdevice_t *device, LIBMTP_playlist_t *pl)
{
uint32_t i;
printf("Number of items: %u\n", pl->no_tracks);
if(pl->no_tracks > 0) {
for(i=0;i<pl->no_tracks;i++) {
LIBMTP_track_t *track;
track = LIBMTP_Get_Trackmetadata(device, pl->tracks[i]);
if (track != NULL) {
printf(" %u: %s - %s\n", pl->tracks[i], track->artist, track->title);
LIBMTP_destroy_track_t(track);
} else {
printf(" %u: INVALID TRACK REFERENCE!\n", pl->tracks[i]);
LIBMTP_Dump_Errorstack(device);
LIBMTP_Clear_Errorstack(device);
}
}
}
return 0;
}
int main (int argc, char **argv)
{
LIBMTP_mtpdevice_t *device;
LIBMTP_playlist_t *playlist;
uint32_t id;
char *endptr;
fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n");
// We need file ID
if ( argc != 2 ) {
fprintf(stderr, "Just a playlist ID is required\n");
return 1;
}
// Sanity check playlist ID
id = strtoul(argv[1], &endptr, 10);
if ( *endptr != 0 ) {
fprintf(stderr, "illegal value %s\n", argv[1]);
return 1;
} else if ( ! id ) {
fprintf(stderr, "bad playlist id %u\n", id);
return 1;
}
LIBMTP_Init();
device = LIBMTP_Get_First_Device();
if (device == NULL) {
printf("No devices. Connect/replug device and try again.\n");
exit (0);
}
playlist = LIBMTP_Get_Playlist(device,id);
if (playlist != NULL) {
dump_playlist(device,playlist);
}
LIBMTP_destroy_playlist_t(playlist);
LIBMTP_Release_Device(device);
printf("OK.\n");
exit (0);
}
LIBMTP_Get_First_Device
LIBMTP_mtpdevice_t * LIBMTP_Get_First_Device(void)
Definition libmtp.c:1719
LIBMTP_Release_Device
void LIBMTP_Release_Device(LIBMTP_mtpdevice_t *device)
Definition libmtp.c:2513
LIBMTP_Dump_Errorstack
void LIBMTP_Dump_Errorstack(LIBMTP_mtpdevice_t *device)
Definition libmtp.c:2659
LIBMTP_Clear_Errorstack
void LIBMTP_Clear_Errorstack(LIBMTP_mtpdevice_t *device)
Definition libmtp.c:2632
LIBMTP_Init
void LIBMTP_Init(void)
Definition libmtp.c:774
LIBMTP_destroy_playlist_t
void LIBMTP_destroy_playlist_t(LIBMTP_playlist_t *playlist)
Definition libmtp.c:7690
LIBMTP_Get_Playlist
LIBMTP_playlist_t * LIBMTP_Get_Playlist(LIBMTP_mtpdevice_t *device, uint32_t const plid)
Definition libmtp.c:7793
LIBMTP_Get_Trackmetadata
LIBMTP_track_t * LIBMTP_Get_Trackmetadata(LIBMTP_mtpdevice_t *device, uint32_t const trackid)
Definition libmtp.c:5196
LIBMTP_destroy_track_t
void LIBMTP_destroy_track_t(LIBMTP_track_t *track)
Definition libmtp.c:4773
LIBMTP_track_t
struct LIBMTP_track_struct LIBMTP_track_t
Definition libmtp.h:466
LIBMTP_playlist_t
struct LIBMTP_playlist_struct LIBMTP_playlist_t
Definition libmtp.h:467
LIBMTP_mtpdevice_t
struct LIBMTP_mtpdevice_struct LIBMTP_mtpdevice_t
Definition libmtp.h:464
LIBMTP_playlist_struct::no_tracks
uint32_t no_tracks
Definition libmtp.h:743
LIBMTP_playlist_struct::tracks
uint32_t * tracks
Definition libmtp.h:742
LIBMTP_track_struct::title
char * title
Definition libmtp.h:712
LIBMTP_track_struct::artist
char * artist
Definition libmtp.h:713