annotate src/madplug/tuple.c @ 2203:13b8ab116b69

removed debugging stuff. some notes added
author Eugene Zagidullin <e.asphyx@gmail.com>
date Mon, 03 Dec 2007 02:10:29 +0300
parents f76e846d53d9
children 9a869d4bb0d3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
1 /*
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
2 * mad plugin for audacious
2201
df520f828dcf Say goodbye to custom fileinfo dialog in madplug
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2050
diff changeset
3 * Copyright (C) 2005-2007 William Pitcock, Yoshiki Yazawa, Eugene Zagidullin
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
4 *
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
5 * Portions derived from xmms-mad:
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
6 * Copyright (C) 2001-2002 Sam Clegg - See COPYING
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
7 *
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
8 * This program is free software; you can redistribute it and/or modify
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
10 * the Free Software Foundation; under version 2 of the License.
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
11 *
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful,
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
15 * GNU General Public License for more details.
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
16 *
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
17 * You should have received a copy of the GNU General Public License
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
18 * along with this program; if not, write to the Free Software
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
20 */
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
21
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
22 #include "config.h"
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
23
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
24 #include "plugin.h"
2202
f76e846d53d9 updating TLEN frame returned
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2201
diff changeset
25 #include "tuple.h"
f76e846d53d9 updating TLEN frame returned
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2201
diff changeset
26 #include "input.h"
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
27
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
28 #include <math.h>
2201
df520f828dcf Say goodbye to custom fileinfo dialog in madplug
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2050
diff changeset
29 #include <string.h>
df520f828dcf Say goodbye to custom fileinfo dialog in madplug
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2050
diff changeset
30
df520f828dcf Say goodbye to custom fileinfo dialog in madplug
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2050
diff changeset
31 #include <glib.h>
df520f828dcf Say goodbye to custom fileinfo dialog in madplug
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2050
diff changeset
32 #include <glib/gprintf.h>
df520f828dcf Say goodbye to custom fileinfo dialog in madplug
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2050
diff changeset
33
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
34 #include <audacious/util.h>
2201
df520f828dcf Say goodbye to custom fileinfo dialog in madplug
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2050
diff changeset
35 #include <audacious/plugin.h>
df520f828dcf Say goodbye to custom fileinfo dialog in madplug
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2050
diff changeset
36 #include <audacious/id3tag.h>
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
37
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
38 /* yaz */
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
39 #include <langinfo.h>
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
40
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
41 static void
2201
df520f828dcf Say goodbye to custom fileinfo dialog in madplug
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2050
diff changeset
42 update_id3_frame(struct id3_tag *tag, const char *frame_name, const char *data, int sjis)
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
43 {
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
44 int res;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
45 struct id3_frame *frame;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
46 union id3_field *field;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
47 id3_ucs4_t *ucs4;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
48
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
49 if (data == NULL)
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
50 return;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
51
2203
13b8ab116b69 removed debugging stuff. some notes added
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2202
diff changeset
52 /* printf ("updating id3: %s: %s\n", frame_name, data);
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
53
2203
13b8ab116b69 removed debugging stuff. some notes added
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2202
diff changeset
54
13b8ab116b69 removed debugging stuff. some notes added
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2202
diff changeset
55 An empty string removes the frame altogether.
13b8ab116b69 removed debugging stuff. some notes added
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2202
diff changeset
56 */
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
57 if (strlen(data) == 0) {
629
ee59ad236eb6 [svn] - revise save tag callback
yaz
parents: 613
diff changeset
58 while ((frame = id3_tag_findframe(tag, frame_name, 0))) {
ee59ad236eb6 [svn] - revise save tag callback
yaz
parents: 613
diff changeset
59 #ifdef DEBUG
2201
df520f828dcf Say goodbye to custom fileinfo dialog in madplug
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2050
diff changeset
60 fprintf(stderr, "madplug: detachframe\n");
629
ee59ad236eb6 [svn] - revise save tag callback
yaz
parents: 613
diff changeset
61 #endif
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
62 id3_tag_detachframe(tag, frame);
629
ee59ad236eb6 [svn] - revise save tag callback
yaz
parents: 613
diff changeset
63 }
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
64 return;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
65 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
66
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
67 frame = id3_tag_findframe(tag, frame_name, 0);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
68 if (!frame) {
629
ee59ad236eb6 [svn] - revise save tag callback
yaz
parents: 613
diff changeset
69 #ifdef DEBUG
ee59ad236eb6 [svn] - revise save tag callback
yaz
parents: 613
diff changeset
70 printf("frame_new\n");
ee59ad236eb6 [svn] - revise save tag callback
yaz
parents: 613
diff changeset
71 #endif
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
72 frame = id3_frame_new(frame_name);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
73 id3_tag_attachframe(tag, frame);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
74 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
75
2203
13b8ab116b69 removed debugging stuff. some notes added
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2202
diff changeset
76 /* setup ucs4 string */
2201
df520f828dcf Say goodbye to custom fileinfo dialog in madplug
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2050
diff changeset
77 if(sjis) {
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
78 ucs4 = id3_latin1_ucs4duplicate((id3_latin1_t *) data);
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
79 }
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
80 else {
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
81 ucs4 = id3_utf8_ucs4duplicate((id3_utf8_t *) data);
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
82 }
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
83
2203
13b8ab116b69 removed debugging stuff. some notes added
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2202
diff changeset
84 /* set encoding */
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
85 field = id3_frame_field(frame, 0);
2201
df520f828dcf Say goodbye to custom fileinfo dialog in madplug
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2050
diff changeset
86 id3_field_settextencoding(field, sjis ? ID3_FIELD_TEXTENCODING_ISO_8859_1 :
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
87 ID3_FIELD_TEXTENCODING_UTF_8);
1302
1d3b02d1842b Guess... Yes, "i18n" stuff.
Stany HENRY <StrassBoy@gmail.com>
parents: 1264
diff changeset
88
2203
13b8ab116b69 removed debugging stuff. some notes added
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2202
diff changeset
89 /* setup genre code */
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
90 if (!strcmp(frame_name, ID3_FRAME_GENRE)) {
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
91 char *tmp;
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
92 int index = id3_genre_number(ucs4);
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
93 g_free(ucs4);
730
74a46ac77c97 [svn] - now fileinfo dialog shows "Unknown" instead of "Blues" if genre name isn't specified.
yaz
parents: 645
diff changeset
94
2203
13b8ab116b69 removed debugging stuff. some notes added
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2202
diff changeset
95 if(index == -1) { /* unknown genre. remove TCON frame. */
730
74a46ac77c97 [svn] - now fileinfo dialog shows "Unknown" instead of "Blues" if genre name isn't specified.
yaz
parents: 645
diff changeset
96 #ifdef DEBUG
2201
df520f828dcf Say goodbye to custom fileinfo dialog in madplug
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2050
diff changeset
97 fprintf(stderr, "madplug: remove genre frame\n");
730
74a46ac77c97 [svn] - now fileinfo dialog shows "Unknown" instead of "Blues" if genre name isn't specified.
yaz
parents: 645
diff changeset
98 #endif
74a46ac77c97 [svn] - now fileinfo dialog shows "Unknown" instead of "Blues" if genre name isn't specified.
yaz
parents: 645
diff changeset
99 id3_tag_detachframe(tag, frame);
74a46ac77c97 [svn] - now fileinfo dialog shows "Unknown" instead of "Blues" if genre name isn't specified.
yaz
parents: 645
diff changeset
100 }
2203
13b8ab116b69 removed debugging stuff. some notes added
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2202
diff changeset
101 else { /* meaningful genre */
730
74a46ac77c97 [svn] - now fileinfo dialog shows "Unknown" instead of "Blues" if genre name isn't specified.
yaz
parents: 645
diff changeset
102 tmp = g_strdup_printf("%d", index);
74a46ac77c97 [svn] - now fileinfo dialog shows "Unknown" instead of "Blues" if genre name isn't specified.
yaz
parents: 645
diff changeset
103 ucs4 = id3_latin1_ucs4duplicate((unsigned char *) tmp);
74a46ac77c97 [svn] - now fileinfo dialog shows "Unknown" instead of "Blues" if genre name isn't specified.
yaz
parents: 645
diff changeset
104 }
1302
1d3b02d1842b Guess... Yes, "i18n" stuff.
Stany HENRY <StrassBoy@gmail.com>
parents: 1264
diff changeset
105
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
106 }
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
107
2203
13b8ab116b69 removed debugging stuff. some notes added
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2202
diff changeset
108 /* write string */
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
109 if (!strcmp(frame_name, ID3_FRAME_COMMENT)) {
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
110 field = id3_frame_field(frame, 3);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
111 field->type = ID3_FIELD_TYPE_STRINGFULL;
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
112 res = id3_field_setfullstring(field, ucs4);
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
113 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
114 else {
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
115 field = id3_frame_field(frame, 1);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
116 field->type = ID3_FIELD_TYPE_STRINGLIST;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
117 res = id3_field_setstrings(field, 1, &ucs4);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
118 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
119
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
120 if (res != 0)
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
121 g_print("error setting id3 field: %s\n", frame_name);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
122 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
123
2201
df520f828dcf Say goodbye to custom fileinfo dialog in madplug
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2050
diff changeset
124 static void
df520f828dcf Say goodbye to custom fileinfo dialog in madplug
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2050
diff changeset
125 update_id3_frame_from_tuple(struct id3_tag *id3tag, const char *field, Tuple *tuple, int fieldn, int sjis)
df520f828dcf Say goodbye to custom fileinfo dialog in madplug
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2050
diff changeset
126 {
df520f828dcf Say goodbye to custom fileinfo dialog in madplug
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2050
diff changeset
127 int val;
df520f828dcf Say goodbye to custom fileinfo dialog in madplug
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2050
diff changeset
128 char *text, *text2;
df520f828dcf Say goodbye to custom fileinfo dialog in madplug
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2050
diff changeset
129 const char *encoding = sjis ? "SJIS" : "UTF-8";
df520f828dcf Say goodbye to custom fileinfo dialog in madplug
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2050
diff changeset
130
df520f828dcf Say goodbye to custom fileinfo dialog in madplug
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2050
diff changeset
131 if(aud_tuple_get_value_type(tuple, fieldn, NULL) == TUPLE_INT) {
df520f828dcf Say goodbye to custom fileinfo dialog in madplug
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2050
diff changeset
132 val = aud_tuple_get_int(tuple, fieldn, NULL);
df520f828dcf Say goodbye to custom fileinfo dialog in madplug
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2050
diff changeset
133 if(val > 0) {
df520f828dcf Say goodbye to custom fileinfo dialog in madplug
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2050
diff changeset
134 text2 = g_strdup_printf("%d", val);
df520f828dcf Say goodbye to custom fileinfo dialog in madplug
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2050
diff changeset
135 #ifdef DEBUG
df520f828dcf Say goodbye to custom fileinfo dialog in madplug
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2050
diff changeset
136 fprintf(stderr, "madplug: updating field:\"%s\"=\"%s\", enc %s\n", field, text2, encoding);
df520f828dcf Say goodbye to custom fileinfo dialog in madplug
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2050
diff changeset
137 #endif
df520f828dcf Say goodbye to custom fileinfo dialog in madplug
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2050
diff changeset
138 update_id3_frame(id3tag, field, text2, 0);
df520f828dcf Say goodbye to custom fileinfo dialog in madplug
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2050
diff changeset
139 g_free(text2);
df520f828dcf Say goodbye to custom fileinfo dialog in madplug
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2050
diff changeset
140 } else {
df520f828dcf Say goodbye to custom fileinfo dialog in madplug
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2050
diff changeset
141 update_id3_frame(id3tag, field, "", 0); /* will be detached */
df520f828dcf Say goodbye to custom fileinfo dialog in madplug
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2050
diff changeset
142 }
df520f828dcf Say goodbye to custom fileinfo dialog in madplug
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2050
diff changeset
143
df520f828dcf Say goodbye to custom fileinfo dialog in madplug
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2050
diff changeset
144 } else if(aud_tuple_get_value_type(tuple, fieldn, NULL) == TUPLE_STRING) {
df520f828dcf Say goodbye to custom fileinfo dialog in madplug
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2050
diff changeset
145 text = (char*)aud_tuple_get_string(tuple, fieldn, NULL);
df520f828dcf Say goodbye to custom fileinfo dialog in madplug
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2050
diff changeset
146 text2 = g_convert(text, strlen(text), encoding, "UTF-8", NULL, NULL, NULL);
df520f828dcf Say goodbye to custom fileinfo dialog in madplug
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2050
diff changeset
147 #ifdef DEBUG
df520f828dcf Say goodbye to custom fileinfo dialog in madplug
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2050
diff changeset
148 fprintf(stderr, "madplug: updating field:\"%s\"=\"%s\", enc %s\n", field, text2, encoding);
df520f828dcf Say goodbye to custom fileinfo dialog in madplug
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2050
diff changeset
149 #endif
df520f828dcf Say goodbye to custom fileinfo dialog in madplug
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2050
diff changeset
150 update_id3_frame(id3tag, field, text2, sjis);
df520f828dcf Say goodbye to custom fileinfo dialog in madplug
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2050
diff changeset
151 g_free(text2);
df520f828dcf Say goodbye to custom fileinfo dialog in madplug
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2050
diff changeset
152 }
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
153 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
154
2201
df520f828dcf Say goodbye to custom fileinfo dialog in madplug
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2050
diff changeset
155 gboolean
df520f828dcf Say goodbye to custom fileinfo dialog in madplug
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2050
diff changeset
156 audmad_update_song_tuple(Tuple *tuple, VFSFile *fd)
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
157 {
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
158 struct id3_file *id3file;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
159 struct id3_tag *id3tag;
2202
f76e846d53d9 updating TLEN frame returned
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2201
diff changeset
160 gchar *text;
f76e846d53d9 updating TLEN frame returned
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2201
diff changeset
161 struct mad_info_t songinfo;
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
162
2201
df520f828dcf Say goodbye to custom fileinfo dialog in madplug
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2050
diff changeset
163 if ((id3file = id3_file_vfsopen(fd, ID3_FILE_MODE_READWRITE)) == NULL) return FALSE;
df520f828dcf Say goodbye to custom fileinfo dialog in madplug
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2050
diff changeset
164
629
ee59ad236eb6 [svn] - revise save tag callback
yaz
parents: 613
diff changeset
165 id3tag = id3_file_tag(id3file);
ee59ad236eb6 [svn] - revise save tag callback
yaz
parents: 613
diff changeset
166 if (!id3tag) {
ee59ad236eb6 [svn] - revise save tag callback
yaz
parents: 613
diff changeset
167 #ifdef DEBUG
2201
df520f828dcf Say goodbye to custom fileinfo dialog in madplug
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2050
diff changeset
168 fprintf(stderr, "no id3tag\n. append new tag.\n");
629
ee59ad236eb6 [svn] - revise save tag callback
yaz
parents: 613
diff changeset
169 #endif
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
170 id3tag = id3_tag_new();
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
171 id3_tag_clearframes(id3tag);
629
ee59ad236eb6 [svn] - revise save tag callback
yaz
parents: 613
diff changeset
172 id3tag->options |= ID3_TAG_OPTION_APPENDEDTAG | ID3_TAG_OPTION_ID3V1;
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
173 }
629
ee59ad236eb6 [svn] - revise save tag callback
yaz
parents: 613
diff changeset
174
2201
df520f828dcf Say goodbye to custom fileinfo dialog in madplug
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2050
diff changeset
175 id3_tag_options(id3tag, ID3_TAG_OPTION_ID3V1, ~0); /* enables id3v1. TODO: make id3v1 optional */
df520f828dcf Say goodbye to custom fileinfo dialog in madplug
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2050
diff changeset
176
df520f828dcf Say goodbye to custom fileinfo dialog in madplug
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2050
diff changeset
177 update_id3_frame_from_tuple(id3tag, ID3_FRAME_TITLE, tuple, FIELD_TITLE, audmad_config.sjis);
df520f828dcf Say goodbye to custom fileinfo dialog in madplug
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2050
diff changeset
178 update_id3_frame_from_tuple(id3tag, ID3_FRAME_ARTIST, tuple, FIELD_ARTIST, audmad_config.sjis);
df520f828dcf Say goodbye to custom fileinfo dialog in madplug
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2050
diff changeset
179 update_id3_frame_from_tuple(id3tag, ID3_FRAME_ALBUM, tuple, FIELD_ALBUM, audmad_config.sjis);
df520f828dcf Say goodbye to custom fileinfo dialog in madplug
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2050
diff changeset
180 update_id3_frame_from_tuple(id3tag, ID3_FRAME_YEAR, tuple, FIELD_YEAR, audmad_config.sjis);
df520f828dcf Say goodbye to custom fileinfo dialog in madplug
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2050
diff changeset
181 update_id3_frame_from_tuple(id3tag, ID3_FRAME_COMMENT, tuple, FIELD_COMMENT, audmad_config.sjis);
df520f828dcf Say goodbye to custom fileinfo dialog in madplug
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2050
diff changeset
182 update_id3_frame_from_tuple(id3tag, ID3_FRAME_TRACK, tuple, FIELD_TRACK_NUMBER, audmad_config.sjis);
df520f828dcf Say goodbye to custom fileinfo dialog in madplug
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2050
diff changeset
183 update_id3_frame_from_tuple(id3tag, ID3_FRAME_GENRE, tuple, FIELD_GENRE, audmad_config.sjis);
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
184
2202
f76e846d53d9 updating TLEN frame returned
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2201
diff changeset
185 if(!id3_tag_findframe(id3tag, "TLEN", 0) && input_init(&songinfo, fd->uri, fd) && !songinfo.remote) {
f76e846d53d9 updating TLEN frame returned
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2201
diff changeset
186 #ifdef DEBUG
f76e846d53d9 updating TLEN frame returned
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2201
diff changeset
187 fprintf(stderr, "update TLEN frame\n");
f76e846d53d9 updating TLEN frame returned
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2201
diff changeset
188 #endif
f76e846d53d9 updating TLEN frame returned
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2201
diff changeset
189 songinfo.fileinfo_request = FALSE; /* we don't need to read tuple again */
f76e846d53d9 updating TLEN frame returned
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2201
diff changeset
190 input_get_info(&songinfo, FALSE);
f76e846d53d9 updating TLEN frame returned
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2201
diff changeset
191 text = g_strdup_printf("%ld", mad_timer_count(songinfo.duration, MAD_UNITS_MILLISECONDS));
f76e846d53d9 updating TLEN frame returned
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2201
diff changeset
192 #ifdef DEBUG
f76e846d53d9 updating TLEN frame returned
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2201
diff changeset
193 fprintf(stderr, "TLEN: \"%s\"\n", text);
f76e846d53d9 updating TLEN frame returned
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2201
diff changeset
194 #endif
f76e846d53d9 updating TLEN frame returned
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2201
diff changeset
195 update_id3_frame(id3tag, "TLEN", text, 0);
f76e846d53d9 updating TLEN frame returned
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2201
diff changeset
196 g_free(text);
f76e846d53d9 updating TLEN frame returned
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2201
diff changeset
197 input_term(&songinfo);
f76e846d53d9 updating TLEN frame returned
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2201
diff changeset
198 }
f76e846d53d9 updating TLEN frame returned
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2201
diff changeset
199
2201
df520f828dcf Say goodbye to custom fileinfo dialog in madplug
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2050
diff changeset
200 if (id3_file_update(id3file) != 0) return FALSE;
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
201
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
202 id3_file_close(id3file);
2201
df520f828dcf Say goodbye to custom fileinfo dialog in madplug
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2050
diff changeset
203 return TRUE;
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
204 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
205