Blame examples/playlists.c

Packit Bot a284d4
/** 
Packit Bot a284d4
 * \file playlists.c
Packit Bot a284d4
 * Example program to list the playlists on a device.
Packit Bot a284d4
 *
Packit Bot a284d4
 * Copyright (C) 2005-2007 Linus Walleij <triad@df.lth.se>
Packit Bot a284d4
 *
Packit Bot a284d4
 * This library is free software; you can redistribute it and/or
Packit Bot a284d4
 * modify it under the terms of the GNU Lesser General Public
Packit Bot a284d4
 * License as published by the Free Software Foundation; either
Packit Bot a284d4
 * version 2 of the License, or (at your option) any later version.
Packit Bot a284d4
 *
Packit Bot a284d4
 * This library is distributed in the hope that it will be useful,
Packit Bot a284d4
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Bot a284d4
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Bot a284d4
 * Lesser General Public License for more details.
Packit Bot a284d4
 *
Packit Bot a284d4
 * You should have received a copy of the GNU Lesser General Public
Packit Bot a284d4
 * License along with this library; if not, write to the
Packit Bot a284d4
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Packit Bot a284d4
 * Boston, MA 02111-1307, USA.
Packit Bot a284d4
 */
Packit Bot a284d4
#include "common.h"
Packit Bot a284d4
#include <stdlib.h>
Packit Bot a284d4
Packit Bot a284d4
static void dump_plinfo(LIBMTP_mtpdevice_t *device, LIBMTP_playlist_t *pl)
Packit Bot a284d4
{
Packit Bot a284d4
  uint32_t i;
Packit Bot a284d4
Packit Bot a284d4
  printf("Playlist ID: %d\n", pl->playlist_id);
Packit Bot a284d4
  if (pl->name != NULL)
Packit Bot a284d4
    printf("   Name: %s\n", pl->name);
Packit Bot a284d4
  printf("   Parent ID: %d\n", pl->parent_id);
Packit Bot a284d4
  printf("   Tracks:\n");
Packit Bot a284d4
Packit Bot a284d4
  for (i = 0; i < pl->no_tracks; i++) {
Packit Bot a284d4
    LIBMTP_track_t *track;
Packit Bot a284d4
    
Packit Bot a284d4
    track = LIBMTP_Get_Trackmetadata(device, pl->tracks[i]);
Packit Bot a284d4
    if (track != NULL) {
Packit Bot a284d4
      printf("      %u: %s - %s\n", pl->tracks[i], track->artist, track->title);
Packit Bot a284d4
      LIBMTP_destroy_track_t(track);
Packit Bot a284d4
    } else {
Packit Bot a284d4
      printf("      %u: INVALID TRACK REFERENCE!\n", pl->tracks[i]);
Packit Bot a284d4
      LIBMTP_Dump_Errorstack(device);
Packit Bot a284d4
      LIBMTP_Clear_Errorstack(device);
Packit Bot a284d4
    }
Packit Bot a284d4
  }
Packit Bot a284d4
}
Packit Bot a284d4
Packit Bot a284d4
int main (int argc, char **argv)
Packit Bot a284d4
{
Packit Bot a284d4
  LIBMTP_mtpdevice_t *device;
Packit Bot a284d4
  LIBMTP_playlist_t *playlists;
Packit Bot a284d4
Packit Bot a284d4
  fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n");
Packit Bot a284d4
Packit Bot a284d4
  LIBMTP_Init();
Packit Bot a284d4
  device = LIBMTP_Get_First_Device();
Packit Bot a284d4
  if (device == NULL) {
Packit Bot a284d4
    printf("No devices.\n");
Packit Bot a284d4
    exit (0);
Packit Bot a284d4
  }
Packit Bot a284d4
  
Packit Bot a284d4
  // Get playlist listing.
Packit Bot a284d4
  playlists = LIBMTP_Get_Playlist_List(device);
Packit Bot a284d4
  if (playlists == NULL) {
Packit Bot a284d4
    printf("No playlists.\n");
Packit Bot a284d4
  } else {
Packit Bot a284d4
    LIBMTP_playlist_t *pl, *tmp;
Packit Bot a284d4
    pl = playlists;
Packit Bot a284d4
    while (pl != NULL) {
Packit Bot a284d4
      dump_plinfo(device, pl);
Packit Bot a284d4
      tmp = pl;
Packit Bot a284d4
      pl = pl->next;
Packit Bot a284d4
      LIBMTP_destroy_playlist_t(tmp);
Packit Bot a284d4
    }
Packit Bot a284d4
  }
Packit Bot a284d4
    
Packit Bot a284d4
  LIBMTP_Release_Device(device);
Packit Bot a284d4
  printf("OK.\n");
Packit Bot a284d4
  exit (0);
Packit Bot a284d4
}