blob: a608d1514c40c8351efb59d620d48a298fd4540b [file] [log] [blame]
Linus Walleijc3a6eeb2010-01-30 07:32:41 +00001/**
Linus Walleij3d78c4c2007-02-15 12:18:12 +00002 * \file sendtr.c
3 * Example program to send a music track to a device.
cjdebenh71f45f02006-11-08 02:19:57 +00004 * This program is derived from the exact equivalent in libnjb.
Linus Walleijc3a6eeb2010-01-30 07:32:41 +00005 * based on Enrique Jorreto Ledesma's work on the original program by
cjdebenh71f45f02006-11-08 02:19:57 +00006 * Shaun Jackman and Linus Walleij.
Linus Walleij3d78c4c2007-02-15 12:18:12 +00007 *
Linus Walleijc3a6eeb2010-01-30 07:32:41 +00008 * Copyright (C) 2003-2010 Linus Walleij <triad@df.lth.se>
Linus Walleij3d78c4c2007-02-15 12:18:12 +00009 * Copyright (C) 2003-2005 Shaun Jackman
10 * Copyright (C) 2003-2005 Enrique Jorrete Ledesma
11 * Copyright (C) 2006 Chris A. Debenham <chris@adebenham.com>
Linus Walleij75fe2bf2008-02-12 07:34:35 +000012 * Copyright (C) 2008 Nicolas Pennequin <nicolas.pennequin@free.fr>
Linus Walleij4347fda2008-09-19 22:28:45 +000013 * Copyright (C) 2008 Joseph Nahmias <joe@nahmias.net>
Linus Walleij3d78c4c2007-02-15 12:18:12 +000014 *
15 * This library is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU Lesser General Public
17 * License as published by the Free Software Foundation; either
18 * version 2 of the License, or (at your option) any later version.
19 *
20 * This library is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * Lesser General Public License for more details.
24 *
25 * You should have received a copy of the GNU Lesser General Public
26 * License along with this library; if not, write to the
27 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
28 * Boston, MA 02111-1307, USA.
cjdebenh71f45f02006-11-08 02:19:57 +000029 */
Linus Walleij05358382007-08-06 20:46:35 +000030
Linus Walleij2eaaff02009-01-15 21:30:36 +000031#include <stdlib.h>
32#include <limits.h>
Linus Walleijbde621f2006-02-22 16:11:35 +000033#include <string.h>
cjdebenhcb4ac9f2006-11-03 02:00:49 +000034#include <libgen.h>
Linus Walleijbde621f2006-02-22 16:11:35 +000035#include <sys/stat.h>
cjdebenhcb4ac9f2006-11-03 02:00:49 +000036#include <sys/types.h>
37#include <fcntl.h>
Linus Walleij56c63952008-06-08 21:55:58 +000038#ifdef HAVE_LANGINFO_H
39#include <langinfo.h>
40#endif
Linus Walleij843210f2010-10-17 22:40:45 +000041
42#include "config.h"
43#include "common.h"
44#include "util.h"
45#include "connect.h"
cjdebenhcb4ac9f2006-11-03 02:00:49 +000046#include "libmtp.h"
47#include "pathutils.h"
Linus Walleijbde621f2006-02-22 16:11:35 +000048
cjdebenhcb4ac9f2006-11-03 02:00:49 +000049extern LIBMTP_folder_t *folders;
50extern LIBMTP_file_t *files;
51extern LIBMTP_mtpdevice_t *device;
52
cjdebenhc80f9b42006-11-09 22:29:26 +000053void sendtrack_usage (void)
cjdebenh71f45f02006-11-08 02:19:57 +000054{
Linus Walleij31b74292008-05-02 23:29:06 +000055 fprintf(stderr, "usage: sendtr [ -D debuglvl ] [ -q ]\n");
56 fprintf(stderr, "-t <title> -a <artist> -A <Album artist> -w <writer or composer>\n");
57 fprintf(stderr, " -l <album> -c <codec> -g <genre> -n <track number> -y <year>\n");
Linus Walleij4347fda2008-09-19 22:28:45 +000058 fprintf(stderr, " -d <duration in seconds> -s <storage_id> <local path> <remote path>\n");
cjdebenh71f45f02006-11-08 02:19:57 +000059 fprintf(stderr, "(-q means the program will not ask for missing information.)\n");
60}
Linus Walleijbde621f2006-02-22 16:11:35 +000061
Linus Walleijbde621f2006-02-22 16:11:35 +000062static char *prompt (const char *prompt, char *buffer, size_t bufsz, int required)
63{
64 char *cp, *bp;
Linus Walleij843210f2010-10-17 22:40:45 +000065
Linus Walleijbde621f2006-02-22 16:11:35 +000066 while (1) {
67 fprintf(stdout, "%s> ", prompt);
68 if ( fgets(buffer, bufsz, stdin) == NULL ) {
69 if (ferror(stdin)) {
70 perror("fgets");
71 } else {
72 fprintf(stderr, "EOF on stdin\n");
73 }
74 return NULL;
75 }
Linus Walleij843210f2010-10-17 22:40:45 +000076
Linus Walleijbde621f2006-02-22 16:11:35 +000077 cp = strrchr(buffer, '\n');
78 if ( cp != NULL ) *cp = '\0';
Linus Walleij843210f2010-10-17 22:40:45 +000079
Linus Walleijbde621f2006-02-22 16:11:35 +000080 bp = buffer;
81 while ( bp != cp ) {
82 if ( *bp != ' ' && *bp != '\t' ) return bp;
83 bp++;
84 }
Linus Walleij843210f2010-10-17 22:40:45 +000085
Linus Walleijbde621f2006-02-22 16:11:35 +000086 if (! required) return bp;
87 }
88}
89
Linus Walleij75fe2bf2008-02-12 07:34:35 +000090static int add_track_to_album(LIBMTP_album_t *albuminfo, LIBMTP_track_t *trackmeta)
91{
Linus Walleij95640132008-02-12 11:57:37 +000092 LIBMTP_album_t *album;
Venkateswara Rao Mandela0c6c8fc2012-05-16 13:08:50 +020093 LIBMTP_album_t *album_orig;
Linus Walleij95640132008-02-12 11:57:37 +000094 LIBMTP_album_t *found_album = NULL;
Linus Walleij75fe2bf2008-02-12 07:34:35 +000095 int ret;
96
Linus Walleij75fe2bf2008-02-12 07:34:35 +000097 /* Look for the album */
Linus Walleij95640132008-02-12 11:57:37 +000098 album = LIBMTP_Get_Album_List(device);
Venkateswara Rao Mandela0c6c8fc2012-05-16 13:08:50 +020099 album_orig = album;
Linus Walleij75fe2bf2008-02-12 07:34:35 +0000100 while(album != NULL) {
Linus Walleij31b74292008-05-02 23:29:06 +0000101 if ((album->name != NULL &&
Linus Walleijbbd91422008-02-12 12:00:51 +0000102 album->artist != NULL &&
103 !strcmp(album->name, albuminfo->name) &&
Linus Walleij31b74292008-05-02 23:29:06 +0000104 !strcmp(album->artist, albuminfo->artist)) ||
105 (album->name != NULL &&
106 album->composer != NULL &&
107 !strcmp(album->name, albuminfo->name) &&
108 !strcmp(album->composer, albuminfo->composer))) {
Linus Walleij95640132008-02-12 11:57:37 +0000109 /* Disconnect this album for later use */
110 found_album = album;
111 album = album->next;
112 found_album->next = NULL;
113 } else {
Linus Walleij95640132008-02-12 11:57:37 +0000114 album = album->next;
Venkateswara Rao Mandela0c6c8fc2012-05-16 13:08:50 +0200115 }
116 }
117
118 if (found_album == NULL) {
119 printf("Could not find Album. Retrying with only Album name\n");
120 album = album_orig;
121 while(album != NULL) {
122 if ((album->name != NULL) &&
123 !strcmp(album->name, albuminfo->name) ){
124 /* Disconnect this album for later use */
125 found_album = album;
126 album = album->next;
127 found_album->next = NULL;
128 } else {
129 album = album->next;
130 }
Linus Walleij75fe2bf2008-02-12 07:34:35 +0000131 }
Linus Walleij75fe2bf2008-02-12 07:34:35 +0000132 }
Linus Walleij843210f2010-10-17 22:40:45 +0000133
Linus Walleij95640132008-02-12 11:57:37 +0000134 if (found_album != NULL) {
135 uint32_t *tracks;
136
137 tracks = (uint32_t *)malloc((found_album->no_tracks+1) * sizeof(uint32_t));
138 printf("Album \"%s\" found: updating...\n", found_album->name);
Linus Walleij75fe2bf2008-02-12 07:34:35 +0000139 if (!tracks) {
Linus Walleij95640132008-02-12 11:57:37 +0000140 printf("failed malloc in add_track_to_album()\n");
Linus Walleij75fe2bf2008-02-12 07:34:35 +0000141 return 1;
142 }
Linus Walleij95640132008-02-12 11:57:37 +0000143 found_album->no_tracks++;
144 if (found_album->tracks != NULL) {
145 memcpy(tracks, found_album->tracks, found_album->no_tracks * sizeof(uint32_t));
146 free(found_album->tracks);
147 }
Linus Walleij95640132008-02-12 11:57:37 +0000148 tracks[found_album->no_tracks-1] = trackmeta->item_id;
Linus Walleijbbd91422008-02-12 12:00:51 +0000149 found_album->tracks = tracks;
Linus Walleij95640132008-02-12 11:57:37 +0000150 ret = LIBMTP_Update_Album(device, found_album);
Linus Walleij75fe2bf2008-02-12 07:34:35 +0000151 } else {
Linus Walleij95640132008-02-12 11:57:37 +0000152 uint32_t *trackid;
Linus Walleij843210f2010-10-17 22:40:45 +0000153
Linus Walleij95640132008-02-12 11:57:37 +0000154 trackid = (uint32_t *)malloc(sizeof(uint32_t));
155 *trackid = trackmeta->item_id;
156 albuminfo->tracks = trackid;
157 albuminfo->no_tracks = 1;
Linus Walleijea68f1f2008-06-22 21:54:44 +0000158 albuminfo->storage_id = trackmeta->storage_id;
Linus Walleij75fe2bf2008-02-12 07:34:35 +0000159 printf("Album doesn't exist: creating...\n");
Linus Walleijea68f1f2008-06-22 21:54:44 +0000160 ret = LIBMTP_Create_New_Album(device, albuminfo);
Linus Walleij95640132008-02-12 11:57:37 +0000161 /* albuminfo will be destroyed later by caller */
Linus Walleij75fe2bf2008-02-12 07:34:35 +0000162 }
Linus Walleijc3a6eeb2010-01-30 07:32:41 +0000163
Venkateswara Rao Mandela0c6c8fc2012-05-16 13:08:50 +0200164 /* Delete the earlier retrieved Album list */
165 album=album_orig;
166 while(album!=NULL){
167 LIBMTP_album_t *tmp;
168
169 tmp = album;
170 album = album->next;
171 LIBMTP_destroy_album_t(tmp);
172 }
173
Linus Walleij75fe2bf2008-02-12 07:34:35 +0000174 if (ret != 0) {
175 printf("Error creating or updating album.\n");
Linus Walleijf3296622008-09-04 20:53:56 +0000176 printf("(This could be due to that your device does not support albums.)\n");
Linus Walleij75fe2bf2008-02-12 07:34:35 +0000177 LIBMTP_Dump_Errorstack(device);
178 LIBMTP_Clear_Errorstack(device);
179 } else {
Linus Walleij95640132008-02-12 11:57:37 +0000180 printf("success!\n");
Linus Walleij75fe2bf2008-02-12 07:34:35 +0000181 }
Linus Walleij31b74292008-05-02 23:29:06 +0000182 return ret;
Linus Walleij75fe2bf2008-02-12 07:34:35 +0000183}
184
Linus Walleij28ad9b72009-09-21 12:10:35 +0000185int sendtrack_function(char * from_path, char * to_path, char *partist, char *palbumartist, char *ptitle, char *pgenre, char *palbum, char *pcomposer, uint16_t tracknum, uint16_t length, uint16_t year, uint32_t storageid, uint16_t quiet)
Linus Walleijbde621f2006-02-22 16:11:35 +0000186{
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000187 char *filename, *parent;
Linus Walleij31b74292008-05-02 23:29:06 +0000188 char artist[80], albumartist[80], title[80], genre[80], album[80], composer[80];
Marcus Meissnerff7e5452015-10-04 13:07:18 +0200189 char *to_path_copy = NULL;
Linus Walleijbde621f2006-02-22 16:11:35 +0000190 char num[80];
Linus Walleijbde621f2006-02-22 16:11:35 +0000191 uint64_t filesize;
Linus Walleij3eb115c2006-06-05 10:28:24 +0000192 uint32_t parent_id = 0;
Linus Walleijbde621f2006-02-22 16:11:35 +0000193 struct stat sb;
Linus Walleijbde621f2006-02-22 16:11:35 +0000194 LIBMTP_track_t *trackmeta;
Linus Walleij75fe2bf2008-02-12 07:34:35 +0000195 LIBMTP_album_t *albuminfo;
196 int ret;
197
Linus Walleij28ad9b72009-09-21 12:10:35 +0000198 printf("Sending track %s to %s\n", from_path, to_path);
Linus Walleij75fe2bf2008-02-12 07:34:35 +0000199
Marcus Meissnerff7e5452015-10-04 13:07:18 +0200200 to_path_copy = strdup(to_path);
201 parent = dirname(to_path_copy);
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000202 parent_id = parse_path (parent,files,folders);
203 if (parent_id == -1) {
Marcus Meissnerff7e5452015-10-04 13:07:18 +0200204 free (to_path_copy);
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000205 printf("Parent folder could not be found, skipping\n");
206 return 1;
Linus Walleijbde621f2006-02-22 16:11:35 +0000207 }
Marcus Meissnerff7e5452015-10-04 13:07:18 +0200208 strcpy (to_path_copy,to_path);
209 filename = basename(to_path_copy);
Linus Walleijbde621f2006-02-22 16:11:35 +0000210
Linus Walleij843210f2010-10-17 22:40:45 +0000211 if (stat(from_path, &sb) == -1) {
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000212 fprintf(stderr, "%s: ", from_path);
Linus Walleijbde621f2006-02-22 16:11:35 +0000213 perror("stat");
Marcus Meissnerff7e5452015-10-04 13:07:18 +0200214 free (to_path_copy);
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000215 return 1;
Linus Walleij17e39f72006-02-23 15:54:28 +0000216 }
Linus Walleij843210f2010-10-17 22:40:45 +0000217
Marcus Meissnerff7e5452015-10-04 13:07:18 +0200218 if (!S_ISREG(sb.st_mode)) {
219 free (to_path_copy);
Linus Walleij843210f2010-10-17 22:40:45 +0000220 return 0;
Marcus Meissnerff7e5452015-10-04 13:07:18 +0200221 }
Linus Walleij843210f2010-10-17 22:40:45 +0000222
223 filesize = sb.st_size;
Marcus Meissner9959f5b2015-04-11 13:33:48 +0200224
225 trackmeta = LIBMTP_new_track_t();
Linus Walleij843210f2010-10-17 22:40:45 +0000226 trackmeta->filetype = find_filetype (from_path);
227 if (!LIBMTP_FILETYPE_IS_TRACK(trackmeta->filetype)) {
228 printf("Not a valid track codec: \"%s\"\n", LIBMTP_Get_Filetype_Description(trackmeta->filetype));
Marcus Meissner9959f5b2015-04-11 13:33:48 +0200229 LIBMTP_destroy_track_t(trackmeta);
Marcus Meissnerff7e5452015-10-04 13:07:18 +0200230 free (to_path_copy);
Linus Walleij843210f2010-10-17 22:40:45 +0000231 return 1;
232 }
233
234 if ((ptitle == NULL) && (quiet == 0)) {
235 if ( (ptitle = prompt("Title", title, 80, 0)) != NULL )
236 if (!strlen(ptitle)) ptitle = NULL;
237 }
238
239 if ((palbum == NULL) && (quiet == 0)) {
240 if ( (palbum = prompt("Album", album, 80, 0)) != NULL )
241 if (!strlen(palbum)) palbum = NULL;
242 }
243
244 if ((palbumartist == NULL) && (quiet == 0)) {
245 if ( (palbumartist = prompt("Album artist", albumartist, 80, 0)) != NULL )
246 if (!strlen(palbumartist)) palbumartist = NULL;
247 }
248
249 if ((partist == NULL) && (quiet == 0)) {
250 if ( (partist = prompt("Artist", artist, 80, 0)) != NULL )
251 if (!strlen(partist)) partist = NULL;
252 }
253
254 if ((pcomposer == NULL) && (quiet == 0)) {
255 if ( (pcomposer = prompt("Writer or Composer", composer, 80, 0)) != NULL )
256 if (!strlen(pcomposer)) pcomposer = NULL;
257 }
258
259 if ((pgenre == NULL) && (quiet == 0)) {
260 if ( (pgenre = prompt("Genre", genre, 80, 0)) != NULL )
261 if (!strlen(pgenre)) pgenre = NULL;
262 }
263
264 if ((tracknum == 0) && (quiet == 0)) {
265 char *pnum;
266 if ( (pnum = prompt("Track number", num, 80, 0)) == NULL )
267 tracknum = 0;
268 else
269 tracknum = strtoul(pnum, 0, 10);
270 }
271
272 if ((year == 0) && (quiet == 0)) {
273 char *pnum;
274 if ( (pnum = prompt("Year", num, 80, 0)) == NULL )
275 year = 0;
276 else
277 year = strtoul(pnum, 0, 10);
278 }
279
280 if ((length == 0) && (quiet == 0)) {
281 char *pnum;
282 if ( (pnum = prompt("Length", num, 80, 0)) == NULL )
283 length = 0;
284 else
285 length = strtoul(pnum, 0, 10);
286 }
287
288 printf("Sending track:\n");
289 printf("Codec: %s\n", LIBMTP_Get_Filetype_Description(trackmeta->filetype));
290 if (ptitle) {
291 printf("Title: %s\n", ptitle);
292 trackmeta->title = strdup(ptitle);
293 }
Marcus Meissner9959f5b2015-04-11 13:33:48 +0200294
295 albuminfo = LIBMTP_new_album_t();
296
Linus Walleij843210f2010-10-17 22:40:45 +0000297 if (palbum) {
298 printf("Album: %s\n", palbum);
299 trackmeta->album = strdup(palbum);
300 albuminfo->name = strdup(palbum);
301 }
302 if (palbumartist) {
303 printf("Album artist: %s\n", palbumartist);
304 albuminfo->artist = strdup(palbumartist);
305 }
306 if (partist) {
307 printf("Artist: %s\n", partist);
308 trackmeta->artist = strdup(partist);
309 if (palbumartist == NULL)
310 albuminfo->artist = strdup(partist);
311 }
312 if (pcomposer) {
313 printf("Writer or Composer: %s\n", pcomposer);
314 trackmeta->composer = strdup(pcomposer);
315 albuminfo->composer = strdup(pcomposer);
316 }
317 if (pgenre) {
318 printf("Genre: %s\n", pgenre);
319 trackmeta->genre = strdup(pgenre);
320 albuminfo->genre = strdup(pgenre);
321 }
322 if (year > 0) {
323 char tmp[80];
324 printf("Year: %d\n", year);
325 snprintf(tmp, sizeof(tmp)-1, "%4d0101T0000.0", year);
326 tmp[sizeof(tmp)-1] = '\0';
327 trackmeta->date = strdup(tmp);
328 }
329 if (tracknum > 0) {
330 printf("Track no: %d\n", tracknum);
331 trackmeta->tracknumber = tracknum;
332 }
333 if (length > 0) {
334 printf("Length: %d\n", length);
335 // Multiply by 1000 since this is in milliseconds
336 trackmeta->duration = length * 1000;
337 }
338 // We should always have this
339 if (filename != NULL) {
340 trackmeta->filename = strdup(filename);
341 }
342 trackmeta->filesize = filesize;
343 trackmeta->parent_id = parent_id;
344 {
345 int rc;
346 char *desc = NULL;
347 LIBMTP_devicestorage_t *pds = NULL;
348
349 if (0 != (rc=LIBMTP_Get_Storage(device, LIBMTP_STORAGE_SORTBY_NOTSORTED))) {
350 perror("LIBMTP_Get_Storage()");
351 exit(-1);
352 }
353 for (pds = device->storage; pds != NULL; pds = pds->next) {
354 if (pds->id == storageid) {
355 desc = strdup(pds->StorageDescription);
356 break;
357 }
358 }
359 if (NULL != desc) {
360 printf("Storage ID: %s (%u)\n", desc, storageid);
361 free(desc);
362 } else
363 printf("Storage ID: %u\n", storageid);
364 trackmeta->storage_id = storageid;
365 }
366
367 printf("Sending track...\n");
368 ret = LIBMTP_Send_Track_From_File(device, from_path, trackmeta, progress, NULL);
369 printf("\n");
370 if (ret != 0) {
371 printf("Error sending track.\n");
372 LIBMTP_Dump_Errorstack(device);
373 LIBMTP_Clear_Errorstack(device);
374 ret = 1;
375 } else {
376 printf("New track ID: %d\n", trackmeta->item_id);
377 }
378
379 /* Add here add to album call */
380 if (palbum)
381 ret = add_track_to_album(albuminfo, trackmeta);
382
383 LIBMTP_destroy_album_t(albuminfo);
384 LIBMTP_destroy_track_t(trackmeta);
Marcus Meissnerff7e5452015-10-04 13:07:18 +0200385 free (to_path_copy);
Linus Walleij843210f2010-10-17 22:40:45 +0000386
387 return ret;
Linus Walleijbde621f2006-02-22 16:11:35 +0000388}
cjdebenh71f45f02006-11-08 02:19:57 +0000389
Linus Walleij843210f2010-10-17 22:40:45 +0000390int sendtrack_command (int argc, char **argv) {
Marcus Meissneraca5c262015-04-11 13:26:49 +0200391 int opt, ret;
Linus Walleij070e9b42007-01-22 08:49:28 +0000392 extern int optind;
393 extern char *optarg;
394 char *partist = NULL;
Linus Walleij31b74292008-05-02 23:29:06 +0000395 char *palbumartist = NULL;
396 char *pcomposer = NULL;
Linus Walleij070e9b42007-01-22 08:49:28 +0000397 char *ptitle = NULL;
398 char *pgenre = NULL;
399 char *pcodec = NULL;
400 char *palbum = NULL;
401 uint16_t tracknum = 0;
402 uint16_t length = 0;
403 uint16_t year = 0;
404 uint16_t quiet = 0;
Linus Walleij4347fda2008-09-19 22:28:45 +0000405 uint32_t storageid = 0;
406 while ( (opt = getopt(argc, argv, "qD:t:a:A:w:l:c:g:n:d:y:s:")) != -1 ) {
Linus Walleij070e9b42007-01-22 08:49:28 +0000407 switch (opt) {
408 case 't':
Marcus Meissnerff7e5452015-10-04 13:07:18 +0200409 free (ptitle);
Linus Walleij070e9b42007-01-22 08:49:28 +0000410 ptitle = strdup(optarg);
411 break;
412 case 'a':
Marcus Meissnerff7e5452015-10-04 13:07:18 +0200413 free (partist);
Linus Walleij070e9b42007-01-22 08:49:28 +0000414 partist = strdup(optarg);
415 break;
Linus Walleij31b74292008-05-02 23:29:06 +0000416 case 'A':
Marcus Meissnerff7e5452015-10-04 13:07:18 +0200417 free (palbumartist);
Linus Walleij31b74292008-05-02 23:29:06 +0000418 palbumartist = strdup(optarg);
419 break;
420 case 'w':
Marcus Meissnerff7e5452015-10-04 13:07:18 +0200421 free (pcomposer);
Linus Walleij31b74292008-05-02 23:29:06 +0000422 pcomposer = strdup(optarg);
423 break;
Linus Walleij070e9b42007-01-22 08:49:28 +0000424 case 'l':
Marcus Meissnerff7e5452015-10-04 13:07:18 +0200425 free (palbum);
Linus Walleij070e9b42007-01-22 08:49:28 +0000426 palbum = strdup(optarg);
427 break;
428 case 'c':
Marcus Meissnerff7e5452015-10-04 13:07:18 +0200429 free (pcodec);
Linus Walleij070e9b42007-01-22 08:49:28 +0000430 pcodec = strdup(optarg); // FIXME: DSM check for MP3, WAV or WMA
431 break;
432 case 'g':
Marcus Meissnerff7e5452015-10-04 13:07:18 +0200433 free (pgenre);
Linus Walleij070e9b42007-01-22 08:49:28 +0000434 pgenre = strdup(optarg);
435 break;
436 case 'n':
437 tracknum = atoi(optarg);
438 break;
Linus Walleij4347fda2008-09-19 22:28:45 +0000439 case 's':
440 storageid = (uint32_t) strtoul(optarg, NULL, 0);
441 break;
Linus Walleij070e9b42007-01-22 08:49:28 +0000442 case 'd':
443 length = atoi(optarg);
444 break;
445 case 'y':
446 year = atoi(optarg);
447 break;
448 case 'q':
449 quiet = 1;
450 break;
451 default:
452 sendtrack_usage();
453 }
454 }
455 argc -= optind;
456 argv += optind;
Linus Walleij843210f2010-10-17 22:40:45 +0000457
Linus Walleij070e9b42007-01-22 08:49:28 +0000458 if ( argc != 2 ) {
459 printf("You need to pass a filename and destination.\n");
460 sendtrack_usage();
Marcus Meissner61fe60f2015-10-04 12:39:40 +0200461 ret = 0;
462 } else {
463 checklang();
464 printf("%s,%s,%s,%s,%s,%s,%s,%s,%d%d,%d,%u,%d\n",argv[0],argv[1],partist,palbumartist,ptitle,pgenre,palbum,pcomposer,tracknum, length, year, storageid, quiet);
465 ret = sendtrack_function(argv[0],argv[1],partist,palbumartist,ptitle,pgenre,palbum,pcomposer, tracknum, length, year, storageid, quiet);
Linus Walleij070e9b42007-01-22 08:49:28 +0000466 }
Marcus Meissneraca5c262015-04-11 13:26:49 +0200467 free (ptitle);
468 free (partist);
469 free (palbumartist);
470 free (pcomposer);
471 free (palbum);
472 free (pcodec);
473 free (pgenre);
474 return ret;
cjdebenh71f45f02006-11-08 02:19:57 +0000475}