blob: bb2586ad70a493f14113e795dbe16215e080b8b3 [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 Walleij75fe2bf2008-02-12 07:34:35 +00008 * Copyright (C) 2003-2008 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 Walleij3d78c4c2007-02-15 12:18:12 +000013 *
14 * This library is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public
16 * License as published by the Free Software Foundation; either
17 * version 2 of the License, or (at your option) any later version.
18 *
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
23 *
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the
26 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
27 * Boston, MA 02111-1307, USA.
cjdebenh71f45f02006-11-08 02:19:57 +000028 */
Linus Walleij05358382007-08-06 20:46:35 +000029#define _LARGEFILE_SOURCE
30#define _LARGEFILE64_SOURCE
31
Linus Walleijbde621f2006-02-22 16:11:35 +000032#include <string.h>
cjdebenhcb4ac9f2006-11-03 02:00:49 +000033#include <libgen.h>
Linus Walleijbde621f2006-02-22 16:11:35 +000034#include <sys/stat.h>
cjdebenhcb4ac9f2006-11-03 02:00:49 +000035#include <sys/types.h>
36#include <fcntl.h>
37#include "common.h"
38#include "libmtp.h"
39#include "pathutils.h"
Linus Walleijbde621f2006-02-22 16:11:35 +000040
cjdebenhcb4ac9f2006-11-03 02:00:49 +000041extern LIBMTP_folder_t *folders;
42extern LIBMTP_file_t *files;
43extern LIBMTP_mtpdevice_t *device;
44
Linus Walleij31b74292008-05-02 23:29:06 +000045int sendtrack_function (char *, char *, char *, char *, char *, char *, char *, char *, uint16_t, uint16_t, uint16_t);
cjdebenhc80f9b42006-11-09 22:29:26 +000046void sendtrack_command (int, char **);
47void sendtrack_usage (void);
cjdebenh71f45f02006-11-08 02:19:57 +000048
cjdebenhc80f9b42006-11-09 22:29:26 +000049void sendtrack_usage (void)
cjdebenh71f45f02006-11-08 02:19:57 +000050{
Linus Walleij31b74292008-05-02 23:29:06 +000051 fprintf(stderr, "usage: sendtr [ -D debuglvl ] [ -q ]\n");
52 fprintf(stderr, "-t <title> -a <artist> -A <Album artist> -w <writer or composer>\n");
53 fprintf(stderr, " -l <album> -c <codec> -g <genre> -n <track number> -y <year>\n");
cjdebenh71f45f02006-11-08 02:19:57 +000054 fprintf(stderr, " -d <duration in seconds> <local path> <remote path>\n");
55 fprintf(stderr, "(-q means the program will not ask for missing information.)\n");
56}
Linus Walleijbde621f2006-02-22 16:11:35 +000057
Linus Walleijbde621f2006-02-22 16:11:35 +000058static char *prompt (const char *prompt, char *buffer, size_t bufsz, int required)
59{
60 char *cp, *bp;
61
62 while (1) {
63 fprintf(stdout, "%s> ", prompt);
64 if ( fgets(buffer, bufsz, stdin) == NULL ) {
65 if (ferror(stdin)) {
66 perror("fgets");
67 } else {
68 fprintf(stderr, "EOF on stdin\n");
69 }
70 return NULL;
71 }
72
73 cp = strrchr(buffer, '\n');
74 if ( cp != NULL ) *cp = '\0';
75
76 bp = buffer;
77 while ( bp != cp ) {
78 if ( *bp != ' ' && *bp != '\t' ) return bp;
79 bp++;
80 }
81
82 if (! required) return bp;
83 }
84}
85
Linus Walleij75fe2bf2008-02-12 07:34:35 +000086static int add_track_to_album(LIBMTP_album_t *albuminfo, LIBMTP_track_t *trackmeta)
87{
Linus Walleij95640132008-02-12 11:57:37 +000088 LIBMTP_album_t *album;
89 LIBMTP_album_t *found_album = NULL;
Linus Walleij75fe2bf2008-02-12 07:34:35 +000090 int ret;
91
Linus Walleij75fe2bf2008-02-12 07:34:35 +000092 /* Look for the album */
Linus Walleij95640132008-02-12 11:57:37 +000093 album = LIBMTP_Get_Album_List(device);
Linus Walleij75fe2bf2008-02-12 07:34:35 +000094 while(album != NULL) {
Linus Walleij31b74292008-05-02 23:29:06 +000095 if ((album->name != NULL &&
Linus Walleijbbd91422008-02-12 12:00:51 +000096 album->artist != NULL &&
97 !strcmp(album->name, albuminfo->name) &&
Linus Walleij31b74292008-05-02 23:29:06 +000098 !strcmp(album->artist, albuminfo->artist)) ||
99 (album->name != NULL &&
100 album->composer != NULL &&
101 !strcmp(album->name, albuminfo->name) &&
102 !strcmp(album->composer, albuminfo->composer))) {
Linus Walleij95640132008-02-12 11:57:37 +0000103 /* Disconnect this album for later use */
104 found_album = album;
105 album = album->next;
106 found_album->next = NULL;
107 } else {
108 LIBMTP_album_t *tmp;
109
110 tmp = album;
111 album = album->next;
112 LIBMTP_destroy_album_t(tmp);
Linus Walleij75fe2bf2008-02-12 07:34:35 +0000113 }
Linus Walleij75fe2bf2008-02-12 07:34:35 +0000114 }
115
Linus Walleij95640132008-02-12 11:57:37 +0000116 if (found_album != NULL) {
117 uint32_t *tracks;
118
119 tracks = (uint32_t *)malloc((found_album->no_tracks+1) * sizeof(uint32_t));
120 printf("Album \"%s\" found: updating...\n", found_album->name);
Linus Walleij75fe2bf2008-02-12 07:34:35 +0000121 if (!tracks) {
Linus Walleij95640132008-02-12 11:57:37 +0000122 printf("failed malloc in add_track_to_album()\n");
Linus Walleij75fe2bf2008-02-12 07:34:35 +0000123 return 1;
124 }
Linus Walleij95640132008-02-12 11:57:37 +0000125 found_album->no_tracks++;
126 if (found_album->tracks != NULL) {
127 memcpy(tracks, found_album->tracks, found_album->no_tracks * sizeof(uint32_t));
128 free(found_album->tracks);
129 }
Linus Walleij95640132008-02-12 11:57:37 +0000130 tracks[found_album->no_tracks-1] = trackmeta->item_id;
Linus Walleijbbd91422008-02-12 12:00:51 +0000131 found_album->tracks = tracks;
Linus Walleij95640132008-02-12 11:57:37 +0000132 ret = LIBMTP_Update_Album(device, found_album);
133 LIBMTP_destroy_album_t(found_album);
Linus Walleij75fe2bf2008-02-12 07:34:35 +0000134 } else {
Linus Walleij95640132008-02-12 11:57:37 +0000135 uint32_t *trackid;
136
137 trackid = (uint32_t *)malloc(sizeof(uint32_t));
138 *trackid = trackmeta->item_id;
139 albuminfo->tracks = trackid;
140 albuminfo->no_tracks = 1;
Linus Walleij75fe2bf2008-02-12 07:34:35 +0000141 printf("Album doesn't exist: creating...\n");
142 ret = LIBMTP_Create_New_Album(device, albuminfo, 0);
Linus Walleij95640132008-02-12 11:57:37 +0000143 /* albuminfo will be destroyed later by caller */
Linus Walleij75fe2bf2008-02-12 07:34:35 +0000144 }
145
146 if (ret != 0) {
147 printf("Error creating or updating album.\n");
148 LIBMTP_Dump_Errorstack(device);
149 LIBMTP_Clear_Errorstack(device);
150 } else {
Linus Walleij95640132008-02-12 11:57:37 +0000151 printf("success!\n");
Linus Walleij75fe2bf2008-02-12 07:34:35 +0000152 }
Linus Walleij31b74292008-05-02 23:29:06 +0000153 return ret;
Linus Walleij75fe2bf2008-02-12 07:34:35 +0000154}
155
Linus Walleij31b74292008-05-02 23:29:06 +0000156int 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)
Linus Walleijbde621f2006-02-22 16:11:35 +0000157{
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000158 char *filename, *parent;
Linus Walleij31b74292008-05-02 23:29:06 +0000159 char artist[80], albumartist[80], title[80], genre[80], album[80], composer[80];
Linus Walleijbde621f2006-02-22 16:11:35 +0000160 char num[80];
Linus Walleijbde621f2006-02-22 16:11:35 +0000161 uint64_t filesize;
Linus Walleij3eb115c2006-06-05 10:28:24 +0000162 uint32_t parent_id = 0;
Linus Walleij05358382007-08-06 20:46:35 +0000163#ifdef __USE_LARGEFILE64
164 struct stat64 sb;
165#else
Linus Walleijbde621f2006-02-22 16:11:35 +0000166 struct stat sb;
Linus Walleij05358382007-08-06 20:46:35 +0000167#endif
Linus Walleijbde621f2006-02-22 16:11:35 +0000168 LIBMTP_track_t *trackmeta;
Linus Walleij75fe2bf2008-02-12 07:34:35 +0000169 LIBMTP_album_t *albuminfo;
170 int ret;
171
172 printf("Sending track %s to %s\n",from_path,to_path);
173
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000174 trackmeta = LIBMTP_new_track_t();
Linus Walleij75fe2bf2008-02-12 07:34:35 +0000175 albuminfo = LIBMTP_new_album_t();
Linus Walleijd6a49972006-05-02 08:24:54 +0000176
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000177 parent = dirname(to_path);
178 filename = basename(to_path);
179 parent_id = parse_path (parent,files,folders);
180 if (parent_id == -1) {
181 printf("Parent folder could not be found, skipping\n");
182 return 1;
Linus Walleijbde621f2006-02-22 16:11:35 +0000183 }
Linus Walleijbde621f2006-02-22 16:11:35 +0000184
Linus Walleij05358382007-08-06 20:46:35 +0000185#ifdef __USE_LARGEFILE64
186 if ( stat64(from_path, &sb) == -1 ) {
187#else
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000188 if ( stat(from_path, &sb) == -1 ) {
Linus Walleij05358382007-08-06 20:46:35 +0000189#endif
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000190 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#ifdef __USE_LARGEFILE64
195 filesize = sb.st_size;
196#else
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000197 filesize = (uint64_t) sb.st_size;
Linus Walleij05358382007-08-06 20:46:35 +0000198#endif
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000199 trackmeta->filetype = find_filetype (from_path);
Linus Walleij02ee8802006-12-30 17:27:58 +0000200 if ((trackmeta->filetype != LIBMTP_FILETYPE_MP3)
201 && (trackmeta->filetype != LIBMTP_FILETYPE_WAV)
202 && (trackmeta->filetype != LIBMTP_FILETYPE_OGG)
203 && (trackmeta->filetype != LIBMTP_FILETYPE_MP4)
204 && (trackmeta->filetype != LIBMTP_FILETYPE_AAC)
205 && (trackmeta->filetype != LIBMTP_FILETYPE_M4A)
206 && (trackmeta->filetype != LIBMTP_FILETYPE_FLAC)
207 && (trackmeta->filetype != LIBMTP_FILETYPE_WMA)) {
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000208 printf("Not a valid codec: \"%s\"\n", LIBMTP_Get_Filetype_Description(trackmeta->filetype));
Linus Walleij02ee8802006-12-30 17:27:58 +0000209 printf("Supported formats: MP3, WAV, OGG, MP4, AAC, M4A, FLAC, WMA\n");
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000210 return 1;
211 }
Linus Walleijbde621f2006-02-22 16:11:35 +0000212
Linus Walleijbde621f2006-02-22 16:11:35 +0000213 if (ptitle == NULL) {
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000214 ptitle = prompt("Title", title, 80, 0);
Linus Walleijbde621f2006-02-22 16:11:35 +0000215 }
216 if (!strlen(ptitle))
217 ptitle = NULL;
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000218
Linus Walleijbde621f2006-02-22 16:11:35 +0000219 if (palbum == NULL) {
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000220 palbum = prompt("Album", album, 80, 0);
Linus Walleijbde621f2006-02-22 16:11:35 +0000221 }
222 if (!strlen(palbum))
223 palbum = NULL;
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000224
Linus Walleij31b74292008-05-02 23:29:06 +0000225 if (palbumartist == NULL) {
226 palbumartist = prompt("Album artist", albumartist, 80, 0);
227 }
Linus Walleijbde621f2006-02-22 16:11:35 +0000228 if (partist == NULL) {
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000229 partist = prompt("Artist", artist, 80, 0);
Linus Walleijbde621f2006-02-22 16:11:35 +0000230 }
231 if (!strlen(partist))
232 partist = NULL;
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000233
Linus Walleij31b74292008-05-02 23:29:06 +0000234 if (pcomposer == NULL) {
235 pcomposer = prompt("Writer or Composer", composer, 80, 0);
236 }
237 if (!strlen(pcomposer))
238 pcomposer = NULL;
239
Linus Walleijbde621f2006-02-22 16:11:35 +0000240 if (pgenre == NULL) {
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000241 pgenre = prompt("Genre", genre, 80, 0);
Linus Walleijbde621f2006-02-22 16:11:35 +0000242 }
243 if (!strlen(pgenre))
244 pgenre = NULL;
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000245
Linus Walleijbde621f2006-02-22 16:11:35 +0000246 if (tracknum == 0) {
247 char *pnum;
248 if ( (pnum = prompt("Track number", num, 80, 0)) == NULL )
249 tracknum = 0;
250 if ( strlen(pnum) ) {
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000251 tracknum = strtoul(pnum, 0, 10);
Linus Walleijbde621f2006-02-22 16:11:35 +0000252 } else {
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000253 tracknum = 0;
Linus Walleijbde621f2006-02-22 16:11:35 +0000254 }
255 }
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000256
Linus Walleijbde621f2006-02-22 16:11:35 +0000257 if (year == 0) {
258 char *pnum;
259 if ( (pnum = prompt("Year", num, 80, 0)) == NULL )
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000260 year = 0;
Linus Walleijbde621f2006-02-22 16:11:35 +0000261 if ( strlen(pnum) ) {
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000262 year = strtoul(pnum, 0, 10);
Linus Walleijbde621f2006-02-22 16:11:35 +0000263 } else {
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000264 year = 0;
Linus Walleijbde621f2006-02-22 16:11:35 +0000265 }
266 }
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000267
Linus Walleijbde621f2006-02-22 16:11:35 +0000268 if (length == 0) {
269 char *pnum;
270 if ( (pnum = prompt("Length", num, 80, 0)) == NULL )
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000271 length = 0;
Linus Walleijbde621f2006-02-22 16:11:35 +0000272 if ( strlen(pnum) ) {
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000273 length = strtoul(pnum, 0, 10);
Linus Walleijbde621f2006-02-22 16:11:35 +0000274 } else {
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000275 length = 0;
Linus Walleijbde621f2006-02-22 16:11:35 +0000276 }
277 }
Linus Walleijbde621f2006-02-22 16:11:35 +0000278
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000279 printf("Sending track:\n");
280 printf("Codec: %s\n", LIBMTP_Get_Filetype_Description(trackmeta->filetype));
281 if (ptitle) {
282 printf("Title: %s\n", ptitle);
283 trackmeta->title = strdup(ptitle);
284 }
285 if (palbum) {
286 printf("Album: %s\n", palbum);
287 trackmeta->album = strdup(palbum);
Linus Walleij75fe2bf2008-02-12 07:34:35 +0000288 albuminfo->name = strdup(palbum);
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000289 }
Linus Walleij31b74292008-05-02 23:29:06 +0000290 if (palbumartist) {
291 printf("Album artist: %s\n", palbumartist);
292 albuminfo->artist = strdup(palbumartist);
293 }
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000294 if (partist) {
295 printf("Artist: %s\n", partist);
296 trackmeta->artist = strdup(partist);
Linus Walleij31b74292008-05-02 23:29:06 +0000297 if (palbumartist == NULL)
Linus Walleij75fe2bf2008-02-12 07:34:35 +0000298 albuminfo->artist = strdup(partist);
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000299 }
Linus Walleij31b74292008-05-02 23:29:06 +0000300
301 if (pcomposer) {
302 printf("Writer or Composer: %s\n", pcomposer);
303 trackmeta->composer = strdup(pcomposer);
304 albuminfo->composer = strdup(pcomposer);
305 }
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000306 if (pgenre) {
307 printf("Genre: %s\n", pgenre);
308 trackmeta->genre = strdup(pgenre);
Linus Walleij75fe2bf2008-02-12 07:34:35 +0000309 albuminfo->genre = strdup(pgenre);
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000310 }
311 if (year > 0) {
312 char tmp[80];
313 printf("Year: %d\n", year);
314 snprintf(tmp, sizeof(tmp)-1, "%4d0101T0000.0", year);
315 tmp[sizeof(tmp)-1] = '\0';
316 trackmeta->date = strdup(tmp);
317 }
318 if (tracknum > 0) {
319 printf("Track no: %d\n", tracknum);
320 trackmeta->tracknumber = tracknum;
321 }
322 if (length > 0) {
323 printf("Length: %d\n", length);
324 // Multiply by 1000 since this is in milliseconds
325 trackmeta->duration = length * 1000;
326 }
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000327 // We should always have this
328 if (filename != NULL) {
329 trackmeta->filename = strdup(filename);
330 }
331 trackmeta->filesize = filesize;
332
333 printf("Sending track...\n");
334 ret = LIBMTP_Send_Track_From_File(device, from_path, trackmeta, progress, NULL, parent_id);
Linus Walleijd2778d12007-08-06 19:24:58 +0000335 printf("\n");
Linus Walleij070e9b42007-01-22 08:49:28 +0000336 if (ret != 0) {
337 printf("Error sending track.\n");
338 LIBMTP_Dump_Errorstack(device);
339 LIBMTP_Clear_Errorstack(device);
340 } else {
341 printf("New track ID: %d\n", trackmeta->item_id);
342 }
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000343
Linus Walleij31b74292008-05-02 23:29:06 +0000344/* Add here add to album call */
345 ret = add_track_to_album(albuminfo, trackmeta);
346
Linus Walleij75fe2bf2008-02-12 07:34:35 +0000347 LIBMTP_destroy_album_t(albuminfo);
Linus Walleij17e39f72006-02-23 15:54:28 +0000348 LIBMTP_destroy_track_t(trackmeta);
Linus Walleij75fe2bf2008-02-12 07:34:35 +0000349
cjdebenhcb4ac9f2006-11-03 02:00:49 +0000350 return 0;
Linus Walleij17e39f72006-02-23 15:54:28 +0000351 }
Linus Walleijbde621f2006-02-22 16:11:35 +0000352 return 0;
353}
cjdebenh71f45f02006-11-08 02:19:57 +0000354
cjdebenhc80f9b42006-11-09 22:29:26 +0000355void sendtrack_command (int argc, char **argv) {
Linus Walleij070e9b42007-01-22 08:49:28 +0000356 int opt;
357 extern int optind;
358 extern char *optarg;
359 char *partist = NULL;
Linus Walleij31b74292008-05-02 23:29:06 +0000360 char *palbumartist = NULL;
361 char *pcomposer = NULL;
Linus Walleij070e9b42007-01-22 08:49:28 +0000362 char *ptitle = NULL;
363 char *pgenre = NULL;
364 char *pcodec = NULL;
365 char *palbum = NULL;
366 uint16_t tracknum = 0;
367 uint16_t length = 0;
368 uint16_t year = 0;
369 uint16_t quiet = 0;
370 char *lang;
Linus Walleij31b74292008-05-02 23:29:06 +0000371 while ( (opt = getopt(argc, argv, "qD:t:a:A:w:l:c:g:n:d:y:")) != -1 ) {
Linus Walleij070e9b42007-01-22 08:49:28 +0000372 switch (opt) {
373 case 't':
374 ptitle = strdup(optarg);
375 break;
376 case 'a':
377 partist = strdup(optarg);
378 break;
Linus Walleij31b74292008-05-02 23:29:06 +0000379 case 'A':
380 palbumartist = strdup(optarg);
381 break;
382 case 'w':
383 pcomposer = strdup(optarg);
384 break;
Linus Walleij070e9b42007-01-22 08:49:28 +0000385 case 'l':
386 palbum = strdup(optarg);
387 break;
388 case 'c':
389 pcodec = strdup(optarg); // FIXME: DSM check for MP3, WAV or WMA
390 break;
391 case 'g':
392 pgenre = strdup(optarg);
393 break;
394 case 'n':
395 tracknum = atoi(optarg);
396 break;
397 case 'd':
398 length = atoi(optarg);
399 break;
400 case 'y':
401 year = atoi(optarg);
402 break;
403 case 'q':
404 quiet = 1;
405 break;
406 default:
407 sendtrack_usage();
408 }
409 }
410 argc -= optind;
411 argv += optind;
412
413 if ( argc != 2 ) {
414 printf("You need to pass a filename and destination.\n");
415 sendtrack_usage();
416 }
417 /*
418 * Check environment variables $LANG and $LC_CTYPE
419 * to see if we want to support UTF-8 unicode
420 */
421 lang = getenv("LANG");
422 if (lang != NULL) {
423 if (strlen(lang) > 5) {
424 char *langsuff = &lang[strlen(lang)-5];
425 if (strcmp(langsuff, "UTF-8")) {
426 printf("Your system does not appear to have UTF-8 enabled ($LANG=\"%s\")\n", lang);
427 printf("If you want to have support for diacritics and Unicode characters,\n");
428 printf("please switch your locale to an UTF-8 locale, e.g. \"en_US.UTF-8\".\n");
cjdebenh71f45f02006-11-08 02:19:57 +0000429 }
Linus Walleij070e9b42007-01-22 08:49:28 +0000430 }
431 }
432
Linus Walleij31b74292008-05-02 23:29:06 +0000433 printf("%s,%s,%s,%s,%s,%s,%s,%s,%d%d,%d\n",argv[0],argv[1],partist,palbumartist,ptitle,pgenre,palbum,pcomposer,tracknum, length, year);
434 sendtrack_function(argv[0],argv[1],partist,palbumartist,ptitle,pgenre,palbum,pcomposer, tracknum, length, year);
cjdebenh71f45f02006-11-08 02:19:57 +0000435}