summaryrefslogtreecommitdiff
path: root/apps/metadata.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/metadata.c')
-rw-r--r--apps/metadata.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/apps/metadata.c b/apps/metadata.c
index 66719754ad..3a0ff574bf 100644
--- a/apps/metadata.c
+++ b/apps/metadata.c
@@ -30,6 +30,9 @@
30 30
31#if CONFIG_CODEC == SWCODEC 31#if CONFIG_CODEC == SWCODEC
32 32
33/* For trailing tag stripping */
34#include "buffering.h"
35
33#include "metadata/metadata_common.h" 36#include "metadata/metadata_common.h"
34#include "metadata/metadata_parsers.h" 37#include "metadata/metadata_parsers.h"
35 38
@@ -322,3 +325,42 @@ bool get_metadata(struct mp3entry* id3, int fd, const char* trackname)
322 return true; 325 return true;
323} 326}
324 327
328void strip_tags(int handle_id)
329{
330 int i;
331 static const unsigned char tag[] = "TAG";
332 static const unsigned char apetag[] = "APETAGEX";
333 size_t len, version;
334 unsigned char *tail;
335
336 if (bufgettail(handle_id, 128, (void **)&tail) != 128)
337 return;
338
339 for(i = 0;i < 3;i++)
340 if(tail[i] != tag[i])
341 goto strip_ape_tag;
342
343 /* Skip id3v1 tag */
344 logf("Cutting off ID3v1 tag");
345 bufcuttail(handle_id, 128);
346
347strip_ape_tag:
348 /* Check for APE tag (look for the APE tag footer) */
349
350 if (bufgettail(handle_id, 32, (void **)&tail) != 32)
351 return;
352
353 for(i = 0;i < 8;i++)
354 if(tail[i] != apetag[i])
355 return;
356
357 /* Read the version and length from the footer */
358 version = tail[8] | (tail[9] << 8) | (tail[10] << 16) | (tail[11] << 24);
359 len = tail[12] | (tail[13] << 8) | (tail[14] << 16) | (tail[15] << 24);
360 if (version == 2000)
361 len += 32; /* APEv2 has a 32 byte header */
362
363 /* Skip APE tag */
364 logf("Cutting off APE tag (%ldB)", len);
365 bufcuttail(handle_id, len);
366}