version 0.43
[FAPG] / fapg.c
diff --git a/fapg.c b/fapg.c
index df022cf..bd2b3f0 100644 (file)
--- a/fapg.c
+++ b/fapg.c
@@ -43,7 +43,7 @@
 
 #define MP3_BASE 1024
 #define OGG_BASE 1024*10
-#define MAX 1024*200            /* 200ko for ID3 with JPEG images in it */
+#define MAX 1024*250            /* 250ko for ID3 with JPEG images in it */
 
 #define FORMAT_M3U 0
 #define FORMAT_PLS 1
@@ -85,11 +85,13 @@ int duration;
 #define MPPENC 4
 #define OGGENC 5
 #define WAVENC 6
+#define WMAENC 7
 
 char *magic[] = { NULL,
     "audio/mpeg", "audio/mpeg",
     "audio/mpeg", "audio/mpeg",
     "audio/ogg-vorbis", "audio/x-wav",
+    "audio/x-ms-wma", 
     NULL
 };
 
@@ -423,7 +425,7 @@ void print_webpath(const char *path)
 {
     const char *c = path;
 
-    printf(prefix);             /* we must not modify this part */
+    printf("%s", prefix);             /* we must not modify this part */
     if(*c == '.' && c[1] == '/') {      /* remove leading "./" when parsing current directory */
         c += 2;
         /* maybe there follow many slashes */
@@ -441,7 +443,7 @@ void print_webpath(const char *path)
 void print_path(const char *path)
 {
     const char *c = path;
-    printf(prefix);
+    printf("%s", prefix);
     /* skip leading "./" when parsing current directory */
     if(*c == '.' && *(c + 1) == '/') {
         c += 2;
@@ -498,7 +500,6 @@ void reference(const char *title)
     pipe = popen(command, "r");
     if(pipe == NULL) {
         fprintf(stderr, "Warning >> can't open pipe >%s< !\n", command);
-        free(command);
         return;
     }
     fgets(buffer, 1020, pipe);
@@ -767,6 +768,9 @@ void parse_mp3(unsigned char *file)
                     /* genre=atoi(&genrebuf[1]); */
                     genre = atoi(c + 12);
                 }
+                if(strncmp(c, "TLEN", 4) == 0) {
+                    duration = atoi(c + 11) / 1000;
+                }
                 c += size + 10;
             }
     }
@@ -841,7 +845,7 @@ void parse_ogg(unsigned char *file)
     lus = fread(buffer, 1, OGG_BASE, fic);
 
     /* try Ogg */
-    if(buffer[0] != 'O' && buffer[1] != 'g' && buffer[2] != 'g') {
+    if(strncmp(buffer, "Ogg", 3) != 0) {
         fprintf(stderr, "Warning >> not a Ogg header : %s\n", file);
         return;
     }
@@ -860,6 +864,13 @@ void parse_ogg(unsigned char *file)
             title[size - 6] = '\0';
             c += size;
         }
+        if(strncasecmp(c, "ALBUM ARTIST=", 13) == 0) {
+            // ignore tag
+            size =
+                *(c - 4) + (*(c - 3) << 8) + (*(c - 2) << 16) +
+                (*(c - 1) << 24);
+            c += size;
+        }
         if(strncasecmp(c, "ARTIST=", 7) == 0) {
             size =
                 *(c - 4) + (*(c - 3) << 8) + (*(c - 2) << 16) +
@@ -924,7 +935,7 @@ void parse_mpc(unsigned char *file)
     lus = fread(buffer, 1, 12, fic);
 
     /* try Musepack */
-    if(buffer[0] != 'M' && buffer[1] != 'P' && buffer[2] != '+') {
+    if (strncmp(buffer, "MP+", 3) != 0) {
         fprintf(stderr, "Warning >> not a Musepack header : %s\n", file);
         return;
     }
@@ -1281,9 +1292,15 @@ void parse_file(unsigned char *newpath, unsigned char * original_path)
         encoding = OGGENC;
     }
     if(strcmp(".wav", ext) == 0) {
-        duration = -1;          /* parse_wav(newpath); */
+        duration = -1;
+        /* parse_wav(newpath); */
         encoding = WAVENC;
     }
+    if(strcmp(".wma", ext) == 0) {
+        duration = -1;
+        /* parse_wma(newpath); */
+        encoding = WMAENC;
+    }
     /* guesstitle() */
     if((strlen(artist) == 0) && (strlen(title) == 0)) {
         // there are no tag infos read
@@ -1321,12 +1338,10 @@ void parse_file(unsigned char *newpath, unsigned char * original_path)
         counter++;
         switch (format) {
         case FORMAT_M3U:
-            if(duration != -1) {
-                printf("#EXTINF:%d,", duration);
-                if(strlen(artist) != 0)
-                    printf("%s - ", artist);
-                printf("%s%s", title, eol);
-            }
+            printf("#EXTINF:%d,", duration);
+            if(strlen(artist) != 0)
+                printf("%s - ", artist);
+            printf("%s%s", title, eol);
             print_path(newpath);
             printf("%s", eol);
             break;