blob: d6159d7f74455f7091c7fa97f12da86d790f5134 [file] [log] [blame]
Yavor Goulishev3aa430d2011-05-23 11:54:45 -07001/**
2 * \file trexist.c
3 * Example program to check if a certain track exists on the device.
4 *
5 * Copyright (C) 2006 The libmtp development team.
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#include <limits.h>
25
26static void usage (void)
27{
28 fprintf(stderr, "trexist <trackid>\n");
29}
30
31int main (int argc, char **argv)
32{
33 LIBMTP_mtpdevice_t *device;
34 uint32_t id;
35 char *endptr;
36
37 fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n");
38
39 // We need track ID
40 if ( argc != 2 ) {
41 usage();
42 return 1;
43 }
44
45 // Sanity check song ID
46 id = strtoul(argv[1], &endptr, 10);
47 if ( *endptr != 0 ) {
48 fprintf(stderr, "illegal value %s\n", argv[1]);
49 return 1;
50 } else if ( ! id ) {
51 fprintf(stderr, "bad song id %u\n", id);
52 return 1;
53 }
54
55 LIBMTP_Init();
56 device = LIBMTP_Get_First_Device();
57 if (device == NULL) {
58 printf("No devices. Connect/replug device and try again.\n");
59 exit (0);
60 }
61
62 printf("%s\n", LIBMTP_Track_Exists(device, id) ? "Yes" : "No");
63
64 LIBMTP_Release_Device(device);
65 printf("OK.\n");
66 exit (0);
67}
68