libmtp: playlists.c

libmtp 1.1.22

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++) {
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);
}
}
}
int main (int argc, char **argv)
{
LIBMTP_mtpdevice_t *device;
LIBMTP_playlist_t *playlists;
fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n");
LIBMTP_Init();
device = LIBMTP_Get_First_Device();
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;
LIBMTP_destroy_playlist_t(tmp);
}
}
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_List
LIBMTP_playlist_t * LIBMTP_Get_Playlist_List(LIBMTP_mtpdevice_t *device)
Definition libmtp.c:7715
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_mtpdevice_struct
Definition libmtp.h:635
LIBMTP_playlist_struct
Definition libmtp.h:737
LIBMTP_playlist_struct::next
LIBMTP_playlist_t * next
Definition libmtp.h:744
LIBMTP_playlist_struct::playlist_id
uint32_t playlist_id
Definition libmtp.h:738
LIBMTP_playlist_struct::name
char * name
Definition libmtp.h:741
LIBMTP_playlist_struct::parent_id
uint32_t parent_id
Definition libmtp.h:739
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
Definition libmtp.h:708
LIBMTP_track_struct::title
char * title
Definition libmtp.h:712
LIBMTP_track_struct::artist
char * artist
Definition libmtp.h:713