diff options
| author | Marcoen Hirschberg <marcoen@gmail.com> | 2007-06-16 18:19:51 +0000 |
|---|---|---|
| committer | Marcoen Hirschberg <marcoen@gmail.com> | 2007-06-16 18:19:51 +0000 |
| commit | 2175d1edf65367fd3fe3cff266b8d6ea12930f2f (patch) | |
| tree | 9d6f50ebfc7919b4e2f0853fc8c0cb844cabe995 /apps/metadata/spc.c | |
| parent | c3206a455a455fadb282d09f9af482c66b6bdf8e (diff) | |
| download | rockbox-2175d1edf65367fd3fe3cff266b8d6ea12930f2f.zip rockbox-2175d1edf65367fd3fe3cff266b8d6ea12930f2f.tar.gz rockbox-2175d1edf65367fd3fe3cff266b8d6ea12930f2f.tar.bz2 rockbox-2175d1edf65367fd3fe3cff266b8d6ea12930f2f.tar.xz | |
split up the metadata parser
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13637 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/metadata/spc.c')
| -rw-r--r-- | apps/metadata/spc.c | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/apps/metadata/spc.c b/apps/metadata/spc.c new file mode 100644 index 0000000..8d85518 --- /dev/null +++ b/apps/metadata/spc.c @@ -0,0 +1,126 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2005 Dave Chapman + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <ctype.h> +#include <inttypes.h> + +#include "system.h" +#include "id3.h" +#include "metadata_common.h" +#include "debug.h" +#include "atoi.h" +#include "rbunicode.h" + +bool get_spc_metadata(int fd, struct mp3entry* id3) +{ + /* Use the trackname part of the id3 structure as a temporary buffer */ + unsigned char * buf = (unsigned char *)id3->path; + int read_bytes; + char * p; + + unsigned long length; + unsigned long fade; + bool isbinary = true; + int i; + + /* try to get the ID666 tag */ + if ((lseek(fd, 0x2e, SEEK_SET) < 0) + || ((read_bytes = read(fd, buf, 0xD2)) < 0xD2)) + { + DEBUGF("lseek or read failed\n"); + return false; + } + + p = id3->id3v2buf; + + id3->title = p; + buf[31] = 0; + p = iso_decode(buf, p, 0, 32); + buf += 32; + + id3->album = p; + buf[31] = 0; + p = iso_decode(buf, p, 0, 32); + buf += 48; + + id3->comment = p; + buf[31] = 0; + p = iso_decode(buf, p, 0, 32); + buf += 32; + + /* Date check */ + if(buf[2] == '/' && buf[5] == '/') + isbinary = false; + + /* Reserved bytes check */ + if(buf[0xD2 - 0x2E - 112] >= '0' && + buf[0xD2 - 0x2E - 112] <= '9' && + buf[0xD3 - 0x2E - 112] == 0x00) + isbinary = false; + + /* is length & fade only digits? */ + for (i=0;i<8 && ( + (buf[0xA9 - 0x2E - 112+i]>='0'&&buf[0xA9 - 0x2E - 112+i]<='9') || + buf[0xA9 - 0x2E - 112+i]=='\0'); + i++); + if (i==8) isbinary = false; + + if(isbinary) { + id3->year = buf[0] | (buf[1]<<8); + buf += 11; + + length = (buf[0] | (buf[1]<<8) | (buf[2]<<16)) * 1000; + buf += 3; + + fade = (buf[0] | (buf[1]<<8) | (buf[2]<<16) | (buf[3]<<24)); + buf += 4; + } else { + char tbuf[6]; + + buf += 6; + buf[4] = 0; + id3->year = atoi(buf); + buf += 5; + + memcpy(tbuf, buf, 3); + tbuf[3] = 0; + length = atoi(tbuf) * 1000; + buf += 3; + + memcpy(tbuf, buf, 5); + tbuf[5] = 0; + fade = atoi(tbuf); + buf += 5; + } + + id3->artist = p; + buf[31] = 0; + p = iso_decode(buf, p, 0, 32); + + if (length==0) { + length=3*60*1000; /* 3 minutes */ + fade=5*1000; /* 5 seconds */ + } + + id3->length = length+fade; + + return true; +} |