Linus Nielsen Feltzing a écrit :
Bluechip wrote:

1. Why does RB append a blank 4K ID3v2 header to the start of every file?


It's there for convenience, so that the file can be updated with a valid tag without rewriting the entire file.


That's the main flaw of id3v2, and yet another reason to switch to APEv2 ;-) I'm just kidding of course, I know id3v2 is more widely supported, but it gives me an occasion to remind you that APEv2 support for mp3 is just a 10-lines patch that doesn't break anything...

fred
Index: apps/metadata.c
===================================================================
RCS file: /cvsroot/rockbox/apps/metadata.c,v
retrieving revision 1.33
diff -u -r1.33 metadata.c
--- apps/metadata.c     5 Nov 2005 13:58:08 -0000       1.33
+++ apps/metadata.c     6 Nov 2005 17:04:08 -0000
@@ -401,11 +401,11 @@
 /* Read the items in an APEV2 tag. Only looks for a tag at the end of a 
  * file. Returns true if a tag was found and fully read, false otherwise.
  */
-static bool read_ape_tags(int fd, struct mp3entry* id3)
+static bool read_ape_tags(int fd, struct mp3entry* id3, int offset)
 {
     struct apetag_header header;
 
-    if ((lseek(fd, -APETAG_HEADER_LENGTH, SEEK_END) < 0)
+    if ((lseek(fd, -APETAG_HEADER_LENGTH + offset, SEEK_END) < 0)
         || (read(fd, &header, APETAG_HEADER_LENGTH) != APETAG_HEADER_LENGTH)
         || (memcmp(header.id, "APETAGEX", sizeof(header.id))))
     {
@@ -424,7 +424,7 @@
         unsigned int tag_remaining = header.length - APETAG_HEADER_LENGTH;
         int i;
         
-        if (lseek(fd, -header.length, SEEK_END) < 0)
+        if (lseek(fd, -header.length + offset, SEEK_END) < 0)
         {
             return false;
         }
@@ -1375,6 +1375,12 @@
         {
             return false;
         }
+        if (track->id3.id3version <= ID3_VER_1_1)
+        {
+            /* An id3v1 tag may hide an APEv2 tag... */
+            /* use any apetag info we find */
+            read_ape_tags(fd, &track->id3, -track->id3.id3v1len);
+        }
 
         break;
 
@@ -1389,7 +1395,7 @@
     case AFMT_MPC:
         if (!get_musepack_metadata(fd, &(track->id3)))
             return false;
-        read_ape_tags(fd, &(track->id3));
+        read_ape_tags(fd, &(track->id3), 0);
         break;
     
     case AFMT_OGG_VORBIS:
@@ -1452,7 +1458,7 @@
             track->id3.bitrate = filesize (fd) / (track->id3.length / 8);
         }
 
-        read_ape_tags(fd, &track->id3);     /* use any apetag info we find */
+        read_ape_tags(fd, &track->id3, 0); /* use any apetag info we find */
         break;
 
     case AFMT_A52:

Reply via email to