1 /*
2 * ID3v2 header writer
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include <stdint.h>
22 #include <string.h>
23
31
32 #define PADDING_BYTES 10
33
35 {
40 }
41
43 {
44 while (*str && *str < 128) str++;
45 return !*str;
46 }
47
50 {
52
56 } else
58
59 put(pb, str);
60 }
61
62 /**
63 * Write a text frame with one (normal frames) or two (TXXX frames) strings
64 * according to encoding (only UTF-8 or UTF-16+BOM supported).
65 * @return number of bytes written or a negative error code.
66 */
69 {
75
76 /* check if the strings are ASCII-only and use UTF16 only if
77 * they're not */
81
84 if (str2)
87
89 /* ID3v2.3 frame size is not synchsafe */
92 else
96
99 }
100
103 {
105 int i;
106
107 if (t->
key[0] !=
'T' || strlen(t->
key) != 4)
108 return -1;
110 for (i = 0; *table[i]; i++)
113 return -1;
114 }
115
117 {
120 const char *key, *
value;
121 char year[5] = {0}, day_month[5] = {0};
122 int i;
123
127 /* split date tag using "YYYY-MM-DD" format into year and month/day segments */
129 i = 0;
130 while (value[i] >= '0' && value[i] <= '9') i++;
131 if (value[i] == '0円' || value[i] == '-') {
134
135 if (value[i] == '-' &&
136 value[i+1] >= '0' && value[i+1] <= '1' &&
137 value[i+2] >= '0' && value[i+2] <= '9' &&
138 value[i+3] == '-' &&
139 value[i+4] >= '0' && value[i+4] <= '3' &&
140 value[i+5] >= '0' && value[i+5] <= '9' &&
141 (value[i+6] == '0円' || value[i+6] == ' ')) {
142 snprintf(day_month,
sizeof(day_month),
"%.2s%.2s", value + i + 4, value + i + 1);
144 }
145 } else
147 } else
149 }
151 *pm = dst;
152 }
153
155 const char *magic)
156 {
158
162
163 /* reserve space for size */
166 }
167
170 {
173
179
183 continue;
184 }
188 continue;
189 }
190
191 /* unknown tag, write as TXXX frame */
195 }
196
197 return 0;
198 }
199
201 {
208
210 goto fail;
211
214
221
223 goto fail;
224
227
232
233 fail:
234 if (dyn_bc && !dyn_buf)
237
239 }
240
242 {
246
249
253 }
254
255 return 0;
256 }
257
259 {
262
266 const char *mimetype = NULL, *desc = "";
270
271 /* get the mimetype*/
274 mimetype = mime->
str;
275 break;
276 }
277 mime++;
278 }
279 if (!mimetype) {
281 "write an attached picture.\n", st->
index);
283 }
284
285 /* get the picture type */
289 type = i;
290 break;
291 }
292 }
293
294 /* get the description */
297
298 /* use UTF16 only for non-ASCII strings */
301
302 /* start writing */
305
312
316 else
321
323
324 return 0;
325 }
326
328 {
329 int64_t cur_pos;
330
331 /* adding an arbitrary amount of padding bytes at the end of the
332 * ID3 metadata fixes cover art display for some software (iTunes,
333 * Traktor, Serato, Torq) */
336
341 }
342
344 const char *magic)
345 {
348
353
354 return 0;
355 }