aboutsummaryrefslogtreecommitdiff
path: root/libid3tag
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2011-07-25 01:04:56 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2011-07-25 01:07:48 +0300
commit53fe6eef6d572f96cde8592dab13ffa63c2c433a (patch)
treebfa9ff565c7e77adaa30d11f358f9252964276b9 /libid3tag
parent6db300c686c28f05562930b5ff58487f625e4a01 (diff)
downloadidest-53fe6eef6d572f96cde8592dab13ffa63c2c433a.tar.gz
idest-53fe6eef6d572f96cde8592dab13ffa63c2c433a.tar.bz2
Convert v2.2 PIC to v2.4 APIC
* libid3tag/compat.gperf (translate_APIC): New function. Use it to translate PIC to APIC.
Diffstat (limited to 'libid3tag')
-rw-r--r--libid3tag/compat.gperf97
1 files changed, 95 insertions, 2 deletions
diff --git a/libid3tag/compat.gperf b/libid3tag/compat.gperf
index 6fa1d4e..71e28d0 100644
--- a/libid3tag/compat.gperf
+++ b/libid3tag/compat.gperf
@@ -28,6 +28,7 @@
28 28
29# include <stdlib.h> 29# include <stdlib.h>
30# include <string.h> 30# include <string.h>
31# include <ctype.h>
31 32
32# ifdef HAVE_ASSERT_H 33# ifdef HAVE_ASSERT_H
33# include <assert.h> 34# include <assert.h>
@@ -44,7 +45,7 @@
44# define OBSOLETE 0, 0 45# define OBSOLETE 0, 0
45# define TX(id) #id, translate_##id 46# define TX(id) #id, translate_##id
46 47
47static id3_compat_func_t translate_TCON; 48static id3_compat_func_t translate_TCON, translate_APIC;
48%} 49%}
49struct id3_compat; 50struct id3_compat;
50%% 51%%
@@ -72,7 +73,7 @@ IPLS, EQ(TIPL) /* Involved people list */
72LNK, EQ(LINK) /* Linked information */ 73LNK, EQ(LINK) /* Linked information */
73MCI, EQ(MCDI) /* Music CD identifier */ 74MCI, EQ(MCDI) /* Music CD identifier */
74MLL, EQ(MLLT) /* MPEG location lookup table */ 75MLL, EQ(MLLT) /* MPEG location lookup table */
75PIC, EQ(APIC) /* Attached picture */ 76PIC, TX(APIC) /* Attached picture */
76POP, EQ(POPM) /* Popularimeter */ 77POP, EQ(POPM) /* Popularimeter */
77REV, EQ(RVRB) /* Reverb */ 78REV, EQ(RVRB) /* Reverb */
78RVA, OBSOLETE /* Relative volume adjustment [obsolete] */ 79RVA, OBSOLETE /* Relative volume adjustment [obsolete] */
@@ -190,6 +191,98 @@ translate_TCON(struct id3_frame *frame, char const *oldid,
190 return result; 191 return result;
191} 192}
192 193
194static const char *
195translate_subtype(const id3_byte_t *in)
196{
197 static char lcin[4];
198 static struct inout {
199 char *in;
200 char *out;
201 } subtype_trans[] = {
202 { "jpg", "jpeg" },
203 { NULL }
204 };
205 struct inout *p;
206
207 lcin[0] = tolower(in[0]);
208 lcin[1] = tolower(in[1]);
209 lcin[2] = tolower(in[2]);
210 lcin[3] = 0;
211 for (p = subtype_trans; p->in; p++)
212 if (memcmp(p->in, in, 3) == 0)
213 return p->out;
214 return lcin;
215}
216
217static id3_latin1_t *
218str_to_mime_type(const id3_byte_t *str)
219{
220 const char *subtype = translate_subtype(str);
221 static const char prefix[] = "image/";
222 char *ret;
223
224 ret = malloc(sizeof(prefix) + strlen(subtype));
225 if (ret)
226 strcat(strcpy(ret, prefix), subtype);
227 return (id3_latin1_t *) ret;
228}
229
230static int
231translate_APIC(struct id3_frame *frame, char const *oldid,
232 id3_byte_t const *data, id3_length_t length)
233{
234 id3_byte_t const *end;
235 enum id3_field_textencoding encoding =
236 ID3_FIELD_TEXTENCODING_ISO_8859_1;
237 int rc = 0;
238
239 /* translate old PIC into APIC */
240
241 assert(frame->nfields == 5);
242
243 end = data + length;
244
245 do {
246 /* Encoding */
247 if ((rc = id3_field_parse(&frame->fields[0], &data,
248 end - data, &encoding)) == -1)
249 break;
250
251 /* MIME type: a 3-byte string in v2.2, as pointed out
252 in https://bugs.kde.org/show_bug.cgi?id=167786#c2 */
253 if ((end - data) < 3) {
254 rc = -1;
255 break;
256 }
257 id3_field_finish(&frame->fields[1]);
258 frame->fields[1].latin1.ptr = str_to_mime_type(data);
259 if (!frame->fields[1].latin1.ptr) {
260 rc = -1;
261 break;
262 }
263 data += 3;
264
265 /* Picture type */
266 if ((rc = id3_field_parse(&frame->fields[2], &data,
267 end - data, &encoding)) == -1)
268 break;
269 /* Description */
270 if ((rc = id3_field_parse(&frame->fields[3], &data,
271 end - data, &encoding)) == -1)
272 break;
273 /* Picture date */
274 if ((rc = id3_field_parse(&frame->fields[4], &data,
275 end - data, &encoding)) == -1)
276 break;
277 } while (0);
278
279 if (rc) {
280 /* FIXME: cleanup */
281 ;
282 }
283 return rc;
284}
285
193/* 286/*
194 * NAME: compat->fixup() 287 * NAME: compat->fixup()
195 * DESCRIPTION: finish compatibility translations 288 * DESCRIPTION: finish compatibility translations

Return to:

Send suggestions and report system problems to the System administrator.