libmtp: playlists.c

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

# playlists.c

    00001
    00022 #include "common.h"
    00023
    00024 static void dump_plinfo(LIBMTP_mtpdevice_t *device, LIBMTP_playlist_t *pl)
    00025 {
    00026   uint32_t i;
    00027
    00028   printf("Playlist ID: %d\n", pl->playlist_id);
    00029   if (pl->name != NULL)
    00030     printf("   Name: %s\n", pl->name);
    00031   printf("   Tracks:\n");
    00032
    00033   for (i = 0; i < pl->no_tracks; i++) {
    00034     LIBMTP_track_t *track;
    00035
    00036     track = LIBMTP_Get_Trackmetadata(device, pl->tracks[i]);
    00037     if (track != NULL) {
    00038       printf("      %u: %s - %s\n", pl->tracks[i], track->artist, track->title);
    00039       LIBMTP_destroy_track_t(track);
    00040     } else {
    00041       printf("      %u: INVALID TRACK REFERENCE!\n", pl->tracks[i]);
    00042       LIBMTP_Dump_Errorstack(device);
    00043       LIBMTP_Clear_Errorstack(device);
    00044     }
    00045   }
    00046 }
    00047
    00048 int main (int argc, char **argv)
    00049 {
    00050   LIBMTP_mtpdevice_t *device;
    00051   LIBMTP_playlist_t *playlists;
    00052
    00053   LIBMTP_Init();
    00054   device = LIBMTP_Get_First_Device();
    00055   if (device == NULL) {
    00056     printf("No devices.\n");
    00057     exit (0);
    00058   }
    00059
    00060   // Get playlist listing.
    00061   playlists = LIBMTP_Get_Playlist_List(device);
    00062   if (playlists == NULL) {
    00063     printf("No playlists.\n");
    00064   } else {
    00065     LIBMTP_playlist_t *pl, *tmp;
    00066     pl = playlists;
    00067     while (pl != NULL) {
    00068       dump_plinfo(device, pl);
    00069       tmp = pl;
    00070       pl = pl->next;
    00071       LIBMTP_destroy_playlist_t(tmp);
    00072     }
    00073   }
    00074
    00075   LIBMTP_Release_Device(device);
    00076   printf("OK.\n");
    00077   exit (0);
    00078 }