libmtp: playlists.c

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

# playlists.c

    00001 #include "common.h"
    00002
    00003 static void dump_plinfo(LIBMTP_mtpdevice_t *device, LIBMTP_playlist_t *pl)
    00004 {
    00005   uint32_t i;
    00006
    00007   printf("Playlist ID: %d\n", pl->playlist_id);
    00008   if (pl->name != NULL)
    00009     printf("   Name: %s\n", pl->name);
    00010   printf("   Tracks:\n");
    00011
    00012   for (i = 0; i < pl->no_tracks; i++) {
    00013     LIBMTP_track_t *track;
    00014
    00015     track = LIBMTP_Get_Trackmetadata(device, pl->tracks[i]);
    00016     if (track != NULL) {
    00017       printf("      %u: %s - %s\n", pl->tracks[i], track->artist, track->title);
    00018       LIBMTP_destroy_track_t(track);
    00019     } else {
    00020       printf("      %u: INVALID TRACK REFERENCE!\n", pl->tracks[i]);
    00021     }
    00022   }
    00023 }
    00024
    00025 int main (int argc, char **argv)
    00026 {
    00027   LIBMTP_mtpdevice_t *device;
    00028   LIBMTP_playlist_t *playlists;
    00029
    00030   LIBMTP_Init();
    00031   device = LIBMTP_Get_First_Device();
    00032   if (device == NULL) {
    00033     printf("No devices.\n");
    00034     exit (0);
    00035   }
    00036
    00037   // Get playlist listing.
    00038   playlists = LIBMTP_Get_Playlist_List(device);
    00039   if (playlists == NULL) {
    00040     printf("No playlists.\n");
    00041   } else {
    00042     LIBMTP_playlist_t *pl, *tmp;
    00043     pl = playlists;
    00044     while (pl != NULL) {
    00045       dump_plinfo(device, pl);
    00046       tmp = pl;
    00047       pl = pl->next;
    00048       LIBMTP_destroy_playlist_t(tmp);
    00049     }
    00050   }
    00051
    00052   LIBMTP_Release_Device(device);
    00053   printf("OK.\n");
    00054   exit (0);
    00055 }