|
Packit Bot |
a284d4 |
/**
|
|
Packit Bot |
a284d4 |
* \file sendtr.c
|
|
Packit Bot |
a284d4 |
* Example program to send a music track to a device.
|
|
Packit Bot |
a284d4 |
* This program is derived from the exact equivalent in libnjb.
|
|
Packit Bot |
a284d4 |
* based on Enrique Jorreto Ledesma's work on the original program by
|
|
Packit Bot |
a284d4 |
* Shaun Jackman and Linus Walleij.
|
|
Packit Bot |
a284d4 |
*
|
|
Packit Bot |
a284d4 |
* Copyright (C) 2003-2010 Linus Walleij <triad@df.lth.se>
|
|
Packit Bot |
a284d4 |
* Copyright (C) 2003-2005 Shaun Jackman
|
|
Packit Bot |
a284d4 |
* Copyright (C) 2003-2005 Enrique Jorrete Ledesma
|
|
Packit Bot |
a284d4 |
* Copyright (C) 2006 Chris A. Debenham <chris@adebenham.com>
|
|
Packit Bot |
a284d4 |
* Copyright (C) 2008 Nicolas Pennequin <nicolas.pennequin@free.fr>
|
|
Packit Bot |
a284d4 |
* Copyright (C) 2008 Joseph Nahmias <joe@nahmias.net>
|
|
Packit Bot |
a284d4 |
*
|
|
Packit Bot |
a284d4 |
* This library is free software; you can redistribute it and/or
|
|
Packit Bot |
a284d4 |
* modify it under the terms of the GNU Lesser General Public
|
|
Packit Bot |
a284d4 |
* License as published by the Free Software Foundation; either
|
|
Packit Bot |
a284d4 |
* version 2 of the License, or (at your option) any later version.
|
|
Packit Bot |
a284d4 |
*
|
|
Packit Bot |
a284d4 |
* This library is distributed in the hope that it will be useful,
|
|
Packit Bot |
a284d4 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Bot |
a284d4 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Bot |
a284d4 |
* Lesser General Public License for more details.
|
|
Packit Bot |
a284d4 |
*
|
|
Packit Bot |
a284d4 |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit Bot |
a284d4 |
* License along with this library; if not, write to the
|
|
Packit Bot |
a284d4 |
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
Packit Bot |
a284d4 |
* Boston, MA 02111-1307, USA.
|
|
Packit Bot |
a284d4 |
*/
|
|
Packit Bot |
a284d4 |
|
|
Packit Bot |
a284d4 |
#include <stdlib.h>
|
|
Packit Bot |
a284d4 |
#include <limits.h>
|
|
Packit Bot |
a284d4 |
#include <string.h>
|
|
Packit Bot |
a284d4 |
#include <libgen.h>
|
|
Packit Bot |
a284d4 |
#include <sys/stat.h>
|
|
Packit Bot |
a284d4 |
#include <sys/types.h>
|
|
Packit Bot |
a284d4 |
#include <fcntl.h>
|
|
Packit Bot |
a284d4 |
#ifdef HAVE_LANGINFO_H
|
|
Packit Bot |
a284d4 |
#include <langinfo.h>
|
|
Packit Bot |
a284d4 |
#endif
|
|
Packit Bot |
a284d4 |
|
|
Packit Bot |
a284d4 |
#include "config.h"
|
|
Packit Bot |
a284d4 |
#include "common.h"
|
|
Packit Bot |
a284d4 |
#include "util.h"
|
|
Packit Bot |
a284d4 |
#include "connect.h"
|
|
Packit Bot |
a284d4 |
#include "libmtp.h"
|
|
Packit Bot |
a284d4 |
#include "pathutils.h"
|
|
Packit Bot |
a284d4 |
|
|
Packit Bot |
a284d4 |
extern LIBMTP_folder_t *folders;
|
|
Packit Bot |
a284d4 |
extern LIBMTP_file_t *files;
|
|
Packit Bot |
a284d4 |
extern LIBMTP_mtpdevice_t *device;
|
|
Packit Bot |
a284d4 |
|
|
Packit Bot |
a284d4 |
void sendtrack_usage (void)
|
|
Packit Bot |
a284d4 |
{
|
|
Packit Bot |
a284d4 |
fprintf(stderr, "usage: sendtr [ -D debuglvl ] [ -q ]\n");
|
|
Packit Bot |
a284d4 |
fprintf(stderr, "-t <title> -a <artist> -A <Album artist> -w <writer or composer>\n");
|
|
Packit Bot |
a284d4 |
fprintf(stderr, " -l <album> -c <codec> -g <genre> -n <track number> -y <year>\n");
|
|
Packit Bot |
a284d4 |
fprintf(stderr, " -d <duration in seconds> -s <storage_id> <local path> <remote path>\n");
|
|
Packit Bot |
a284d4 |
fprintf(stderr, "(-q means the program will not ask for missing information.)\n");
|
|
Packit Bot |
a284d4 |
}
|
|
Packit Bot |
a284d4 |
|
|
Packit Bot |
a284d4 |
static char *prompt (const char *prompt, char *buffer, size_t bufsz, int required)
|
|
Packit Bot |
a284d4 |
{
|
|
Packit Bot |
a284d4 |
char *cp, *bp;
|
|
Packit Bot |
a284d4 |
|
|
Packit Bot |
a284d4 |
while (1) {
|
|
Packit Bot |
a284d4 |
fprintf(stdout, "%s> ", prompt);
|
|
Packit Bot |
a284d4 |
if ( fgets(buffer, bufsz, stdin) == NULL ) {
|
|
Packit Bot |
a284d4 |
if (ferror(stdin)) {
|
|
Packit Bot |
a284d4 |
perror("fgets");
|
|
Packit Bot |
a284d4 |
} else {
|
|
Packit Bot |
a284d4 |
fprintf(stderr, "EOF on stdin\n");
|
|
Packit Bot |
a284d4 |
}
|
|
Packit Bot |
a284d4 |
return NULL;
|
|
Packit Bot |
a284d4 |
}
|
|
Packit Bot |
a284d4 |
|
|
Packit Bot |
a284d4 |
cp = strrchr(buffer, '\n');
|
|
Packit Bot |
a284d4 |
if ( cp != NULL ) *cp = '\0';
|
|
Packit Bot |
a284d4 |
|
|
Packit Bot |
a284d4 |
bp = buffer;
|
|
Packit Bot |
a284d4 |
while ( bp != cp ) {
|
|
Packit Bot |
a284d4 |
if ( *bp != ' ' && *bp != '\t' ) return bp;
|
|
Packit Bot |
a284d4 |
bp++;
|
|
Packit Bot |
a284d4 |
}
|
|
Packit Bot |
a284d4 |
|
|
Packit Bot |
a284d4 |
if (! required) return bp;
|
|
Packit Bot |
a284d4 |
}
|
|
Packit Bot |
a284d4 |
}
|
|
Packit Bot |
a284d4 |
|
|
Packit Bot |
a284d4 |
static int add_track_to_album(LIBMTP_album_t *albuminfo, LIBMTP_track_t *trackmeta)
|
|
Packit Bot |
a284d4 |
{
|
|
Packit Bot |
a284d4 |
LIBMTP_album_t *album;
|
|
Packit Bot |
a284d4 |
LIBMTP_album_t *album_orig;
|
|
Packit Bot |
a284d4 |
LIBMTP_album_t *found_album = NULL;
|
|
Packit Bot |
a284d4 |
int ret;
|
|
Packit Bot |
a284d4 |
|
|
Packit Bot |
a284d4 |
/* Look for the album */
|
|
Packit Bot |
a284d4 |
album = LIBMTP_Get_Album_List(device);
|
|
Packit Bot |
a284d4 |
album_orig = album;
|
|
Packit Bot |
a284d4 |
while(album != NULL) {
|
|
Packit Bot |
a284d4 |
if ((album->name != NULL &&
|
|
Packit Bot |
a284d4 |
album->artist != NULL &&
|
|
Packit Bot |
a284d4 |
!strcmp(album->name, albuminfo->name) &&
|
|
Packit Bot |
a284d4 |
!strcmp(album->artist, albuminfo->artist)) ||
|
|
Packit Bot |
a284d4 |
(album->name != NULL &&
|
|
Packit Bot |
a284d4 |
album->composer != NULL &&
|
|
Packit Bot |
a284d4 |
!strcmp(album->name, albuminfo->name) &&
|
|
Packit Bot |
a284d4 |
!strcmp(album->composer, albuminfo->composer))) {
|
|
Packit Bot |
a284d4 |
/* Disconnect this album for later use */
|
|
Packit Bot |
a284d4 |
found_album = album;
|
|
Packit Bot |
a284d4 |
album = album->next;
|
|
Packit Bot |
a284d4 |
found_album->next = NULL;
|
|
Packit Bot |
a284d4 |
} else {
|
|
Packit Bot |
a284d4 |
album = album->next;
|
|
Packit Bot |
a284d4 |
}
|
|
Packit Bot |
a284d4 |
}
|
|
Packit Bot |
a284d4 |
|
|
Packit Bot |
a284d4 |
if (found_album == NULL) {
|
|
Packit Bot |
a284d4 |
printf("Could not find Album. Retrying with only Album name\n");
|
|
Packit Bot |
a284d4 |
album = album_orig;
|
|
Packit Bot |
a284d4 |
while(album != NULL) {
|
|
Packit Bot |
a284d4 |
if ((album->name != NULL) &&
|
|
Packit Bot |
a284d4 |
!strcmp(album->name, albuminfo->name) ){
|
|
Packit Bot |
a284d4 |
/* Disconnect this album for later use */
|
|
Packit Bot |
a284d4 |
found_album = album;
|
|
Packit Bot |
a284d4 |
album = album->next;
|
|
Packit Bot |
a284d4 |
found_album->next = NULL;
|
|
Packit Bot |
a284d4 |
} else {
|
|
Packit Bot |
a284d4 |
album = album->next;
|
|
Packit Bot |
a284d4 |
}
|
|
Packit Bot |
a284d4 |
}
|
|
Packit Bot |
a284d4 |
}
|
|
Packit Bot |
a284d4 |
|
|
Packit Bot |
a284d4 |
if (found_album != NULL) {
|
|
Packit Bot |
a284d4 |
uint32_t *tracks;
|
|
Packit Bot |
a284d4 |
|
|
Packit Bot |
a284d4 |
tracks = (uint32_t *)malloc((found_album->no_tracks+1) * sizeof(uint32_t));
|
|
Packit Bot |
a284d4 |
printf("Album \"%s\" found: updating...\n", found_album->name);
|
|
Packit Bot |
a284d4 |
if (!tracks) {
|
|
Packit Bot |
a284d4 |
printf("failed malloc in add_track_to_album()\n");
|
|
Packit Bot |
a284d4 |
return 1;
|
|
Packit Bot |
a284d4 |
}
|
|
Packit Bot |
a284d4 |
found_album->no_tracks++;
|
|
Packit Bot |
a284d4 |
if (found_album->tracks != NULL) {
|
|
Packit Bot |
a284d4 |
memcpy(tracks, found_album->tracks, found_album->no_tracks * sizeof(uint32_t));
|
|
Packit Bot |
a284d4 |
free(found_album->tracks);
|
|
Packit Bot |
a284d4 |
}
|
|
Packit Bot |
a284d4 |
tracks[found_album->no_tracks-1] = trackmeta->item_id;
|
|
Packit Bot |
a284d4 |
found_album->tracks = tracks;
|
|
Packit Bot |
a284d4 |
ret = LIBMTP_Update_Album(device, found_album);
|
|
Packit Bot |
a284d4 |
} else {
|
|
Packit Bot |
a284d4 |
uint32_t *trackid;
|
|
Packit Bot |
a284d4 |
|
|
Packit Bot |
a284d4 |
trackid = (uint32_t *)malloc(sizeof(uint32_t));
|
|
Packit Bot |
a284d4 |
*trackid = trackmeta->item_id;
|
|
Packit Bot |
a284d4 |
albuminfo->tracks = trackid;
|
|
Packit Bot |
a284d4 |
albuminfo->no_tracks = 1;
|
|
Packit Bot |
a284d4 |
albuminfo->storage_id = trackmeta->storage_id;
|
|
Packit Bot |
a284d4 |
printf("Album doesn't exist: creating...\n");
|
|
Packit Bot |
a284d4 |
ret = LIBMTP_Create_New_Album(device, albuminfo);
|
|
Packit Bot |
a284d4 |
/* albuminfo will be destroyed later by caller */
|
|
Packit Bot |
a284d4 |
}
|
|
Packit Bot |
a284d4 |
|
|
Packit Bot |
a284d4 |
/* Delete the earlier retrieved Album list */
|
|
Packit Bot |
a284d4 |
album=album_orig;
|
|
Packit Bot |
a284d4 |
while(album!=NULL){
|
|
Packit Bot |
a284d4 |
LIBMTP_album_t *tmp;
|
|
Packit Bot |
a284d4 |
|
|
Packit Bot |
a284d4 |
tmp = album;
|
|
Packit Bot |
a284d4 |
album = album->next;
|
|
Packit Bot |
a284d4 |
LIBMTP_destroy_album_t(tmp);
|
|
Packit Bot |
a284d4 |
}
|
|
Packit Bot |
a284d4 |
|
|
Packit Bot |
a284d4 |
if (ret != 0) {
|
|
Packit Bot |
a284d4 |
printf("Error creating or updating album.\n");
|
|
Packit Bot |
a284d4 |
printf("(This could be due to that your device does not support albums.)\n");
|
|
Packit Bot |
a284d4 |
LIBMTP_Dump_Errorstack(device);
|
|
Packit Bot |
a284d4 |
LIBMTP_Clear_Errorstack(device);
|
|
Packit Bot |
a284d4 |
} else {
|
|
Packit Bot |
a284d4 |
printf("success!\n");
|
|
Packit Bot |
a284d4 |
}
|
|
Packit Bot |
a284d4 |
return ret;
|
|
Packit Bot |
a284d4 |
}
|
|
Packit Bot |
a284d4 |
|
|
Packit Bot |
a284d4 |
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, uint16_t quiet)
|
|
Packit Bot |
a284d4 |
{
|
|
Packit Bot |
a284d4 |
char *filename, *parent;
|
|
Packit Bot |
a284d4 |
char artist[80], albumartist[80], title[80], genre[80], album[80], composer[80];
|
|
Packit Bot |
a284d4 |
char *to_path_copy = NULL;
|
|
Packit Bot |
a284d4 |
char num[80];
|
|
Packit Bot |
a284d4 |
uint64_t filesize;
|
|
Packit Bot |
a284d4 |
uint32_t parent_id = 0;
|
|
Packit Bot |
a284d4 |
struct stat sb;
|
|
Packit Bot |
a284d4 |
LIBMTP_track_t *trackmeta;
|
|
Packit Bot |
a284d4 |
LIBMTP_album_t *albuminfo;
|
|
Packit Bot |
a284d4 |
int ret;
|
|
Packit Bot |
a284d4 |
|
|
Packit Bot |
a284d4 |
printf("Sending track %s to %s\n", from_path, to_path);
|
|
Packit Bot |
a284d4 |
|
|
Packit Bot |
a284d4 |
to_path_copy = strdup(to_path);
|
|
Packit Bot |
a284d4 |
parent = dirname(to_path_copy);
|
|
Packit Bot |
a284d4 |
parent_id = parse_path (parent,files,folders);
|
|
Packit Bot |
a284d4 |
if (parent_id == -1) {
|
|
Packit Bot |
a284d4 |
free (to_path_copy);
|
|
Packit Bot |
a284d4 |
printf("Parent folder could not be found, skipping\n");
|
|
Packit Bot |
a284d4 |
return 1;
|
|
Packit Bot |
a284d4 |
}
|
|
Packit Bot |
a284d4 |
strcpy (to_path_copy,to_path);
|
|
Packit Bot |
a284d4 |
filename = basename(to_path_copy);
|
|
Packit Bot |
a284d4 |
|
|
Packit Bot |
a284d4 |
if (stat(from_path, &sb) == -1) {
|
|
Packit Bot |
a284d4 |
fprintf(stderr, "%s: ", from_path);
|
|
Packit Bot |
a284d4 |
perror("stat");
|
|
Packit Bot |
a284d4 |
free (to_path_copy);
|
|
Packit Bot |
a284d4 |
return 1;
|
|
Packit Bot |
a284d4 |
}
|
|
Packit Bot |
a284d4 |
|
|
Packit Bot |
a284d4 |
if (!S_ISREG(sb.st_mode)) {
|
|
Packit Bot |
a284d4 |
free (to_path_copy);
|
|
Packit Bot |
a284d4 |
return 0;
|
|
Packit Bot |
a284d4 |
}
|
|
Packit Bot |
a284d4 |
|
|
Packit Bot |
a284d4 |
filesize = sb.st_size;
|
|
Packit Bot |
a284d4 |
|
|
Packit Bot |
a284d4 |
trackmeta = LIBMTP_new_track_t();
|
|
Packit Bot |
a284d4 |
trackmeta->filetype = find_filetype (from_path);
|
|
Packit Bot |
a284d4 |
if (!LIBMTP_FILETYPE_IS_TRACK(trackmeta->filetype)) {
|
|
Packit Bot |
a284d4 |
printf("Not a valid track codec: \"%s\"\n", LIBMTP_Get_Filetype_Description(trackmeta->filetype));
|
|
Packit Bot |
a284d4 |
LIBMTP_destroy_track_t(trackmeta);
|
|
Packit Bot |
a284d4 |
free (to_path_copy);
|
|
Packit Bot |
a284d4 |
return 1;
|
|
Packit Bot |
a284d4 |
}
|
|
Packit Bot |
a284d4 |
|
|
Packit Bot |
a284d4 |
if ((ptitle == NULL) && (quiet == 0)) {
|
|
Packit Bot |
a284d4 |
if ( (ptitle = prompt("Title", title, 80, 0)) != NULL )
|
|
Packit Bot |
a284d4 |
if (!strlen(ptitle)) ptitle = NULL;
|
|
Packit Bot |
a284d4 |
}
|
|
Packit Bot |
a284d4 |
|
|
Packit Bot |
a284d4 |
if ((palbum == NULL) && (quiet == 0)) {
|
|
Packit Bot |
a284d4 |
if ( (palbum = prompt("Album", album, 80, 0)) != NULL )
|
|
Packit Bot |
a284d4 |
if (!strlen(palbum)) palbum = NULL;
|
|
Packit Bot |
a284d4 |
}
|
|
Packit Bot |
a284d4 |
|
|
Packit Bot |
a284d4 |
if ((palbumartist == NULL) && (quiet == 0)) {
|
|
Packit Bot |
a284d4 |
if ( (palbumartist = prompt("Album artist", albumartist, 80, 0)) != NULL )
|
|
Packit Bot |
a284d4 |
if (!strlen(palbumartist)) palbumartist = NULL;
|
|
Packit Bot |
a284d4 |
}
|
|
Packit Bot |
a284d4 |
|
|
Packit Bot |
a284d4 |
if ((partist == NULL) && (quiet == 0)) {
|
|
Packit Bot |
a284d4 |
if ( (partist = prompt("Artist", artist, 80, 0)) != NULL )
|
|
Packit Bot |
a284d4 |
if (!strlen(partist)) partist = NULL;
|
|
Packit Bot |
a284d4 |
}
|
|
Packit Bot |
a284d4 |
|
|
Packit Bot |
a284d4 |
if ((pcomposer == NULL) && (quiet == 0)) {
|
|
Packit Bot |
a284d4 |
if ( (pcomposer = prompt("Writer or Composer", composer, 80, 0)) != NULL )
|
|
Packit Bot |
a284d4 |
if (!strlen(pcomposer)) pcomposer = NULL;
|
|
Packit Bot |
a284d4 |
}
|
|
Packit Bot |
a284d4 |
|
|
Packit Bot |
a284d4 |
if ((pgenre == NULL) && (quiet == 0)) {
|
|
Packit Bot |
a284d4 |
if ( (pgenre = prompt("Genre", genre, 80, 0)) != NULL )
|
|
Packit Bot |
a284d4 |
if (!strlen(pgenre)) pgenre = NULL;
|
|
Packit Bot |
a284d4 |
}
|
|
Packit Bot |
a284d4 |
|
|
Packit Bot |
a284d4 |
if ((tracknum == 0) && (quiet == 0)) {
|
|
Packit Bot |
a284d4 |
char *pnum;
|
|
Packit Bot |
a284d4 |
if ( (pnum = prompt("Track number", num, 80, 0)) == NULL )
|
|
Packit Bot |
a284d4 |
tracknum = 0;
|
|
Packit Bot |
a284d4 |
else
|
|
Packit Bot |
a284d4 |
tracknum = strtoul(pnum, 0, 10);
|
|
Packit Bot |
a284d4 |
}
|
|
Packit Bot |
a284d4 |
|
|
Packit Bot |
a284d4 |
if ((year == 0) && (quiet == 0)) {
|
|
Packit Bot |
a284d4 |
char *pnum;
|
|
Packit Bot |
a284d4 |
if ( (pnum = prompt("Year", num, 80, 0)) == NULL )
|
|
Packit Bot |
a284d4 |
year = 0;
|
|
Packit Bot |
a284d4 |
else
|
|
Packit Bot |
a284d4 |
year = strtoul(pnum, 0, 10);
|
|
Packit Bot |
a284d4 |
}
|
|
Packit Bot |
a284d4 |
|
|
Packit Bot |
a284d4 |
if ((length == 0) && (quiet == 0)) {
|
|
Packit Bot |
a284d4 |
char *pnum;
|
|
Packit Bot |
a284d4 |
if ( (pnum = prompt("Length", num, 80, 0)) == NULL )
|
|
Packit Bot |
a284d4 |
length = 0;
|
|
Packit Bot |
a284d4 |
else
|
|
Packit Bot |
a284d4 |
length = strtoul(pnum, 0, 10);
|
|
Packit Bot |
a284d4 |
}
|
|
Packit Bot |
a284d4 |
|
|
Packit Bot |
a284d4 |
printf("Sending track:\n");
|
|
Packit Bot |
a284d4 |
printf("Codec: %s\n", LIBMTP_Get_Filetype_Description(trackmeta->filetype));
|
|
Packit Bot |
a284d4 |
if (ptitle) {
|
|
Packit Bot |
a284d4 |
printf("Title: %s\n", ptitle);
|
|
Packit Bot |
a284d4 |
trackmeta->title = strdup(ptitle);
|
|
Packit Bot |
a284d4 |
}
|
|
Packit Bot |
a284d4 |
|
|
Packit Bot |
a284d4 |
albuminfo = LIBMTP_new_album_t();
|
|
Packit Bot |
a284d4 |
|
|
Packit Bot |
a284d4 |
if (palbum) {
|
|
Packit Bot |
a284d4 |
printf("Album: %s\n", palbum);
|
|
Packit Bot |
a284d4 |
trackmeta->album = strdup(palbum);
|
|
Packit Bot |
a284d4 |
albuminfo->name = strdup(palbum);
|
|
Packit Bot |
a284d4 |
}
|
|
Packit Bot |
a284d4 |
if (palbumartist) {
|
|
Packit Bot |
a284d4 |
printf("Album artist: %s\n", palbumartist);
|
|
Packit Bot |
a284d4 |
albuminfo->artist = strdup(palbumartist);
|
|
Packit Bot |
a284d4 |
}
|
|
Packit Bot |
a284d4 |
if (partist) {
|
|
Packit Bot |
a284d4 |
printf("Artist: %s\n", partist);
|
|
Packit Bot |
a284d4 |
trackmeta->artist = strdup(partist);
|
|
Packit Bot |
a284d4 |
if (palbumartist == NULL)
|
|
Packit Bot |
a284d4 |
albuminfo->artist = strdup(partist);
|
|
Packit Bot |
a284d4 |
}
|
|
Packit Bot |
a284d4 |
if (pcomposer) {
|
|
Packit Bot |
a284d4 |
printf("Writer or Composer: %s\n", pcomposer);
|
|
Packit Bot |
a284d4 |
trackmeta->composer = strdup(pcomposer);
|
|
Packit Bot |
a284d4 |
albuminfo->composer = strdup(pcomposer);
|
|
Packit Bot |
a284d4 |
}
|
|
Packit Bot |
a284d4 |
if (pgenre) {
|
|
Packit Bot |
a284d4 |
printf("Genre: %s\n", pgenre);
|
|
Packit Bot |
a284d4 |
trackmeta->genre = strdup(pgenre);
|
|
Packit Bot |
a284d4 |
albuminfo->genre = strdup(pgenre);
|
|
Packit Bot |
a284d4 |
}
|
|
Packit Bot |
a284d4 |
if (year > 0) {
|
|
Packit Bot |
a284d4 |
char tmp[80];
|
|
Packit Bot |
a284d4 |
printf("Year: %d\n", year);
|
|
Packit Bot |
a284d4 |
snprintf(tmp, sizeof(tmp)-1, "%4d0101T0000.0", year);
|
|
Packit Bot |
a284d4 |
tmp[sizeof(tmp)-1] = '\0';
|
|
Packit Bot |
a284d4 |
trackmeta->date = strdup(tmp);
|
|
Packit Bot |
a284d4 |
}
|
|
Packit Bot |
a284d4 |
if (tracknum > 0) {
|
|
Packit Bot |
a284d4 |
printf("Track no: %d\n", tracknum);
|
|
Packit Bot |
a284d4 |
trackmeta->tracknumber = tracknum;
|
|
Packit Bot |
a284d4 |
}
|
|
Packit Bot |
a284d4 |
if (length > 0) {
|
|
Packit Bot |
a284d4 |
printf("Length: %d\n", length);
|
|
Packit Bot |
a284d4 |
// Multiply by 1000 since this is in milliseconds
|
|
Packit Bot |
a284d4 |
trackmeta->duration = length * 1000;
|
|
Packit Bot |
a284d4 |
}
|
|
Packit Bot |
a284d4 |
// We should always have this
|
|
Packit Bot |
a284d4 |
if (filename != NULL) {
|
|
Packit Bot |
a284d4 |
trackmeta->filename = strdup(filename);
|
|
Packit Bot |
a284d4 |
}
|
|
Packit Bot |
a284d4 |
trackmeta->filesize = filesize;
|
|
Packit Bot |
a284d4 |
trackmeta->parent_id = parent_id;
|
|
Packit Bot |
a284d4 |
{
|
|
Packit Bot |
a284d4 |
int rc;
|
|
Packit Bot |
a284d4 |
char *desc = NULL;
|
|
Packit Bot |
a284d4 |
LIBMTP_devicestorage_t *pds = NULL;
|
|
Packit Bot |
a284d4 |
|
|
Packit Bot |
a284d4 |
if (0 != (rc=LIBMTP_Get_Storage(device, LIBMTP_STORAGE_SORTBY_NOTSORTED))) {
|
|
Packit Bot |
a284d4 |
perror("LIBMTP_Get_Storage()");
|
|
Packit Bot |
a284d4 |
exit(-1);
|
|
Packit Bot |
a284d4 |
}
|
|
Packit Bot |
a284d4 |
for (pds = device->storage; pds != NULL; pds = pds->next) {
|
|
Packit Bot |
a284d4 |
if (pds->id == storageid) {
|
|
Packit Bot |
a284d4 |
desc = strdup(pds->StorageDescription);
|
|
Packit Bot |
a284d4 |
break;
|
|
Packit Bot |
a284d4 |
}
|
|
Packit Bot |
a284d4 |
}
|
|
Packit Bot |
a284d4 |
if (NULL != desc) {
|
|
Packit Bot |
a284d4 |
printf("Storage ID: %s (%u)\n", desc, storageid);
|
|
Packit Bot |
a284d4 |
free(desc);
|
|
Packit Bot |
a284d4 |
} else
|
|
Packit Bot |
a284d4 |
printf("Storage ID: %u\n", storageid);
|
|
Packit Bot |
a284d4 |
trackmeta->storage_id = storageid;
|
|
Packit Bot |
a284d4 |
}
|
|
Packit Bot |
a284d4 |
|
|
Packit Bot |
a284d4 |
printf("Sending track...\n");
|
|
Packit Bot |
a284d4 |
ret = LIBMTP_Send_Track_From_File(device, from_path, trackmeta, progress, NULL);
|
|
Packit Bot |
a284d4 |
printf("\n");
|
|
Packit Bot |
a284d4 |
if (ret != 0) {
|
|
Packit Bot |
a284d4 |
printf("Error sending track.\n");
|
|
Packit Bot |
a284d4 |
LIBMTP_Dump_Errorstack(device);
|
|
Packit Bot |
a284d4 |
LIBMTP_Clear_Errorstack(device);
|
|
Packit Bot |
a284d4 |
ret = 1;
|
|
Packit Bot |
a284d4 |
} else {
|
|
Packit Bot |
a284d4 |
printf("New track ID: %d\n", trackmeta->item_id);
|
|
Packit Bot |
a284d4 |
}
|
|
Packit Bot |
a284d4 |
|
|
Packit Bot |
a284d4 |
/* Add here add to album call */
|
|
Packit Bot |
a284d4 |
if (palbum)
|
|
Packit Bot |
a284d4 |
ret = add_track_to_album(albuminfo, trackmeta);
|
|
Packit Bot |
a284d4 |
|
|
Packit Bot |
a284d4 |
LIBMTP_destroy_album_t(albuminfo);
|
|
Packit Bot |
a284d4 |
LIBMTP_destroy_track_t(trackmeta);
|
|
Packit Bot |
a284d4 |
free (to_path_copy);
|
|
Packit Bot |
a284d4 |
|
|
Packit Bot |
a284d4 |
return ret;
|
|
Packit Bot |
a284d4 |
}
|
|
Packit Bot |
a284d4 |
|
|
Packit Bot |
a284d4 |
int sendtrack_command (int argc, char **argv) {
|
|
Packit Bot |
a284d4 |
int opt, ret;
|
|
Packit Bot |
a284d4 |
extern int optind;
|
|
Packit Bot |
a284d4 |
extern char *optarg;
|
|
Packit Bot |
a284d4 |
char *partist = NULL;
|
|
Packit Bot |
a284d4 |
char *palbumartist = NULL;
|
|
Packit Bot |
a284d4 |
char *pcomposer = NULL;
|
|
Packit Bot |
a284d4 |
char *ptitle = NULL;
|
|
Packit Bot |
a284d4 |
char *pgenre = NULL;
|
|
Packit Bot |
a284d4 |
char *pcodec = NULL;
|
|
Packit Bot |
a284d4 |
char *palbum = NULL;
|
|
Packit Bot |
a284d4 |
uint16_t tracknum = 0;
|
|
Packit Bot |
a284d4 |
uint16_t length = 0;
|
|
Packit Bot |
a284d4 |
uint16_t year = 0;
|
|
Packit Bot |
a284d4 |
uint16_t quiet = 0;
|
|
Packit Bot |
a284d4 |
uint32_t storageid = 0;
|
|
Packit Bot |
a284d4 |
while ( (opt = getopt(argc, argv, "qD:t:a:A:w:l:c:g:n:d:y:s:")) != -1 ) {
|
|
Packit Bot |
a284d4 |
switch (opt) {
|
|
Packit Bot |
a284d4 |
case 't':
|
|
Packit Bot |
a284d4 |
free (ptitle);
|
|
Packit Bot |
a284d4 |
ptitle = strdup(optarg);
|
|
Packit Bot |
a284d4 |
break;
|
|
Packit Bot |
a284d4 |
case 'a':
|
|
Packit Bot |
a284d4 |
free (partist);
|
|
Packit Bot |
a284d4 |
partist = strdup(optarg);
|
|
Packit Bot |
a284d4 |
break;
|
|
Packit Bot |
a284d4 |
case 'A':
|
|
Packit Bot |
a284d4 |
free (palbumartist);
|
|
Packit Bot |
a284d4 |
palbumartist = strdup(optarg);
|
|
Packit Bot |
a284d4 |
break;
|
|
Packit Bot |
a284d4 |
case 'w':
|
|
Packit Bot |
a284d4 |
free (pcomposer);
|
|
Packit Bot |
a284d4 |
pcomposer = strdup(optarg);
|
|
Packit Bot |
a284d4 |
break;
|
|
Packit Bot |
a284d4 |
case 'l':
|
|
Packit Bot |
a284d4 |
free (palbum);
|
|
Packit Bot |
a284d4 |
palbum = strdup(optarg);
|
|
Packit Bot |
a284d4 |
break;
|
|
Packit Bot |
a284d4 |
case 'c':
|
|
Packit Bot |
a284d4 |
free (pcodec);
|
|
Packit Bot |
a284d4 |
pcodec = strdup(optarg); // FIXME: DSM check for MP3, WAV or WMA
|
|
Packit Bot |
a284d4 |
break;
|
|
Packit Bot |
a284d4 |
case 'g':
|
|
Packit Bot |
a284d4 |
free (pgenre);
|
|
Packit Bot |
a284d4 |
pgenre = strdup(optarg);
|
|
Packit Bot |
a284d4 |
break;
|
|
Packit Bot |
a284d4 |
case 'n':
|
|
Packit Bot |
a284d4 |
tracknum = atoi(optarg);
|
|
Packit Bot |
a284d4 |
break;
|
|
Packit Bot |
a284d4 |
case 's':
|
|
Packit Bot |
a284d4 |
storageid = (uint32_t) strtoul(optarg, NULL, 0);
|
|
Packit Bot |
a284d4 |
break;
|
|
Packit Bot |
a284d4 |
case 'd':
|
|
Packit Bot |
a284d4 |
length = atoi(optarg);
|
|
Packit Bot |
a284d4 |
break;
|
|
Packit Bot |
a284d4 |
case 'y':
|
|
Packit Bot |
a284d4 |
year = atoi(optarg);
|
|
Packit Bot |
a284d4 |
break;
|
|
Packit Bot |
a284d4 |
case 'q':
|
|
Packit Bot |
a284d4 |
quiet = 1;
|
|
Packit Bot |
a284d4 |
break;
|
|
Packit Bot |
a284d4 |
default:
|
|
Packit Bot |
a284d4 |
sendtrack_usage();
|
|
Packit Bot |
a284d4 |
}
|
|
Packit Bot |
a284d4 |
}
|
|
Packit Bot |
a284d4 |
argc -= optind;
|
|
Packit Bot |
a284d4 |
argv += optind;
|
|
Packit Bot |
a284d4 |
|
|
Packit Bot |
a284d4 |
if ( argc != 2 ) {
|
|
Packit Bot |
a284d4 |
printf("You need to pass a filename and destination.\n");
|
|
Packit Bot |
a284d4 |
sendtrack_usage();
|
|
Packit Bot |
a284d4 |
ret = 0;
|
|
Packit Bot |
a284d4 |
} else {
|
|
Packit Bot |
a284d4 |
checklang();
|
|
Packit Bot |
a284d4 |
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);
|
|
Packit Bot |
a284d4 |
ret = sendtrack_function(argv[0],argv[1],partist,palbumartist,ptitle,pgenre,palbum,pcomposer, tracknum, length, year, storageid, quiet);
|
|
Packit Bot |
a284d4 |
}
|
|
Packit Bot |
a284d4 |
free (ptitle);
|
|
Packit Bot |
a284d4 |
free (partist);
|
|
Packit Bot |
a284d4 |
free (palbumartist);
|
|
Packit Bot |
a284d4 |
free (pcomposer);
|
|
Packit Bot |
a284d4 |
free (palbum);
|
|
Packit Bot |
a284d4 |
free (pcodec);
|
|
Packit Bot |
a284d4 |
free (pgenre);
|
|
Packit Bot |
a284d4 |
return ret;
|
|
Packit Bot |
a284d4 |
}
|