summaryrefslogtreecommitdiff
path: root/apps/metadata/spc.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/metadata/spc.c')
-rw-r--r--apps/metadata/spc.c126
1 files changed, 126 insertions, 0 deletions
diff --git a/apps/metadata/spc.c b/apps/metadata/spc.c
new file mode 100644
index 0000000000..8d85518714
--- /dev/null
+++ b/apps/metadata/spc.c
@@ -0,0 +1,126 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2005 Dave Chapman
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#include <stdio.h>
20#include <string.h>
21#include <stdlib.h>
22#include <ctype.h>
23#include <inttypes.h>
24
25#include "system.h"
26#include "id3.h"
27#include "metadata_common.h"
28#include "debug.h"
29#include "atoi.h"
30#include "rbunicode.h"
31
32bool get_spc_metadata(int fd, struct mp3entry* id3)
33{
34 /* Use the trackname part of the id3 structure as a temporary buffer */
35 unsigned char * buf = (unsigned char *)id3->path;
36 int read_bytes;
37 char * p;
38
39 unsigned long length;
40 unsigned long fade;
41 bool isbinary = true;
42 int i;
43
44 /* try to get the ID666 tag */
45 if ((lseek(fd, 0x2e, SEEK_SET) < 0)
46 || ((read_bytes = read(fd, buf, 0xD2)) < 0xD2))
47 {
48 DEBUGF("lseek or read failed\n");
49 return false;
50 }
51
52 p = id3->id3v2buf;
53
54 id3->title = p;
55 buf[31] = 0;
56 p = iso_decode(buf, p, 0, 32);
57 buf += 32;
58
59 id3->album = p;
60 buf[31] = 0;
61 p = iso_decode(buf, p, 0, 32);
62 buf += 48;
63
64 id3->comment = p;
65 buf[31] = 0;
66 p = iso_decode(buf, p, 0, 32);
67 buf += 32;
68
69 /* Date check */
70 if(buf[2] == '/' && buf[5] == '/')
71 isbinary = false;
72
73 /* Reserved bytes check */
74 if(buf[0xD2 - 0x2E - 112] >= '0' &&
75 buf[0xD2 - 0x2E - 112] <= '9' &&
76 buf[0xD3 - 0x2E - 112] == 0x00)
77 isbinary = false;
78
79 /* is length & fade only digits? */
80 for (i=0;i<8 && (
81 (buf[0xA9 - 0x2E - 112+i]>='0'&&buf[0xA9 - 0x2E - 112+i]<='9') ||
82 buf[0xA9 - 0x2E - 112+i]=='\0');
83 i++);
84 if (i==8) isbinary = false;
85
86 if(isbinary) {
87 id3->year = buf[0] | (buf[1]<<8);
88 buf += 11;
89
90 length = (buf[0] | (buf[1]<<8) | (buf[2]<<16)) * 1000;
91 buf += 3;
92
93 fade = (buf[0] | (buf[1]<<8) | (buf[2]<<16) | (buf[3]<<24));
94 buf += 4;
95 } else {
96 char tbuf[6];
97
98 buf += 6;
99 buf[4] = 0;
100 id3->year = atoi(buf);
101 buf += 5;
102
103 memcpy(tbuf, buf, 3);
104 tbuf[3] = 0;
105 length = atoi(tbuf) * 1000;
106 buf += 3;
107
108 memcpy(tbuf, buf, 5);
109 tbuf[5] = 0;
110 fade = atoi(tbuf);
111 buf += 5;
112 }
113
114 id3->artist = p;
115 buf[31] = 0;
116 p = iso_decode(buf, p, 0, 32);
117
118 if (length==0) {
119 length=3*60*1000; /* 3 minutes */
120 fade=5*1000; /* 5 seconds */
121 }
122
123 id3->length = length+fade;
124
125 return true;
126}