Remove executable property that somehow got set
[kugel-rb.git] / apps / metadata / spc.c
blob786c678c4c6099ff39a1743c57a858846e0be7b3
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2005 Dave Chapman
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
21 #include <stdio.h>
22 #include <string.h>
23 #include <stdlib.h>
24 #include <ctype.h>
25 #include <inttypes.h>
27 #include "system.h"
28 #include "metadata.h"
29 #include "metadata_common.h"
30 #include "metadata_parsers.h"
31 #include "debug.h"
32 #include "rbunicode.h"
34 bool get_spc_metadata(int fd, struct mp3entry* id3)
36 /* Use the trackname part of the id3 structure as a temporary buffer */
37 unsigned char * buf = (unsigned char *)id3->path;
38 int read_bytes;
39 char * p;
41 unsigned long length;
42 unsigned long fade;
43 bool isbinary = true;
44 int i;
46 /* try to get the ID666 tag */
47 if ((lseek(fd, 0x2e, SEEK_SET) < 0)
48 || ((read_bytes = read(fd, buf, 0xD2)) < 0xD2))
50 DEBUGF("lseek or read failed\n");
51 return false;
54 p = id3->id3v2buf;
56 id3->title = p;
57 buf[31] = 0;
58 p = iso_decode(buf, p, 0, 32);
59 buf += 32;
61 id3->album = p;
62 buf[31] = 0;
63 p = iso_decode(buf, p, 0, 32);
64 buf += 48;
66 id3->comment = p;
67 buf[31] = 0;
68 p = iso_decode(buf, p, 0, 32);
69 buf += 32;
71 /* Date check */
72 if(buf[2] == '/' && buf[5] == '/')
73 isbinary = false;
75 /* Reserved bytes check */
76 if(buf[0xD2 - 0x2E - 112] >= '0' &&
77 buf[0xD2 - 0x2E - 112] <= '9' &&
78 buf[0xD3 - 0x2E - 112] == 0x00)
79 isbinary = false;
81 /* is length & fade only digits? */
82 for (i=0;i<8 && (
83 (buf[0xA9 - 0x2E - 112+i]>='0'&&buf[0xA9 - 0x2E - 112+i]<='9') ||
84 buf[0xA9 - 0x2E - 112+i]=='\0');
85 i++);
86 if (i==8) isbinary = false;
88 if(isbinary) {
89 id3->year = buf[0] | (buf[1]<<8);
90 buf += 11;
92 length = (buf[0] | (buf[1]<<8) | (buf[2]<<16)) * 1000;
93 buf += 3;
95 fade = (buf[0] | (buf[1]<<8) | (buf[2]<<16) | (buf[3]<<24));
96 buf += 4;
97 } else {
98 char tbuf[6];
100 buf += 6;
101 buf[4] = 0;
102 id3->year = atoi(buf);
103 buf += 5;
105 memcpy(tbuf, buf, 3);
106 tbuf[3] = 0;
107 length = atoi(tbuf) * 1000;
108 buf += 3;
110 memcpy(tbuf, buf, 5);
111 tbuf[5] = 0;
112 fade = atoi(tbuf);
113 buf += 5;
116 id3->artist = p;
117 buf[31] = 0;
118 p = iso_decode(buf, p, 0, 32);
120 if (length==0) {
121 length=3*60*1000; /* 3 minutes */
122 fade=5*1000; /* 5 seconds */
125 id3->length = length+fade;
127 return true;