#include "common.h"
#include <string.h>
static char *prompt (const char *prompt, char *buffer, size_t bufsz, int required)
{
char *cp, *bp;
while (1) {
fprintf(stdout, "%s> ", prompt);
if ( fgets(buffer, bufsz, stdin) == NULL ) {
if (ferror(stdin)) {
perror("fgets");
} else {
fprintf(stderr, "EOF on stdin\n");
}
return NULL;
}
cp= strrchr(buffer, '\n');
if ( cp != NULL ) *cp= '\0';
bp= buffer;
while ( bp != cp ) {
if ( *bp != ' ' && *bp != '\t' ) return bp;
bp++;
}
if (! required) return bp;
}
}
static void usage (void)
{
fprintf(stderr, "usage: tagtr [ -D debuglvl ] <trackid>\n");
exit(1);
}
int main(int argc, char **argv)
{
int n, opt, debug, lookup;
extern char *optarg;
extern int optind;
char filename[80], artist[80], title[80], genre[80], codec[80], album[80];
char num[80];
char *pfilename, *partist, *ptitle, *pgenre, *pcodec, *palbum, *pnum;
char *endptr;
u_int16_t tracknum, length, year;
u_int32_t filesize;
int trackid;
char *lang;
debug = 0;
lookup = 0;
while ( (opt= getopt(argc, argv, "D:l")) != -1 ) {
switch (opt) {
case 'l':
lookup= 1;
case 'D':
debug= atoi(optarg);
break;
default:
usage();
}
}
argc-= optind;
argv+= optind;
if ( argc != 1 ) usage();
lang = getenv("LANG");
if (lang != NULL) {
if (strlen(lang) > 5) {
if (!strcmp(&lang[strlen(lang)-5], "UTF-8")) {
}
}
}
trackid= strtoul(argv[0], &endptr, 10);
if ( endptr[0] != '\0' ) {
fprintf(stderr, "invalid id %s\n", argv[1]);
return 1;
}
if ( (pcodec= prompt("CODEC", codec, 80, 0)) == NULL ) return 1;
if ( ! strlen(pcodec) ) pcodec= NULL;
if ( (ptitle= prompt("Title", title, 80, 0)) == NULL ) return 1;
if ( ! strlen(ptitle) ) ptitle= NULL;
if ( (palbum= prompt("Album", album, 80, 0)) == NULL ) return 1;
if ( ! strlen(palbum) ) palbum= NULL;
if ( (partist= prompt("Artist", artist, 80, 0)) == NULL ) return 1;
if ( ! strlen(partist) ) partist= NULL;
if ( (pgenre= prompt("Genre", genre, 80, 0)) == NULL ) return 1;
if ( ! strlen(pgenre) ) pgenre= NULL;
if ( (pfilename= prompt("File path", filename, 80, 0)) == NULL ) return 1;
if ( ! strlen(pfilename) ) pfilename= NULL;
if ( (pnum= prompt("Track number", num, 80, 0)) == NULL ) return 1;
if ( strlen(pnum) ) {
tracknum = strtoul(pnum, 0, 10);
} else {
tracknum = 0;
}
if ( (pnum= prompt("Length", num, 80, 0)) == NULL ) return 1;
if ( strlen(pnum) ) {
length= strtoul(pnum, 0, 10);
} else {
length= 0;
}
if ( (pnum= prompt("Year", num, 80, 0)) == NULL ) return 1;
if ( strlen(pnum) ) {
year = strtoul(pnum, 0, 10);
} else {
year = 0;
}
filesize= 0;
if ( ! lookup ) {
if ( (pnum= prompt("File size", num, 80, 0)) == NULL )
return 1;
if ( strlen(pnum) ) {
filesize = strtoul(pnum, 0, 10);
} else {
filesize = 0;
}
}
fprintf(stderr, "could not locate any jukeboxes\n");
return 1;
}
if ( n == 0 ) {
fprintf(stderr, "no NJB devices found\n");
return 0;
}
njb= njbs;
return 1;
}
frame = NJB_Songid_Frame_New_Filesize(filesize);
frame = NJB_Songid_Frame_New_Title(ptitle);
frame = NJB_Songid_Frame_New_Album(palbum);
frame = NJB_Songid_Frame_New_Artist(partist);
frame = NJB_Songid_Frame_New_Genre(pgenre);
frame = NJB_Songid_Frame_New_Year(year);
frame = NJB_Songid_Frame_New_Tracknum(tracknum);
frame = NJB_Songid_Frame_New_Length(length);
frame = NJB_Songid_Frame_New_Filename(pfilename);
} else {
printf("NJB track ID: %u\n", trackid);
}
printf("\n");
return 0;
}
int NJB_Capture(njb_t *njb)
Definition: procedure.c:223
int NJB_Discover(njb_t *njbs, int limit, int *n)
Definition: procedure.c:108
int NJB_Release(njb_t *njb)
Definition: procedure.c:266
int NJB_Open(njb_t *njb)
Definition: procedure.c:130
void NJB_Set_Unicode(int unicode_flag)
Definition: procedure.c:2833
void NJB_Set_Debug(int debug_flags)
Definition: procedure.c:2819
void NJB_Error_Dump(njb_t *njb, FILE *fp)
Definition: njb_error.c:418
void NJB_Songid_Addframe(njb_songid_t *song, njb_songid_frame_t *frame)
Definition: songid.c:651
void NJB_Songid_Destroy(njb_songid_t *song)
Definition: songid.c:673
njb_songid_t * NJB_Songid_New(void)
Definition: songid.c:42
int NJB_Replace_Track_Tag(njb_t *njb, u_int32_t trackid, njb_songid_t *songid)
Definition: procedure.c:2895
njb_songid_frame_t * NJB_Songid_Frame_New_Codec(const char *value)
Definition: songid.c:871
#define NJB_UC_UTF8
Definition: libnjb.h:147
#define NJB_MAX_DEVICES
Definition: libnjb.h:60