3 * Example program to create a playlist on a device.
5 * Copyright (C) 2006 Robert Reardon <rreardon@monkshatch.vispa.com>
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.
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.
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.
30 static void usage(void) {
31 printf("Usage: newplaylist -i <fileid/trackid> -n <playlistname> -s <storage_id> -p <parent_id>\n");
35 int main (int argc, char **argv) {
39 LIBMTP_mtpdevice_t *device = NULL;
43 char *playlistname = NULL;
45 uint32_t storageid = 0;
46 uint32_t parentid = 0;
48 fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n");
50 while ( (opt = getopt(argc, argv, "hn:i:s:p:")) != -1 ) {
56 if ((tmp = realloc(ids, sizeof(uint32_t) * (idcount))) == NULL) {
57 printf("realloc failed\n");
61 ids[(idcount-1)] = strtoul(optarg, &rest, 0);
64 playlistname = strdup(optarg);
67 storageid = (uint32_t) strtoul(optarg, NULL, 0);
70 parentid = (uint32_t) strtoul(optarg, NULL, 0);
79 if ( playlistname == NULL) {
80 printf("You need to supply a playlist name.\n");
85 printf("You need to supply one or more track IDs\n");
91 device = LIBMTP_Get_First_Device();
93 printf("No devices.\n");
97 LIBMTP_playlist_t *playlist = LIBMTP_new_playlist_t();
98 playlist->name = playlistname;
99 playlist->no_tracks = idcount;
100 playlist->tracks = ids;
101 playlist->parent_id = parentid;
102 playlist->storage_id = storageid;
103 int ret = LIBMTP_Create_New_Playlist(device,playlist);
105 printf("Couldn't create playlist object\n");
106 LIBMTP_Dump_Errorstack(device);
107 LIBMTP_Clear_Errorstack(device);
110 printf("Created new playlist: %u\n", playlist->playlist_id);
113 LIBMTP_Release_Device(device);