5
5
* based on Enrique Jorreto Ledesma's work on the original program by
6
6
* Shaun Jackman and Linus Walleij.
8
* Copyright (C) 2003-2008 Linus Walleij <triad@df.lth.se>
8
* Copyright (C) 2003-2009 Linus Walleij <triad@df.lth.se>
9
9
* Copyright (C) 2003-2005 Shaun Jackman
10
10
* Copyright (C) 2003-2005 Enrique Jorrete Ledesma
11
11
* Copyright (C) 2006 Chris A. Debenham <chris@adebenham.com>
12
12
* Copyright (C) 2008 Nicolas Pennequin <nicolas.pennequin@free.fr>
13
* Copyright (C) 2008 Joseph Nahmias <joe@nahmias.net>
14
15
* This library is free software; you can redistribute it and/or
15
16
* modify it under the terms of the GNU Lesser General Public
45
49
extern LIBMTP_file_t *files;
46
50
extern LIBMTP_mtpdevice_t *device;
48
int sendtrack_function (char *, char *, char *, char *, char *, char *, char *, char *, uint16_t, uint16_t, uint16_t);
52
int sendtrack_function (char *, char *, char *, char *, char *, char *, char *, char *, uint16_t, uint16_t, uint16_t, uint32_t);
49
53
void sendtrack_command (int, char **);
50
54
void sendtrack_usage (void);
54
58
fprintf(stderr, "usage: sendtr [ -D debuglvl ] [ -q ]\n");
55
59
fprintf(stderr, "-t <title> -a <artist> -A <Album artist> -w <writer or composer>\n");
56
60
fprintf(stderr, " -l <album> -c <codec> -g <genre> -n <track number> -y <year>\n");
57
fprintf(stderr, " -d <duration in seconds> <local path> <remote path>\n");
61
fprintf(stderr, " -d <duration in seconds> -s <storage_id> <local path> <remote path>\n");
58
62
fprintf(stderr, "(-q means the program will not ask for missing information.)\n");
61
static void checklang(void)
63
char *langsuff = NULL;
64
char *lang = getenv("LANG");
66
#ifdef HAVE_LANGINFO_H
67
langsuff = nl_langinfo(CODESET);
70
* Check environment variables $LANG and $LC_CTYPE
71
* to see if we want to support UTF-8 unicode
74
if (strlen(lang) > 5) {
75
langsuff = &lang[strlen(lang)-5];
79
if (strcmp(langsuff, "UTF-8")) {
80
printf("Your system does not appear to have UTF-8 enabled ($LANG=\"%s\")\n", lang);
81
printf("If you want to have support for diacritics and Unicode characters,\n");
82
printf("please switch your locale to an UTF-8 locale, e.g. \"en_US.UTF-8\".\n");
86
65
static char *prompt (const char *prompt, char *buffer, size_t bufsz, int required)
185
int 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)
165
int 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)
187
167
char *filename, *parent;
188
168
char artist[80], albumartist[80], title[80], genre[80], album[80], composer[80];
203
183
trackmeta = LIBMTP_new_track_t();
204
184
albuminfo = LIBMTP_new_album_t();
206
parent = dirname(to_path);
207
filename = basename(to_path);
186
parent = dirname(strdup(to_path));
187
filename = basename(strdup(to_path));
208
188
parent_id = parse_path (parent,files,folders);
209
189
if (parent_id == -1) {
210
190
printf("Parent folder could not be found, skipping\n");
352
332
trackmeta->filesize = filesize;
353
333
trackmeta->parent_id = parent_id;
354
// Use default storage.
355
trackmeta->storage_id = 0;
337
LIBMTP_devicestorage_t *pds = NULL;
339
if ( 0 != (rc=LIBMTP_Get_Storage(device, LIBMTP_STORAGE_SORTBY_NOTSORTED)) )
341
perror("LIBMTP_Get_Storage()");
344
for (pds = device->storage; pds != NULL; pds = pds->next)
346
if (pds->id == storageid)
348
desc = strdup(pds->StorageDescription);
354
printf("Storage ID: %s (%u)\n", desc, storageid);
358
printf("Storage ID: %u\n", storageid);
359
trackmeta->storage_id = storageid;
357
362
printf("Sending track...\n");
358
363
ret = LIBMTP_Send_Track_From_File(device, from_path, trackmeta, progress, NULL);
365
370
printf("New track ID: %d\n", trackmeta->item_id);
368
/* Add here add to album call */
369
ret = add_track_to_album(albuminfo, trackmeta);
373
/* Add here add to album call */
375
ret = add_track_to_album(albuminfo, trackmeta);
371
377
LIBMTP_destroy_album_t(albuminfo);
372
378
LIBMTP_destroy_track_t(trackmeta);
437
446
if ( argc != 2 ) {
438
447
printf("You need to pass a filename and destination.\n");
439
448
sendtrack_usage();
444
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);
445
sendtrack_function(argv[0],argv[1],partist,palbumartist,ptitle,pgenre,palbum,pcomposer, tracknum, length, year);
454
printf("%s,%s,%s,%s,%s,%s,%s,%s,%d%d,%d,%u\n",argv[0],argv[1],partist,palbumartist,ptitle,pgenre,palbum,pcomposer,tracknum, length, year, storageid);
455
sendtrack_function(argv[0],argv[1],partist,palbumartist,ptitle,pgenre,palbum,pcomposer, tracknum, length, year, storageid);