Home | History | Annotate | Download | only in examples
      1 /**
      2  * \file playlists.c
      3  * Example program to list the playlists on a device.
      4  *
      5  * Copyright (C) 2005-2007 Linus Walleij <triad (at) df.lth.se>
      6  *
      7  * This library is free software; you can redistribute it and/or
      8  * modify it under the terms of the GNU Lesser General Public
      9  * License as published by the Free Software Foundation; either
     10  * version 2 of the License, or (at your option) any later version.
     11  *
     12  * This library is distributed in the hope that it will be useful,
     13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     15  * Lesser General Public License for more details.
     16  *
     17  * You should have received a copy of the GNU Lesser General Public
     18  * License along with this library; if not, write to the
     19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
     20  * Boston, MA 02111-1307, USA.
     21  */
     22 #include "common.h"
     23 #include <stdlib.h>
     24 
     25 static void dump_plinfo(LIBMTP_mtpdevice_t *device, LIBMTP_playlist_t *pl)
     26 {
     27   uint32_t i;
     28 
     29   printf("Playlist ID: %d\n", pl->playlist_id);
     30   if (pl->name != NULL)
     31     printf("   Name: %s\n", pl->name);
     32   printf("   Parent ID: %d\n", pl->parent_id);
     33   printf("   Tracks:\n");
     34 
     35   for (i = 0; i < pl->no_tracks; i++) {
     36     LIBMTP_track_t *track;
     37 
     38     track = LIBMTP_Get_Trackmetadata(device, pl->tracks[i]);
     39     if (track != NULL) {
     40       printf("      %u: %s - %s\n", pl->tracks[i], track->artist, track->title);
     41       LIBMTP_destroy_track_t(track);
     42     } else {
     43       printf("      %u: INVALID TRACK REFERENCE!\n", pl->tracks[i]);
     44       LIBMTP_Dump_Errorstack(device);
     45       LIBMTP_Clear_Errorstack(device);
     46     }
     47   }
     48 }
     49 
     50 int main (int argc, char **argv)
     51 {
     52   LIBMTP_mtpdevice_t *device;
     53   LIBMTP_playlist_t *playlists;
     54 
     55   fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n");
     56 
     57   LIBMTP_Init();
     58   device = LIBMTP_Get_First_Device();
     59   if (device == NULL) {
     60     printf("No devices.\n");
     61     exit (0);
     62   }
     63 
     64   // Get playlist listing.
     65   playlists = LIBMTP_Get_Playlist_List(device);
     66   if (playlists == NULL) {
     67     printf("No playlists.\n");
     68   } else {
     69     LIBMTP_playlist_t *pl, *tmp;
     70     pl = playlists;
     71     while (pl != NULL) {
     72       dump_plinfo(device, pl);
     73       tmp = pl;
     74       pl = pl->next;
     75       LIBMTP_destroy_playlist_t(tmp);
     76     }
     77   }
     78 
     79   LIBMTP_Release_Device(device);
     80   printf("OK.\n");
     81   exit (0);
     82 }
     83