aboutsummaryrefslogtreecommitdiff
path: root/src/idop.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2009-03-15 23:10:01 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2009-03-15 23:10:01 +0200
commit3a27428194f866050472b0f7c7b9e55b19cec230 (patch)
tree0207e9f21036bcb1b2a7fe3edf11b9ad761e2768 /src/idop.c
parentf6c2e714cc84ad327cf661967cdb024f835dd1c1 (diff)
downloadidest-3a27428194f866050472b0f7c7b9e55b19cec230.tar.gz
idest-3a27428194f866050472b0f7c7b9e55b19cec230.tar.bz2
Remove old v1 code. Add an option for converting tags to v1.
* libid3tag/file.c (SIZE_T_MAX): Rename to MALLOC_MAX. Use (size_t_max-1), due to a bug in glibc's malloc. (make_temp_file): Fix size calculation (memory overrun). (v2_write): data and/or length can be 0. (id3_file_update): Drop v2 header, if ID3_TAG_OPTION_NO_ID3V2 is set. * libid3tag/id3tag.h (ID3_TAG_OPTION_NO_ID3V2): New constant. * src/id3v1.c, src/id3v1.h: Remove. * src/id3v2.c: Rename to... * src/idop.c: ... this. (set_tags): Handle convert_version and version_option. * src/Makefile.am: Reflect the above. * src/cmdline.opt (--convert, -C): New option. * src/idest.h: Kick off id3v1.h. (convert_version, version_option): new externs. (set_id3v1, query_id3v1, del_id3v1) (set_id3v2, query_id3v2, del_id3v2): Remove. (set_tags, query_tags, del_tags): New prototypes. * src/main.c (convert_version): New variable. (query_id3): use all_frames to determine ed_list. (set_id3): Remove old v1 code. (main): Remove old v1 code.
Diffstat (limited to 'src/idop.c')
-rw-r--r--src/idop.c233
1 files changed, 233 insertions, 0 deletions
diff --git a/src/idop.c b/src/idop.c
new file mode 100644
index 0000000..76a5b0d
--- /dev/null
+++ b/src/idop.c
@@ -0,0 +1,233 @@
1/* This file is part of Idest.
2 Copyright (C) 2009 Sergey Poznyakoff
3
4 Idest is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3, or (at your option)
7 any later version.
8
9 Idest is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with Idest. If not, see <http://www.gnu.org/licenses/>. */
16
17#include "idest.h"
18
19void
20set_frame_value(struct id3_frame *frame, const char *value)
21{
22 union id3_field *field;
23 enum id3_field_textencoding encoding =
24 (latin1_option ? ID3_FIELD_TEXTENCODING_ISO_8859_1
25 : ID3_FIELD_TEXTENCODING_UTF_8);
26 id3_ucs4_t *ucs4;
27
28 switch (frame_id(frame->id)) {
29 case item_title:
30 case item_artist:
31 case item_album:
32 case item_year:
33 case item_track:
34 case item_genre:
35 field = id3_frame_field(frame, 0);
36 id3_field_settextencoding(field, encoding);
37
38 if (latin1_option)
39 ucs4 = id3_latin1_ucs4duplicate(
40 (const id3_latin1_t *) value);
41 else
42 ucs4 = id3_utf8_ucs4duplicate(
43 (const id3_utf8_t *)value);
44
45 field = id3_frame_field(frame, 1);
46 id3_field_setstrings(field, 1, &ucs4);
47 free(ucs4);
48 break;
49
50 case item_comment:
51 /* Field 0: Encoding */
52 field = id3_frame_field(frame, 0);
53 id3_field_settextencoding(field, encoding);
54 /* FIXME: Field 1: Language */
55 /* FIXME: Field 2: String */
56 /* Field 3: Comment */
57 field = id3_frame_field(frame, 3);
58 if (latin1_option)
59 ucs4 = id3_latin1_ucs4duplicate(
60 (const id3_latin1_t *) value);
61 else
62 ucs4 = id3_utf8_ucs4duplicate(
63 (const id3_utf8_t *)value);
64 id3_field_setfullstring(field, ucs4);
65 free(ucs4);
66 break;
67
68 default:
69 error(1, 0, "don't know how to set field %s", frame->id);
70 }
71}
72
73void
74set_tags(const char *name)
75{
76 struct id3_file *file;
77 struct id3_tag *tag;
78
79 file = id3_file_open(name, ID3_FILE_MODE_READWRITE);
80 if (!file)
81 error(1, errno, "cannot open file %s", name);
82 tag = id3_file_tag(file);
83 if (!tag)
84 abort(); /* FIXME */
85
86 if (ed_list) {
87 gl_list_iterator_t itr;
88 const void *p;
89
90 itr = gl_list_iterator(ed_list);
91 while (gl_list_iterator_next(&itr, &p, NULL)) {
92 const struct ed_item *item = p;
93 struct id3_frame *frame
94 = id3_tag_findframe(tag, item->id, 0);
95 if (!frame) {
96 frame = id3_frame_new(item->id);
97 if (id3_tag_attachframe(tag, frame))
98 error(1, 0, "cannot attach new frame");
99 }
100 set_frame_value(frame, item->v.value);
101 }
102 gl_list_iterator_free(&itr);
103 }
104
105 if (convert_version == 1) {
106 id3_tag_options(tag,
107 ID3_TAG_OPTION_NO_ID3V2,
108 ID3_TAG_OPTION_NO_ID3V2);
109 version_option = 1;
110 }
111
112 if (version_option == 1)
113 id3_tag_options(tag, ID3_TAG_OPTION_ID3V1, ID3_TAG_OPTION_ID3V1);
114
115 id3_file_update(file);
116 id3_file_close(file);
117}
118
119
120char *
121ucs4_cvt(id3_ucs4_t const *ucs4)
122{
123 if (latin1_option)
124 return (char*)id3_ucs4_latin1duplicate(ucs4);
125 else
126 return (char*)id3_ucs4_utf8duplicate(ucs4);
127}
128
129void
130add_stringlist(gl_list_t list, struct id3_frame *frame,
131 union id3_field *field)
132{
133 unsigned i, nstrings = id3_field_getnstrings(field);
134 for (i = 0; i < nstrings; i++) {
135 id3_ucs4_t const *ucs4;
136 char *str;
137
138 ucs4 = id3_field_getstrings(field, i);
139 if (!ucs4)
140 continue;
141 if (strcmp(frame->id, ID3_FRAME_GENRE) == 0)
142 ucs4 = id3_genre_name(ucs4);
143 str = ucs4_cvt(ucs4);
144 gl_list_add_last(list, str);
145 }
146}
147
148void
149add_field(gl_list_t list, struct id3_frame *frame, union id3_field *field)
150{
151 id3_ucs4_t const *ucs4;
152 char *str;
153
154 switch (id3_field_type(field)) {
155 case ID3_FIELD_TYPE_TEXTENCODING:
156 break;
157 case ID3_FIELD_TYPE_LATIN1:
158 case ID3_FIELD_TYPE_LATIN1FULL:
159 case ID3_FIELD_TYPE_LATIN1LIST:
160 break;
161 case ID3_FIELD_TYPE_STRING:
162 break;
163 case ID3_FIELD_TYPE_STRINGFULL:
164 ucs4 = id3_field_getfullstring(field);
165 str = ucs4_cvt(ucs4);
166 gl_list_add_last(list, str);
167 break;
168 case ID3_FIELD_TYPE_STRINGLIST:
169 add_stringlist(list, frame, field);
170 break;
171 case ID3_FIELD_TYPE_LANGUAGE:
172 case ID3_FIELD_TYPE_FRAMEID:
173 case ID3_FIELD_TYPE_DATE:
174 case ID3_FIELD_TYPE_INT8:
175 case ID3_FIELD_TYPE_INT16:
176 case ID3_FIELD_TYPE_INT24:
177 case ID3_FIELD_TYPE_INT32:
178 case ID3_FIELD_TYPE_INT32PLUS:
179 case ID3_FIELD_TYPE_BINARYDATA:;
180 }
181}
182
183gl_list_t
184frame_to_list(struct id3_frame *frame)
185{
186 gl_list_t list;
187 unsigned i, j, nstrings;
188 union id3_field *field;
189
190 list = new_string_list(true);
191 for (i = 0; field = id3_frame_field(frame, i); i++)
192 add_field(list, frame, field);
193 return list;
194}
195
196static void
197show_tags(struct id3_tag *tag)
198{
199 struct id3_frame *frame;
200 unsigned i;
201
202 for (i = 0; frame = id3_tag_findframe(tag, NULL, i); i++) {
203 gl_list_t list = frame_to_list(frame);
204 if (gl_list_size(list) > 0)
205 ed_list_add_item(frame->id, list);
206 else
207 gl_list_free(list);
208 }
209 ed_list_print();
210 ed_list_clear();
211}
212
213void
214query_tags(const char *name)
215{
216 struct id3_file *file;
217 struct id3_tag *tag;
218
219 file = id3_file_open(name, ID3_FILE_MODE_READONLY);
220 if (!file)
221 error(1, errno, "cannot open file %s", name);
222
223 tag = id3_file_tag(file);
224 if (tag)
225 show_tags(tag);
226
227 id3_file_close(file);
228}
229
230void
231del_id3v2(const char *name)
232{
233}

Return to:

Send suggestions and report system problems to the System administrator.