blob: 67a2eb7d5bbda01bcc84253bd06cc470951e5713 [file] [log] [blame]
Linus Walleij3d78c4c2007-02-15 12:18:12 +00001/**
2 * \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.
cjdebenh71f45f02006-11-08 02:19:57 +00005 * based on Enrique Jorreto Ledesma's work on the original program by
6 * Shaun Jackman and Linus Walleij.
Linus Walleij3d78c4c2007-02-15 12:18:12 +00007 *
Linus Walleij2242b022009-01-02 01:44:00 +00008 * Copyright (C) 2003-2009 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 Walleij2f1b6402009-06-15 19:49:33 +000031#include "config.h"
Linus Walleij56c63952008-06-08 21:55:58 +000032#include "common.h"
Linus Walleij59765e82008-08-15 07:17:12 +000033#include "util.h"
Linus Walleij2eaaff02009-01-15 21:30:36 +000034#include <stdlib.h>
35#include <limits.h>
Linus Walleijbde621f2006-02-22 16:11:35 +000036#include <string.h>
cjdebenhcb4ac9f2006-11-03 02:00:49 +000037#include <libgen.h>
Linus Walleijbde621f2006-02-22 16:11:35 +000038#include <sys/stat.h>
cjdebenhcb4ac9f2006-11-03 02:00:49 +000039#include <sys/types.h>
40#include <fcntl.h>
Linus Walleij56c63952008-06-08 21:55:58 +000041#ifdef HAVE_LANGINFO_H
42#include <langinfo.h>
43#endif
cjdebenhcb4ac9f2006-11-03 02:00:49 +000044#include "libmtp.h"
45#include "pathutils.h"
Linus Walleijbde621f2006-02-22 16:11:35 +000046
cjdebenhcb4ac9f2006-11-03 02:00:49 +000047extern LIBMTP_folder_t *folders;
48extern LIBMTP_file_t *files;
49extern LIBMTP_mtpdevice_t *device;
50
Linus Walleij28ad9b72009-09-21 12:10:35 +000051int sendtrack_function (char *, char *, char *, char *, char *, char *, char *, char *, uint16_t, uint16_t, uint16_t, uint32_t, uint16_t);
cjdebenhc80f9b42006-11-09 22:29:26 +000052void sendtrack_command (int, char **);
53void sendtrack_usage (void);
cjdebenh71f45f02006-11-08 02:19:57 +000054
cjdebenhc80f9b42006-11-09 22:29:26 +000055void sendtrack_usage (void)
cjdebenh71f45f02006-11-08 02:19:57 +000056{
Linus Walleij31b74292008-05-02 23:29:06 +000057 fprintf(stderr, "usage: sendtr [ -D debuglvl ] [ -q ]\n");
58 fprintf(stderr, "-t <title> -a <artist> -A <Album artist> -w <writer or composer>\n");
59 fprintf(stderr, " -l <album> -c <codec> -g <genre> -n <track number> -y <year>\n");
Linus Walleij4347fda2008-09-19 22:28:45 +000060 fprintf(stderr, " -d <duration in seconds> -s <storage_id> <local path> <remote path>\n");
cjdebenh71f45f02006-11-08 02:19:57 +000061 fprintf(stderr, "(-q means the program will not ask for missing information.)\n");
62}
Linus Walleijbde621f2006-02-22 16:11:35 +000063
Linus Walleijbde621f2006-02-22 16:11:35 +000064static char *prompt (const char *prompt, char *buffer, size_t bufsz, int required)
65{
66 char *cp, *bp;
67
68 while (1) {
69 fprintf(stdout, "%s> ", prompt);
70 if ( fgets(buffer, bufsz, stdin) == NULL ) {
71 if (ferror(stdin)) {
72 perror("fgets");
73 } else {
74 fprintf(stderr, "EOF on stdin\n");
75 }
76 return NULL;
77 }
78
79 cp = strrchr(buffer, '\n');
80 if ( cp != NULL ) *cp = '\0';
81
82 bp = buffer;
83 while ( bp != cp ) {
84 if ( *bp != ' ' && *bp != '\t' ) return bp;
85 bp++;
86 }
87
88 if (! required) return bp;
89 }
90}
91
Linus Walleij75fe2bf2008-02-12 07:34:35 +000092static int add_track_to_album(LIBMTP_album_t *albuminfo, LIBMTP_track_t *trackmeta)
93{
Linus Walleij95640132008-02-12 11:57:37 +000094 LIBMTP_album_t *album;
95 LIBMTP_album_t *found_album = NULL;
Linus Walleij75fe2bf2008-02-12 07:34:35 +000096 int ret;
97
Linus Walleij75fe2bf2008-02-12 07:34:35 +000098 /* Look for the album */
Linus Walleij95640132008-02-12 11:57:37 +000099 album = LIBMTP_Get_Album_List(device);
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 {
114 LIBMTP_album_t *tmp;
115
116 tmp = album;
117 album = album->next;
118 LIBMTP_destroy_album_t(tmp);
Linus Walleij75fe2bf2008-02-12 07:34:35 +0000119 }
Linus Walleij75fe2bf2008-02-12 07:34:35 +0000120 }
121
Linus Walleij95640132008-02-12 11:57:37 +0000122 if (found_album != NULL) {
123 uint32_t *tracks;
124
125 tracks = (uint32_t *)malloc((found_album->no_tracks+1) * sizeof(uint32_t));
126 printf("Album \"%s\" found: updating...\n", found_album->name);
Linus Walleij75fe2bf2008-02-12 07:34:35 +0000127 if (!tracks) {
Linus Walleij95640132008-02-12 11:57:37 +0000128 printf("failed malloc in add_track_to_album()\n");
Linus Walleij75fe2bf2008-02-12 07:34:35 +0000129 return 1;
130 }
Linus Walleij95640132008-02-12 11:57:37 +0000131 found_album->no_tracks++;
132 if (found_album->tracks != NULL) {
133 memcpy(tracks, found_album->tracks, found_album->no_tracks * sizeof(uint32_t));
134 free(found_album->tracks);
135 }
Linus Walleij95640132008-02-12 11:57:37 +0000136 tracks[found_album->no_tracks-1] = trackmeta->item_id;
Linus Walleijbbd91422008-02-12 12:00:51 +0000137 found_album->tracks = tracks;
Linus Walleij95640132008-02-12 11:57:37 +0000138 ret = LIBMTP_Update_Album(device, found_album);
139 LIBMTP_destroy_album_t(found_album);
Linus Walleij75fe2bf2008-02-12 07:34:35 +0000140 } else {
Linus Walleij95640132008-02-12 11:57:37 +0000141 uint32_t *trackid;
142
143 trackid = (uint32_t *)malloc(sizeof(uint32_t));
144 *trackid = trackmeta->item_id;
145 albuminfo->tracks = trackid;
146 albuminfo->no_tracks = 1;
Linus Walleijea68f1f2008-06-22 21:54:44 +0000147 albuminfo->storage_id = trackmeta->storage_id;
Linus Walleij75fe2bf2008-02-12 07:34:35 +0000148 printf("Album doesn't exist: creating...\n");
Linus Walleijea68f1f2008-06-22 21:54:44 +0000149 ret = LIBMTP_Create_New_Album(device, albuminfo);
Linus Walleij95640132008-02-12 11:57:37 +0000150 /* albuminfo will be destroyed later by caller */
Linus Walleij75fe2bf2008-02-12 07:34:35 +0000151 }
152
153 if (ret != 0) {
154 printf("Error creating or updating album.\n");
Linus Walleijf3296622008-09-04 20:53:56 +0000155 printf("(This could be due to that your device does not support albums.)\n");
Linus Walleij75fe2bf2008-02-12 07:34:35 +0000156 LIBMTP_Dump_Errorstack(device);
157 LIBMTP_Clear_Errorstack(device);
158 } else {
Linus Walleij95640132008-02-12 11:57:37 +0000159 printf("success!\n");
Linus Walleij75fe2bf2008-02-12 07:34:35 +0000160 }
Linus Walleij31b74292008-05-02 23:29:06 +0000161 return ret;
Linus Walleij75fe2bf2008-02-12 07:34:35 +0000162}
163
Linus Walleij28ad9b72009-09-21 12:10:35 +0000164int 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 +0000165{
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000166 char *filename, *parent;
Linus Walleij31b74292008-05-02 23:29:06 +0000167 char artist[80], albumartist[80], title[80], genre[80], album[80], composer[80];
Linus Walleijbde621f2006-02-22 16:11:35 +0000168 char num[80];
Linus Walleijbde621f2006-02-22 16:11:35 +0000169 uint64_t filesize;
Linus Walleij3eb115c2006-06-05 10:28:24 +0000170 uint32_t parent_id = 0;
Linus Walleijbde621f2006-02-22 16:11:35 +0000171 struct stat sb;
Linus Walleijbde621f2006-02-22 16:11:35 +0000172 LIBMTP_track_t *trackmeta;
Linus Walleij75fe2bf2008-02-12 07:34:35 +0000173 LIBMTP_album_t *albuminfo;
174 int ret;
175
Linus Walleij28ad9b72009-09-21 12:10:35 +0000176 printf("Sending track %s to %s\n", from_path, to_path);
Linus Walleij75fe2bf2008-02-12 07:34:35 +0000177
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000178 trackmeta = LIBMTP_new_track_t();
Linus Walleij75fe2bf2008-02-12 07:34:35 +0000179 albuminfo = LIBMTP_new_album_t();
Linus Walleijd6a49972006-05-02 08:24:54 +0000180
Linus Walleijeb144392008-08-28 14:43:38 +0000181 parent = dirname(strdup(to_path));
182 filename = basename(strdup(to_path));
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000183 parent_id = parse_path (parent,files,folders);
184 if (parent_id == -1) {
185 printf("Parent folder could not be found, skipping\n");
186 return 1;
Linus Walleijbde621f2006-02-22 16:11:35 +0000187 }
Linus Walleijbde621f2006-02-22 16:11:35 +0000188
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000189 if ( stat(from_path, &sb) == -1 ) {
190 fprintf(stderr, "%s: ", from_path);
Linus Walleijbde621f2006-02-22 16:11:35 +0000191 perror("stat");
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000192 return 1;
193 } else if (S_ISREG (sb.st_mode)) {
Linus Walleij05358382007-08-06 20:46:35 +0000194 filesize = sb.st_size;
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000195 trackmeta->filetype = find_filetype (from_path);
Linus Walleij4a712ef2008-05-04 19:21:25 +0000196 if (!LIBMTP_FILETYPE_IS_TRACK(trackmeta->filetype)) {
Linus Walleij10e0ce72008-05-04 19:20:33 +0000197 printf("Not a valid track codec: \"%s\"\n", LIBMTP_Get_Filetype_Description(trackmeta->filetype));
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000198 return 1;
199 }
Linus Walleij28ad9b72009-09-21 12:10:35 +0000200
201 if ((ptitle == NULL) && (quiet == 0)) {
202 if ( (ptitle = prompt("Title", title, 80, 0)) != NULL )
203 if (!strlen(ptitle)) ptitle = NULL;
Linus Walleijbde621f2006-02-22 16:11:35 +0000204 }
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000205
Linus Walleij28ad9b72009-09-21 12:10:35 +0000206 if ((palbum == NULL) && (quiet == 0)) {
207 if ( (palbum = prompt("Album", album, 80, 0)) != NULL )
208 if (!strlen(palbum)) palbum = NULL;
Linus Walleijbde621f2006-02-22 16:11:35 +0000209 }
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000210
Linus Walleij28ad9b72009-09-21 12:10:35 +0000211 if ((palbumartist == NULL) && (quiet == 0)) {
212 if ( (palbumartist = prompt("Album artist", albumartist, 80, 0)) != NULL )
213 if (!strlen(palbumartist)) palbumartist = NULL;
Linus Walleij31b74292008-05-02 23:29:06 +0000214 }
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000215
Linus Walleij28ad9b72009-09-21 12:10:35 +0000216 if ((partist == NULL) && (quiet == 0)) {
217 if ( (partist = prompt("Artist", artist, 80, 0)) != NULL )
218 if (!strlen(partist)) partist = NULL;
Linus Walleij31b74292008-05-02 23:29:06 +0000219 }
Linus Walleij31b74292008-05-02 23:29:06 +0000220
Linus Walleij28ad9b72009-09-21 12:10:35 +0000221 if ((pcomposer == NULL) && (quiet == 0)) {
222 if ( (pcomposer = prompt("Writer or Composer", composer, 80, 0)) != NULL )
223 if (!strlen(pcomposer)) pcomposer = NULL;
Linus Walleijbde621f2006-02-22 16:11:35 +0000224 }
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000225
Linus Walleij28ad9b72009-09-21 12:10:35 +0000226 if ((pgenre == NULL) && (quiet == 0)) {
227 if ( (pgenre = prompt("Genre", genre, 80, 0)) != NULL )
228 if (!strlen(pgenre)) pgenre = NULL;
229 }
230
231 if ((tracknum == 0) && (quiet == 0)) {
Linus Walleijbde621f2006-02-22 16:11:35 +0000232 char *pnum;
233 if ( (pnum = prompt("Track number", num, 80, 0)) == NULL )
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000234 tracknum = 0;
Linus Walleij28ad9b72009-09-21 12:10:35 +0000235 else
236 tracknum = strtoul(pnum, 0, 10);
Linus Walleijbde621f2006-02-22 16:11:35 +0000237 }
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000238
Linus Walleij28ad9b72009-09-21 12:10:35 +0000239 if ((year == 0) && (quiet == 0)) {
Linus Walleijbde621f2006-02-22 16:11:35 +0000240 char *pnum;
241 if ( (pnum = prompt("Year", num, 80, 0)) == NULL )
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000242 year = 0;
Linus Walleij28ad9b72009-09-21 12:10:35 +0000243 else
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000244 year = strtoul(pnum, 0, 10);
Linus Walleijbde621f2006-02-22 16:11:35 +0000245 }
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000246
Linus Walleij28ad9b72009-09-21 12:10:35 +0000247 if ((length == 0) && (quiet == 0)) {
Linus Walleijbde621f2006-02-22 16:11:35 +0000248 char *pnum;
249 if ( (pnum = prompt("Length", num, 80, 0)) == NULL )
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000250 length = 0;
Linus Walleij28ad9b72009-09-21 12:10:35 +0000251 else
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000252 length = strtoul(pnum, 0, 10);
Linus Walleijbde621f2006-02-22 16:11:35 +0000253 }
Linus Walleijbde621f2006-02-22 16:11:35 +0000254
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000255 printf("Sending track:\n");
256 printf("Codec: %s\n", LIBMTP_Get_Filetype_Description(trackmeta->filetype));
257 if (ptitle) {
258 printf("Title: %s\n", ptitle);
259 trackmeta->title = strdup(ptitle);
260 }
261 if (palbum) {
262 printf("Album: %s\n", palbum);
263 trackmeta->album = strdup(palbum);
Linus Walleij75fe2bf2008-02-12 07:34:35 +0000264 albuminfo->name = strdup(palbum);
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000265 }
Linus Walleij31b74292008-05-02 23:29:06 +0000266 if (palbumartist) {
267 printf("Album artist: %s\n", palbumartist);
268 albuminfo->artist = strdup(palbumartist);
269 }
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000270 if (partist) {
271 printf("Artist: %s\n", partist);
272 trackmeta->artist = strdup(partist);
Linus Walleij31b74292008-05-02 23:29:06 +0000273 if (palbumartist == NULL)
Linus Walleij75fe2bf2008-02-12 07:34:35 +0000274 albuminfo->artist = strdup(partist);
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000275 }
Linus Walleij31b74292008-05-02 23:29:06 +0000276
277 if (pcomposer) {
278 printf("Writer or Composer: %s\n", pcomposer);
279 trackmeta->composer = strdup(pcomposer);
280 albuminfo->composer = strdup(pcomposer);
281 }
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000282 if (pgenre) {
283 printf("Genre: %s\n", pgenre);
284 trackmeta->genre = strdup(pgenre);
Linus Walleij75fe2bf2008-02-12 07:34:35 +0000285 albuminfo->genre = strdup(pgenre);
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000286 }
287 if (year > 0) {
288 char tmp[80];
289 printf("Year: %d\n", year);
290 snprintf(tmp, sizeof(tmp)-1, "%4d0101T0000.0", year);
291 tmp[sizeof(tmp)-1] = '\0';
292 trackmeta->date = strdup(tmp);
293 }
294 if (tracknum > 0) {
295 printf("Track no: %d\n", tracknum);
296 trackmeta->tracknumber = tracknum;
297 }
298 if (length > 0) {
299 printf("Length: %d\n", length);
300 // Multiply by 1000 since this is in milliseconds
301 trackmeta->duration = length * 1000;
302 }
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000303 // We should always have this
304 if (filename != NULL) {
305 trackmeta->filename = strdup(filename);
306 }
307 trackmeta->filesize = filesize;
Linus Walleijea68f1f2008-06-22 21:54:44 +0000308 trackmeta->parent_id = parent_id;
Linus Walleij4347fda2008-09-19 22:28:45 +0000309 {
310 int rc;
311 char *desc = NULL;
312 LIBMTP_devicestorage_t *pds = NULL;
313
314 if ( 0 != (rc=LIBMTP_Get_Storage(device, LIBMTP_STORAGE_SORTBY_NOTSORTED)) )
315 {
316 perror("LIBMTP_Get_Storage()");
317 exit(-1);
318 }
319 for (pds = device->storage; pds != NULL; pds = pds->next)
320 {
321 if (pds->id == storageid)
322 {
323 desc = strdup(pds->StorageDescription);
324 break;
325 }
326 }
327 if (NULL != desc)
328 {
329 printf("Storage ID: %s (%u)\n", desc, storageid);
330 free(desc);
331 }
332 else
333 printf("Storage ID: %u\n", storageid);
334 trackmeta->storage_id = storageid;
335 }
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000336
337 printf("Sending track...\n");
Linus Walleijea68f1f2008-06-22 21:54:44 +0000338 ret = LIBMTP_Send_Track_From_File(device, from_path, trackmeta, progress, NULL);
Linus Walleijd2778d12007-08-06 19:24:58 +0000339 printf("\n");
Linus Walleij070e9b42007-01-22 08:49:28 +0000340 if (ret != 0) {
341 printf("Error sending track.\n");
342 LIBMTP_Dump_Errorstack(device);
343 LIBMTP_Clear_Errorstack(device);
344 } else {
345 printf("New track ID: %d\n", trackmeta->item_id);
346 }
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000347
Linus Walleijf3296622008-09-04 20:53:56 +0000348 /* Add here add to album call */
Linus Walleij2242b022009-01-02 01:44:00 +0000349 if (palbum)
350 ret = add_track_to_album(albuminfo, trackmeta);
Linus Walleij31b74292008-05-02 23:29:06 +0000351
Linus Walleij75fe2bf2008-02-12 07:34:35 +0000352 LIBMTP_destroy_album_t(albuminfo);
Linus Walleij17e39f72006-02-23 15:54:28 +0000353 LIBMTP_destroy_track_t(trackmeta);
Linus Walleij75fe2bf2008-02-12 07:34:35 +0000354
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000355 return 0;
Linus Walleij17e39f72006-02-23 15:54:28 +0000356 }
Linus Walleijbde621f2006-02-22 16:11:35 +0000357 return 0;
358}
cjdebenh71f45f02006-11-08 02:19:57 +0000359
cjdebenhc80f9b42006-11-09 22:29:26 +0000360void sendtrack_command (int argc, char **argv) {
Linus Walleij070e9b42007-01-22 08:49:28 +0000361 int opt;
362 extern int optind;
363 extern char *optarg;
364 char *partist = NULL;
Linus Walleij31b74292008-05-02 23:29:06 +0000365 char *palbumartist = NULL;
366 char *pcomposer = NULL;
Linus Walleij070e9b42007-01-22 08:49:28 +0000367 char *ptitle = NULL;
368 char *pgenre = NULL;
369 char *pcodec = NULL;
370 char *palbum = NULL;
371 uint16_t tracknum = 0;
372 uint16_t length = 0;
373 uint16_t year = 0;
374 uint16_t quiet = 0;
Linus Walleij4347fda2008-09-19 22:28:45 +0000375 uint32_t storageid = 0;
376 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 +0000377 switch (opt) {
378 case 't':
379 ptitle = strdup(optarg);
380 break;
381 case 'a':
382 partist = strdup(optarg);
383 break;
Linus Walleij31b74292008-05-02 23:29:06 +0000384 case 'A':
385 palbumartist = strdup(optarg);
386 break;
387 case 'w':
388 pcomposer = strdup(optarg);
389 break;
Linus Walleij070e9b42007-01-22 08:49:28 +0000390 case 'l':
391 palbum = strdup(optarg);
392 break;
393 case 'c':
394 pcodec = strdup(optarg); // FIXME: DSM check for MP3, WAV or WMA
395 break;
396 case 'g':
397 pgenre = strdup(optarg);
398 break;
399 case 'n':
400 tracknum = atoi(optarg);
401 break;
Linus Walleij4347fda2008-09-19 22:28:45 +0000402 case 's':
403 storageid = (uint32_t) strtoul(optarg, NULL, 0);
404 break;
Linus Walleij070e9b42007-01-22 08:49:28 +0000405 case 'd':
406 length = atoi(optarg);
407 break;
408 case 'y':
409 year = atoi(optarg);
410 break;
411 case 'q':
412 quiet = 1;
413 break;
414 default:
415 sendtrack_usage();
416 }
417 }
418 argc -= optind;
419 argv += optind;
420
421 if ( argc != 2 ) {
422 printf("You need to pass a filename and destination.\n");
423 sendtrack_usage();
Linus Walleij2242b022009-01-02 01:44:00 +0000424 return;
Linus Walleij070e9b42007-01-22 08:49:28 +0000425 }
Linus Walleij56c63952008-06-08 21:55:58 +0000426
427 checklang();
Linus Walleij070e9b42007-01-22 08:49:28 +0000428
Linus Walleij28ad9b72009-09-21 12:10:35 +0000429 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);
430 sendtrack_function(argv[0],argv[1],partist,palbumartist,ptitle,pgenre,palbum,pcomposer, tracknum, length, year, storageid, quiet);
cjdebenh71f45f02006-11-08 02:19:57 +0000431}