Linus Walleij | dcde608 | 2006-02-17 16:16:34 +0000 | [diff] [blame] | 1 | #include "common.h" |
cjdebenh | 4a99f50 | 2006-11-09 22:03:05 +0000 | [diff] [blame] | 2 | #include "pathutils.h" |
Linus Walleij | dcde608 | 2006-02-17 16:16:34 +0000 | [diff] [blame] | 3 | |
cjdebenh | c80f9b4 | 2006-11-09 22:29:26 +0000 | [diff] [blame] | 4 | void getfile_function(char *,char *); |
| 5 | void getfile_command(int, char **); |
| 6 | void getfile_usage(void); |
Linus Walleij | dcde608 | 2006-02-17 16:16:34 +0000 | [diff] [blame] | 7 | |
cjdebenh | 4a99f50 | 2006-11-09 22:03:05 +0000 | [diff] [blame] | 8 | extern LIBMTP_folder_t *folders; |
| 9 | extern LIBMTP_file_t *files; |
| 10 | extern LIBMTP_mtpdevice_t *device; |
| 11 | |
cjdebenh | c80f9b4 | 2006-11-09 22:29:26 +0000 | [diff] [blame] | 12 | void getfile_usage (void) |
Linus Walleij | dcde608 | 2006-02-17 16:16:34 +0000 | [diff] [blame] | 13 | { |
Linus Walleij | f6bc178 | 2006-03-24 15:12:47 +0000 | [diff] [blame] | 14 | fprintf(stderr, "getfile <fileid/trackid> <filename>\n"); |
Linus Walleij | dcde608 | 2006-02-17 16:16:34 +0000 | [diff] [blame] | 15 | } |
| 16 | |
cjdebenh | 4a99f50 | 2006-11-09 22:03:05 +0000 | [diff] [blame] | 17 | void |
cjdebenh | c80f9b4 | 2006-11-09 22:29:26 +0000 | [diff] [blame] | 18 | getfile_function(char * from_path,char * to_path) |
Linus Walleij | dcde608 | 2006-02-17 16:16:34 +0000 | [diff] [blame] | 19 | { |
cjdebenh | 4a99f50 | 2006-11-09 22:03:05 +0000 | [diff] [blame] | 20 | int id = parse_path (from_path,files,folders); |
| 21 | if (id > 0) { |
| 22 | printf("Getting %s to %s\n",from_path,to_path); |
| 23 | if (LIBMTP_Get_File_To_File(device, id, to_path, progress, NULL) != 0 ) { |
| 24 | printf("\nError getting file from MTP device.\n"); |
Linus Walleij | 070e9b4 | 2007-01-22 08:49:28 +0000 | [diff] [blame^] | 25 | LIBMTP_Dump_Errorstack(device); |
| 26 | LIBMTP_Clear_Errorstack(device); |
cjdebenh | 4a99f50 | 2006-11-09 22:03:05 +0000 | [diff] [blame] | 27 | } |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | |
cjdebenh | c80f9b4 | 2006-11-09 22:29:26 +0000 | [diff] [blame] | 32 | void getfile_command(int argc, char **argv) |
cjdebenh | 4a99f50 | 2006-11-09 22:03:05 +0000 | [diff] [blame] | 33 | { |
Linus Walleij | dcde608 | 2006-02-17 16:16:34 +0000 | [diff] [blame] | 34 | u_int32_t id; |
| 35 | char *endptr; |
| 36 | char *file; |
| 37 | |
Linus Walleij | f6bc178 | 2006-03-24 15:12:47 +0000 | [diff] [blame] | 38 | // We need file ID and filename |
Linus Walleij | 0cd8543 | 2006-02-20 14:37:50 +0000 | [diff] [blame] | 39 | if ( argc != 3 ) { |
cjdebenh | 4a99f50 | 2006-11-09 22:03:05 +0000 | [diff] [blame] | 40 | getfile_usage(); |
| 41 | return; |
Linus Walleij | dcde608 | 2006-02-17 16:16:34 +0000 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | // Sanity check song ID |
Linus Walleij | 0cd8543 | 2006-02-20 14:37:50 +0000 | [diff] [blame] | 45 | id = strtoul(argv[1], &endptr, 10); |
Linus Walleij | dcde608 | 2006-02-17 16:16:34 +0000 | [diff] [blame] | 46 | if ( *endptr != 0 ) { |
Linus Walleij | 0cd8543 | 2006-02-20 14:37:50 +0000 | [diff] [blame] | 47 | fprintf(stderr, "illegal value %s\n", argv[1]); |
cjdebenh | 4a99f50 | 2006-11-09 22:03:05 +0000 | [diff] [blame] | 48 | return; |
Linus Walleij | dcde608 | 2006-02-17 16:16:34 +0000 | [diff] [blame] | 49 | } else if ( ! id ) { |
Linus Walleij | f6bc178 | 2006-03-24 15:12:47 +0000 | [diff] [blame] | 50 | fprintf(stderr, "bad file/track id %u\n", id); |
cjdebenh | 4a99f50 | 2006-11-09 22:03:05 +0000 | [diff] [blame] | 51 | return; |
Linus Walleij | 0cd8543 | 2006-02-20 14:37:50 +0000 | [diff] [blame] | 52 | } |
Linus Walleij | dcde608 | 2006-02-17 16:16:34 +0000 | [diff] [blame] | 53 | |
| 54 | // Filename, e.g. "foo.mp3" |
Linus Walleij | 0cd8543 | 2006-02-20 14:37:50 +0000 | [diff] [blame] | 55 | file = argv[2]; |
Linus Walleij | f6bc178 | 2006-03-24 15:12:47 +0000 | [diff] [blame] | 56 | printf("Getting file/track %d to local file %s\n", id, file); |
Linus Walleij | dcde608 | 2006-02-17 16:16:34 +0000 | [diff] [blame] | 57 | |
Linus Walleij | f6bc178 | 2006-03-24 15:12:47 +0000 | [diff] [blame] | 58 | // This function will also work just as well for tracks. |
| 59 | if (LIBMTP_Get_File_To_File(device, id, file, progress, NULL) != 0 ) { |
Linus Walleij | ee73ef2 | 2006-08-27 19:56:00 +0000 | [diff] [blame] | 60 | printf("\nError getting file from MTP device.\n"); |
Linus Walleij | dcde608 | 2006-02-17 16:16:34 +0000 | [diff] [blame] | 61 | } |
Linus Walleij | ee73ef2 | 2006-08-27 19:56:00 +0000 | [diff] [blame] | 62 | // Terminate progress bar. |
| 63 | printf("\n"); |
Linus Walleij | dcde608 | 2006-02-17 16:16:34 +0000 | [diff] [blame] | 64 | |
cjdebenh | 4a99f50 | 2006-11-09 22:03:05 +0000 | [diff] [blame] | 65 | return; |
Linus Walleij | dcde608 | 2006-02-17 16:16:34 +0000 | [diff] [blame] | 66 | } |
| 67 | |