Chris@0
|
1 %{
|
Chris@0
|
2 /*
|
Chris@0
|
3 * libid3tag - ID3 tag manipulation library
|
Chris@0
|
4 * Copyright (C) 2000-2004 Underbit Technologies, Inc.
|
Chris@0
|
5 *
|
Chris@0
|
6 * This program is free software; you can redistribute it and/or modify
|
Chris@0
|
7 * it under the terms of the GNU General Public License as published by
|
Chris@0
|
8 * the Free Software Foundation; either version 2 of the License, or
|
Chris@0
|
9 * (at your option) any later version.
|
Chris@0
|
10 *
|
Chris@0
|
11 * This program is distributed in the hope that it will be useful,
|
Chris@0
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Chris@0
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Chris@0
|
14 * GNU General Public License for more details.
|
Chris@0
|
15 *
|
Chris@0
|
16 * You should have received a copy of the GNU General Public License
|
Chris@0
|
17 * along with this program; if not, write to the Free Software
|
Chris@0
|
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Chris@0
|
19 *
|
Chris@0
|
20 * $Id: compat.gperf,v 1.11 2004/01/23 09:41:32 rob Exp $
|
Chris@0
|
21 */
|
Chris@0
|
22
|
Chris@0
|
23 # ifdef HAVE_CONFIG_H
|
Chris@0
|
24 # include "config.h"
|
Chris@0
|
25 # endif
|
Chris@0
|
26
|
Chris@0
|
27 # include "global.h"
|
Chris@0
|
28
|
Chris@0
|
29 # include <stdlib.h>
|
Chris@0
|
30 # include <string.h>
|
Chris@0
|
31
|
Chris@0
|
32 # ifdef HAVE_ASSERT_H
|
Chris@0
|
33 # include <assert.h>
|
Chris@0
|
34 # endif
|
Chris@0
|
35
|
Chris@0
|
36 # include "id3tag.h"
|
Chris@0
|
37 # include "compat.h"
|
Chris@0
|
38 # include "frame.h"
|
Chris@0
|
39 # include "field.h"
|
Chris@0
|
40 # include "parse.h"
|
Chris@0
|
41 # include "ucs4.h"
|
Chris@0
|
42
|
Chris@0
|
43 # define EQ(id) #id, 0
|
Chris@0
|
44 # define OBSOLETE 0, 0
|
Chris@0
|
45 # define TX(id) #id, translate_##id
|
Chris@0
|
46
|
Chris@0
|
47 static id3_compat_func_t translate_TCON;
|
Chris@0
|
48 %}
|
Chris@0
|
49 struct id3_compat;
|
Chris@0
|
50 %%
|
Chris@0
|
51 #
|
Chris@0
|
52 # ID3v2.2 and ID3v2.3 frames
|
Chris@0
|
53 #
|
Chris@0
|
54 # Only obsolete frames or frames with an equivalent ID3v2.4 frame ID are
|
Chris@0
|
55 # listed here. If a frame ID is not listed, it is assumed that the same
|
Chris@0
|
56 # frame ID is itself the equivalent ID3v2.4 frame ID.
|
Chris@0
|
57 #
|
Chris@0
|
58 # This list may also include frames with new content interpretations; the
|
Chris@0
|
59 # translation function will rewrite the contents to comply with ID3v2.4.
|
Chris@0
|
60 #
|
Chris@0
|
61 BUF, EQ(RBUF) /* Recommended buffer size */
|
Chris@0
|
62 CNT, EQ(PCNT) /* Play counter */
|
Chris@0
|
63 COM, EQ(COMM) /* Comments */
|
Chris@0
|
64 CRA, EQ(AENC) /* Audio encryption */
|
Chris@0
|
65 CRM, OBSOLETE /* Encrypted meta frame [obsolete] */
|
Chris@0
|
66 EQU, OBSOLETE /* Equalization [obsolete] */
|
Chris@0
|
67 EQUA, OBSOLETE /* Equalization [obsolete] */
|
Chris@0
|
68 ETC, EQ(ETCO) /* Event timing codes */
|
Chris@0
|
69 GEO, EQ(GEOB) /* General encapsulated object */
|
Chris@0
|
70 IPL, EQ(TIPL) /* Involved people list */
|
Chris@0
|
71 IPLS, EQ(TIPL) /* Involved people list */
|
Chris@0
|
72 LNK, EQ(LINK) /* Linked information */
|
Chris@0
|
73 MCI, EQ(MCDI) /* Music CD identifier */
|
Chris@0
|
74 MLL, EQ(MLLT) /* MPEG location lookup table */
|
Chris@0
|
75 PIC, EQ(APIC) /* Attached picture */
|
Chris@0
|
76 POP, EQ(POPM) /* Popularimeter */
|
Chris@0
|
77 REV, EQ(RVRB) /* Reverb */
|
Chris@0
|
78 RVA, OBSOLETE /* Relative volume adjustment [obsolete] */
|
Chris@0
|
79 RVAD, OBSOLETE /* Relative volume adjustment [obsolete] */
|
Chris@0
|
80 SLT, EQ(SYLT) /* Synchronised lyric/text */
|
Chris@0
|
81 STC, EQ(SYTC) /* Synchronised tempo codes */
|
Chris@0
|
82 TAL, EQ(TALB) /* Album/movie/show title */
|
Chris@0
|
83 TBP, EQ(TBPM) /* BPM (beats per minute) */
|
Chris@0
|
84 TCM, EQ(TCOM) /* Composer */
|
Chris@0
|
85 TCO, TX(TCON) /* Content type */
|
Chris@0
|
86 TCON, TX(TCON) /* Content type */
|
Chris@0
|
87 TCR, EQ(TCOP) /* Copyright message */
|
Chris@0
|
88 TDA, OBSOLETE /* Date [obsolete] */
|
Chris@0
|
89 TDAT, OBSOLETE /* Date [obsolete] */
|
Chris@0
|
90 TDY, EQ(TDLY) /* Playlist delay */
|
Chris@0
|
91 TEN, EQ(TENC) /* Encoded by */
|
Chris@0
|
92 TFT, EQ(TFLT) /* File type */
|
Chris@0
|
93 TIM, OBSOLETE /* Time [obsolete] */
|
Chris@0
|
94 TIME, OBSOLETE /* Time [obsolete] */
|
Chris@0
|
95 TKE, EQ(TKEY) /* Initial key */
|
Chris@0
|
96 TLA, EQ(TLAN) /* Language(s) */
|
Chris@0
|
97 TLE, EQ(TLEN) /* Length */
|
Chris@0
|
98 TMT, EQ(TMED) /* Media type */
|
Chris@0
|
99 TOA, EQ(TOPE) /* Original artist(s)/performer(s) */
|
Chris@0
|
100 TOF, EQ(TOFN) /* Original filename */
|
Chris@0
|
101 TOL, EQ(TOLY) /* Original lyricist(s)/text writer(s) */
|
Chris@0
|
102 TOR, EQ(TDOR) /* Original release year [obsolete] */
|
Chris@0
|
103 TORY, EQ(TDOR) /* Original release year [obsolete] */
|
Chris@0
|
104 TOT, EQ(TOAL) /* Original album/movie/show title */
|
Chris@0
|
105 TP1, EQ(TPE1) /* Lead performer(s)/soloist(s) */
|
Chris@0
|
106 TP2, EQ(TPE2) /* Band/orchestra/accompaniment */
|
Chris@0
|
107 TP3, EQ(TPE3) /* Conductor/performer refinement */
|
Chris@0
|
108 TP4, EQ(TPE4) /* Interpreted, remixed, or otherwise modified by */
|
Chris@0
|
109 TPA, EQ(TPOS) /* Part of a set */
|
Chris@0
|
110 TPB, EQ(TPUB) /* Publisher */
|
Chris@0
|
111 TRC, EQ(TSRC) /* ISRC (international standard recording code) */
|
Chris@0
|
112 TRD, OBSOLETE /* Recording dates [obsolete] */
|
Chris@0
|
113 TRDA, OBSOLETE /* Recording dates [obsolete] */
|
Chris@0
|
114 TRK, EQ(TRCK) /* Track number/position in set */
|
Chris@0
|
115 TSI, OBSOLETE /* Size [obsolete] */
|
Chris@0
|
116 TSIZ, OBSOLETE /* Size [obsolete] */
|
Chris@0
|
117 TSS, EQ(TSSE) /* Software/hardware and settings used for encoding */
|
Chris@0
|
118 TT1, EQ(TIT1) /* Content group description */
|
Chris@0
|
119 TT2, EQ(TIT2) /* Title/songname/content description */
|
Chris@0
|
120 TT3, EQ(TIT3) /* Subtitle/description refinement */
|
Chris@0
|
121 TXT, EQ(TEXT) /* Lyricist/text writer */
|
Chris@0
|
122 TXX, EQ(TXXX) /* User defined text information frame */
|
Chris@0
|
123 TYE, OBSOLETE /* Year [obsolete] */
|
Chris@0
|
124 TYER, OBSOLETE /* Year [obsolete] */
|
Chris@0
|
125 UFI, EQ(UFID) /* Unique file identifier */
|
Chris@0
|
126 ULT, EQ(USLT) /* Unsynchronised lyric/text transcription */
|
Chris@0
|
127 WAF, EQ(WOAF) /* Official audio file webpage */
|
Chris@0
|
128 WAR, EQ(WOAR) /* Official artist/performer webpage */
|
Chris@0
|
129 WAS, EQ(WOAS) /* Official audio source webpage */
|
Chris@0
|
130 WCM, EQ(WCOM) /* Commercial information */
|
Chris@0
|
131 WCP, EQ(WCOP) /* Copyright/legal information */
|
Chris@0
|
132 WPB, EQ(WPUB) /* Publishers official webpage */
|
Chris@0
|
133 WXX, EQ(WXXX) /* User defined URL link frame */
|
Chris@0
|
134 %%
|
Chris@0
|
135
|
Chris@0
|
136 static
|
Chris@0
|
137 int translate_TCON(struct id3_frame *frame, char const *oldid,
|
Chris@0
|
138 id3_byte_t const *data, id3_length_t length)
|
Chris@0
|
139 {
|
Chris@0
|
140 id3_byte_t const *end;
|
Chris@0
|
141 enum id3_field_textencoding encoding;
|
Chris@0
|
142 id3_ucs4_t *string = 0, *ptr, *endptr;
|
Chris@0
|
143 int result = 0;
|
Chris@0
|
144
|
Chris@0
|
145 /* translate old TCON syntax into multiple strings */
|
Chris@0
|
146
|
Chris@0
|
147 assert(frame->nfields == 2);
|
Chris@0
|
148
|
Chris@0
|
149 encoding = ID3_FIELD_TEXTENCODING_ISO_8859_1;
|
Chris@0
|
150
|
Chris@0
|
151 end = data + length;
|
Chris@0
|
152
|
Chris@0
|
153 if (id3_field_parse(&frame->fields[0], &data, end - data, &encoding) == -1)
|
Chris@0
|
154 goto fail;
|
Chris@0
|
155
|
Chris@0
|
156 string = id3_parse_string(&data, end - data, encoding, 0);
|
Chris@0
|
157 if (string == 0)
|
Chris@0
|
158 goto fail;
|
Chris@0
|
159
|
Chris@0
|
160 ptr = string;
|
Chris@0
|
161 while (*ptr == '(') {
|
Chris@0
|
162 if (*++ptr == '(')
|
Chris@0
|
163 break;
|
Chris@0
|
164
|
Chris@0
|
165 endptr = ptr;
|
Chris@0
|
166 while (*endptr && *endptr != ')')
|
Chris@0
|
167 ++endptr;
|
Chris@0
|
168
|
Chris@0
|
169 if (*endptr)
|
Chris@0
|
170 *endptr++ = 0;
|
Chris@0
|
171
|
Chris@0
|
172 if (id3_field_addstring(&frame->fields[1], ptr) == -1)
|
Chris@0
|
173 goto fail;
|
Chris@0
|
174
|
Chris@0
|
175 ptr = endptr;
|
Chris@0
|
176 }
|
Chris@0
|
177
|
Chris@0
|
178 if (*ptr && id3_field_addstring(&frame->fields[1], ptr) == -1)
|
Chris@0
|
179 goto fail;
|
Chris@0
|
180
|
Chris@0
|
181 if (0) {
|
Chris@0
|
182 fail:
|
Chris@0
|
183 result = -1;
|
Chris@0
|
184 }
|
Chris@0
|
185
|
Chris@0
|
186 if (string)
|
Chris@0
|
187 free(string);
|
Chris@0
|
188
|
Chris@0
|
189 return result;
|
Chris@0
|
190 }
|
Chris@0
|
191
|
Chris@0
|
192 /*
|
Chris@0
|
193 * NAME: compat->fixup()
|
Chris@0
|
194 * DESCRIPTION: finish compatibility translations
|
Chris@0
|
195 */
|
Chris@0
|
196 int id3_compat_fixup(struct id3_tag *tag)
|
Chris@0
|
197 {
|
Chris@0
|
198 struct id3_frame *frame;
|
Chris@0
|
199 unsigned int index;
|
Chris@0
|
200 id3_ucs4_t timestamp[17] = { 0 };
|
Chris@0
|
201 int result = 0;
|
Chris@0
|
202
|
Chris@0
|
203 /* create a TDRC frame from obsolete TYER/TDAT/TIME frames */
|
Chris@0
|
204
|
Chris@0
|
205 /*
|
Chris@0
|
206 * TYE/TYER: YYYY
|
Chris@0
|
207 * TDA/TDAT: DDMM
|
Chris@0
|
208 * TIM/TIME: HHMM
|
Chris@0
|
209 *
|
Chris@0
|
210 * TDRC: yyyy-MM-ddTHH:mm
|
Chris@0
|
211 */
|
Chris@0
|
212
|
Chris@0
|
213 index = 0;
|
Chris@0
|
214 while ((frame = id3_tag_findframe(tag, ID3_FRAME_OBSOLETE, index++))) {
|
Chris@0
|
215 char const *id;
|
Chris@0
|
216 id3_byte_t const *data, *end;
|
Chris@0
|
217 id3_length_t length;
|
Chris@0
|
218 enum id3_field_textencoding encoding;
|
Chris@0
|
219 id3_ucs4_t *string;
|
Chris@0
|
220
|
Chris@0
|
221 id = id3_field_getframeid(&frame->fields[0]);
|
Chris@0
|
222 assert(id);
|
Chris@0
|
223
|
Chris@0
|
224 if (strcmp(id, "TYER") != 0 && strcmp(id, "YTYE") != 0 &&
|
Chris@0
|
225 strcmp(id, "TDAT") != 0 && strcmp(id, "YTDA") != 0 &&
|
Chris@0
|
226 strcmp(id, "TIME") != 0 && strcmp(id, "YTIM") != 0)
|
Chris@0
|
227 continue;
|
Chris@0
|
228
|
Chris@0
|
229 data = id3_field_getbinarydata(&frame->fields[1], &length);
|
Chris@0
|
230 assert(data);
|
Chris@0
|
231
|
Chris@0
|
232 if (length < 1)
|
Chris@0
|
233 continue;
|
Chris@0
|
234
|
Chris@0
|
235 end = data + length;
|
Chris@0
|
236
|
Chris@0
|
237 encoding = id3_parse_uint(&data, 1);
|
Chris@0
|
238 string = id3_parse_string(&data, end - data, encoding, 0);
|
Chris@0
|
239
|
Chris@0
|
240 if (id3_ucs4_length(string) < 4) {
|
Chris@0
|
241 free(string);
|
Chris@0
|
242 continue;
|
Chris@0
|
243 }
|
Chris@0
|
244
|
Chris@0
|
245 if (strcmp(id, "TYER") == 0 ||
|
Chris@0
|
246 strcmp(id, "YTYE") == 0) {
|
Chris@0
|
247 timestamp[0] = string[0];
|
Chris@0
|
248 timestamp[1] = string[1];
|
Chris@0
|
249 timestamp[2] = string[2];
|
Chris@0
|
250 timestamp[3] = string[3];
|
Chris@0
|
251 }
|
Chris@0
|
252 else if (strcmp(id, "TDAT") == 0 ||
|
Chris@0
|
253 strcmp(id, "YTDA") == 0) {
|
Chris@0
|
254 timestamp[4] = '-';
|
Chris@0
|
255 timestamp[5] = string[2];
|
Chris@0
|
256 timestamp[6] = string[3];
|
Chris@0
|
257 timestamp[7] = '-';
|
Chris@0
|
258 timestamp[8] = string[0];
|
Chris@0
|
259 timestamp[9] = string[1];
|
Chris@0
|
260 }
|
Chris@0
|
261 else { /* TIME or YTIM */
|
Chris@0
|
262 timestamp[10] = 'T';
|
Chris@0
|
263 timestamp[11] = string[0];
|
Chris@0
|
264 timestamp[12] = string[1];
|
Chris@0
|
265 timestamp[13] = ':';
|
Chris@0
|
266 timestamp[14] = string[2];
|
Chris@0
|
267 timestamp[15] = string[3];
|
Chris@0
|
268 }
|
Chris@0
|
269
|
Chris@0
|
270 free(string);
|
Chris@0
|
271 }
|
Chris@0
|
272
|
Chris@0
|
273 if (timestamp[0]) {
|
Chris@0
|
274 id3_ucs4_t *strings;
|
Chris@0
|
275
|
Chris@0
|
276 frame = id3_frame_new("TDRC");
|
Chris@0
|
277 if (frame == 0)
|
Chris@0
|
278 goto fail;
|
Chris@0
|
279
|
Chris@0
|
280 strings = timestamp;
|
Chris@0
|
281
|
Chris@0
|
282 if (id3_field_settextencoding(&frame->fields[0],
|
Chris@0
|
283 ID3_FIELD_TEXTENCODING_ISO_8859_1) == -1 ||
|
Chris@0
|
284 id3_field_setstrings(&frame->fields[1], 1, &strings) == -1 ||
|
Chris@0
|
285 id3_tag_attachframe(tag, frame) == -1) {
|
Chris@0
|
286 id3_frame_delete(frame);
|
Chris@0
|
287 goto fail;
|
Chris@0
|
288 }
|
Chris@0
|
289 }
|
Chris@0
|
290
|
Chris@0
|
291 if (0) {
|
Chris@0
|
292 fail:
|
Chris@0
|
293 result = -1;
|
Chris@0
|
294 }
|
Chris@0
|
295
|
Chris@0
|
296 return result;
|
Chris@0
|
297 }
|