#define MP3_BASE 1024
#define OGG_BASE 1024*10
#define MAX 1024*250 /* 250ko for ID3 with JPEG images in it */
+#define MAX_ITEM 1024
-#define FORMAT_M3U 0
+#define FORMAT_M3U 0 /* "0" is not a good choice for debugging, but OK for a default */
#define FORMAT_PLS 1
#define FORMAT_HTML 2
#define FORMAT_RSS 3
int counter = 0;
-unsigned char artist[1024];
-unsigned char title[1024];
-unsigned char genrebuf[1024];
+unsigned char artist[MAX_ITEM];
+unsigned char title[MAX_ITEM];
+unsigned char genrebuf[MAX_ITEM];
unsigned char genre = 0;
int duration;
#define MP2ENC 1
}
}
+void utf16toutf8(char *c,int n)
+{
+ /* check whether the we need to convert UTF-16 to UTF-8 strings */
+ if ( ( c[0] != '\377' ) || ( c[1] != '\376' ) ) { return; }
+ /* only continue here, if the first 2 letters are 0xfffe *
+ * c references an UTF-16 input, where latin letters are *
+ * separated by zero bytes, which we need to eliminate */
+ int i=0; --n;
+ for(int j=2; (j<n) && (j<MAX_ITEM); j++ ) {
+ if( isprint(c[j]) ) { /* this is not perfect ! */
+ c[i++]=c[j];
+ } } c[i+1]=c[i]='\0';
+ /* the index i follows the zero-terminated "string" *
+ * now the read buffer is modified, not the file */
+ return;
+}
+
void myplaputstr(const char *c)
{
while(*c != 0) {
fprintf(stderr, "Debug >> parsing mp3 : %s\n", file);
/* read header */
- if((fic = fopen(file, "r")) == NULL) {
+ if((fic = fopen(file, "rb")) == NULL) {
fprintf(stderr, "Warning >> can't open file : %s\n", file);
return;
}
if(*c == 0)
break;
if(strncmp(c, "TT2", 3) == 0) {
+ utf16toutf8(c+7,size);
strncpy(title, c + 7, size - 1);
title[size - 1] = '\0';
}
if(strncmp(c, "TP1", 3) == 0) {
+ utf16toutf8(c+7,size);
strncpy(artist, c + 7, size - 1);
artist[size - 1] = '\0';
}
if(*c == 0)
break;
if(strncmp(c, "TIT2", 4) == 0) {
+ utf16toutf8(c+11,size);
strncpy(title, c + 11, size - 1);
title[size - 1] = '\0';
}
if(strncmp(c, "TPE1", 4) == 0) {
+ utf16toutf8(c+11,size);
strncpy(artist, c + 11, size - 1);
artist[size - 1] = '\0';
}