annotate Plugins/Input/mpg123/id3_frame_text.c @ 61:fa848bd484d8 trunk

[svn] Move plugins to Plugins/
author nenolod
date Fri, 28 Oct 2005 22:58:11 -0700
parents
children 539a0fa7f030
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1 /*********************************************************************
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
2 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
3 * Copyright (C) 1999, 2001, 2002, Espen Skoglund
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
4 * Department of Computer Science, University of Tromsų
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
5 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
6 * Filename: id3_frame_text.c
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
7 * Description: Code for handling ID3 text frames.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
8 * Author: Espen Skoglund <espensk@stud.cs.uit.no>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
9 * Created at: Fri Feb 5 23:50:33 1999
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
10 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
11 * $Id: id3_frame_text.c,v 1.7 2004/08/21 13:04:47 descender Exp $
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
12 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
13 * This program is free software; you can redistribute it and/or
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
14 * modify it under the terms of the GNU General Public License
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
15 * as published by the Free Software Foundation; either version 2
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
16 * of the License, or (at your option) any later version.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
17 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
18 * This program is distributed in the hope that it will be useful,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
21 * GNU General Public License for more details.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
22 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
23 * You should have received a copy of the GNU General Public License
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
24 * along with this program; if not, write to the Free Software
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
26 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
27 ********************************************************************/
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
28 #include "config.h"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
29
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
30 #include <stdarg.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
31 #include <stdlib.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
32 #include <string.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
33
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
34 #include "xmms-id3.h"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
35 #include "id3_header.h"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
36
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
37
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
38 char *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
39 id3_utf16_to_ascii(void *utf16)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
40 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
41 char ascii[256];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
42 char *uc = (char *) utf16 + 2;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
43 int i;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
44
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
45 for (i = 0; *uc != 0 && i < sizeof(ascii); i++, uc += 2)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
46 ascii[i] = *uc;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
47
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
48 ascii[i] = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
49 return g_strdup(ascii);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
50 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
51
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
52
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
53 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
54 * Function id3_get_encoding (frame)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
55 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
56 * Return text encoding for frame, or -1 if frame does not have any
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
57 * text encoding.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
58 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
59 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
60 gint8
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
61 id3_get_encoding(struct id3_frame * frame)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
62 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
63 /* Type check */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
64 if (!id3_frame_is_text(frame) &&
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
65 frame->fr_desc->fd_id != ID3_WXXX &&
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
66 frame->fr_desc->fd_id != ID3_IPLS &&
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
67 frame->fr_desc->fd_id != ID3_USLT &&
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
68 frame->fr_desc->fd_id != ID3_SYLT &&
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
69 frame->fr_desc->fd_id != ID3_COMM &&
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
70 frame->fr_desc->fd_id != ID3_APIC &&
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
71 frame->fr_desc->fd_id != ID3_GEOB &&
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
72 frame->fr_desc->fd_id != ID3_USER &&
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
73 frame->fr_desc->fd_id != ID3_OWNE &&
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
74 frame->fr_desc->fd_id != ID3_COMR)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
75 return -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
76
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
77 /* Check if frame is compressed */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
78 if (id3_decompress_frame(frame) == -1)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
79 return -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
80
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
81 return *(gint8 *) frame->fr_data;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
82 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
83
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
84
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
85 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
86 * Function id3_set_encoding (frame, encoding)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
87 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
88 * Set text encoding for frame. Return 0 upon success, or -1 if an
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
89 * error occured.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
90 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
91 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
92 int
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
93 id3_set_encoding(struct id3_frame *frame, gint8 encoding)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
94 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
95 /* Type check */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
96 if (frame->fr_desc->fd_idstr[0] != 'T' &&
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
97 frame->fr_desc->fd_id != ID3_WXXX &&
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
98 frame->fr_desc->fd_id != ID3_IPLS &&
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
99 frame->fr_desc->fd_id != ID3_USLT &&
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
100 frame->fr_desc->fd_id != ID3_SYLT &&
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
101 frame->fr_desc->fd_id != ID3_COMM &&
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
102 frame->fr_desc->fd_id != ID3_APIC &&
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
103 frame->fr_desc->fd_id != ID3_GEOB &&
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
104 frame->fr_desc->fd_id != ID3_USER &&
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
105 frame->fr_desc->fd_id != ID3_OWNE &&
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
106 frame->fr_desc->fd_id != ID3_COMR)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
107 return -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
108
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
109 /* Check if frame is compressed */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
110 if (id3_decompress_frame(frame) == -1)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
111 return -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
112
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
113 /* Changing the encoding of frames is not supported yet */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
114 if (*(gint8 *) frame->fr_data != encoding)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
115 return -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
116
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
117 /* Set encoding */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
118 *(gint8 *) frame->fr_data = encoding;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
119 return 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
120 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
121
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
122
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
123 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
124 * Function id3_get_text (frame)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
125 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
126 * Return string contents of frame.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
127 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
128 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
129 char *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
130 id3_get_text(struct id3_frame *frame)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
131 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
132 /* Type check */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
133 if (frame->fr_desc->fd_idstr[0] != 'T' && frame->fr_desc->fd_id != ID3_COMM)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
134 return NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
135
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
136 /* Check if frame is compressed */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
137 if (id3_decompress_frame(frame) == -1)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
138 return NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
139
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
140 if (frame->fr_desc->fd_id == ID3_TXXX || frame->fr_desc->fd_id == ID3_COMM) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
141 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
142 * This is a user defined text frame. Skip the description.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
143 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
144 switch (*(guint8 *) frame->fr_data) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
145 case ID3_ENCODING_ISO_8859_1:
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
146 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
147 char *text = (char *) frame->fr_data + 1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
148
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
149 while (*text != 0)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
150 text++;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
151
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
152 return g_strdup(++text);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
153 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
154 case ID3_ENCODING_UTF16:
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
155 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
156 char *text16 = (char *) frame->fr_data + 1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
157
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
158 while (*text16 != 0 || *(text16 + 1) != 0)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
159 text16 += 2;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
160
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
161 return id3_utf16_to_ascii(text16 + 2);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
162 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
163 default:
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
164 return NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
165 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
166 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
167
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
168 if (*(guint8 *) frame->fr_data == ID3_ENCODING_ISO_8859_1)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
169 return g_strdup((char *) frame->fr_data + 1);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
170 else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
171 return id3_utf16_to_ascii(((char *) frame->fr_data + 1));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
172 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
173
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
174
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
175 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
176 * Function id3_get_text_desc (frame)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
177 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
178 * Get description part of a text frame.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
179 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
180 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
181 char *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
182 id3_get_text_desc(struct id3_frame *frame)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
183 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
184 /* Type check */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
185 if (frame->fr_desc->fd_idstr[0] != 'T')
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
186 return NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
187
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
188 /* If predefined text frame, return description. */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
189 if (frame->fr_desc->fd_id != ID3_TXXX)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
190 return frame->fr_desc->fd_description;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
191
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
192 /* Check if frame is compressed */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
193 if (id3_decompress_frame(frame) == -1)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
194 return NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
195
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
196 if (*(guint8 *) frame->fr_data == ID3_ENCODING_ISO_8859_1)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
197 return g_strdup((char *) frame->fr_data + 1);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
198 else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
199 return id3_utf16_to_ascii((char *) frame->fr_data + 1);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
200 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
201
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
202
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
203 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
204 * Function id3_get_text_number (frame)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
205 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
206 * Return string contents of frame translated to a positive
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
207 * integer, or -1 if an error occured.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
208 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
209 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
210 int
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
211 id3_get_text_number(struct id3_frame *frame)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
212 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
213 int number = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
214
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
215 /* Check if frame is compressed */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
216 if (id3_decompress_frame(frame) == -1)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
217 return -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
218
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
219 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
220 * Generate integer according to encoding.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
221 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
222 switch (*(guint8 *) frame->fr_data) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
223 case ID3_ENCODING_ISO_8859_1:
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
224 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
225 char *text = ((char *) frame->fr_data) + 1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
226
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
227 while (*text >= '0' && *text <= '9') {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
228 number *= 10;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
229 number += *text - '0';
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
230 text++;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
231 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
232
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
233 return number;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
234 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
235 case ID3_ENCODING_UTF16:
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
236 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
237 char *text = ((char *) frame->fr_data) + 3;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
238
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
239 /* if (*(gint16 *) frame->fr_data == 0xfeff) */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
240 /* text++; */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
241
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
242 while (*text >= '0' && *text <= '9') {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
243 number *= 10;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
244 number += *text - '0';
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
245 text++;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
246 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
247
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
248 return number;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
249 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
250
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
251 default:
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
252 return -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
253 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
254 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
255
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
256
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
257 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
258 * Function id3_set_text (frame, text)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
259 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
260 * Set text for the indicated frame (only ISO-8859-1 is currently
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
261 * supported). Return 0 upon success, or -1 if an error occured.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
262 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
263 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
264 int
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
265 id3_set_text(struct id3_frame *frame, char *text)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
266 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
267 /* Type check */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
268 if (frame->fr_desc->fd_idstr[0] != 'T')
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
269 return -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
270
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
271 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
272 * Release memory occupied by previous data.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
273 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
274 id3_frame_clear_data(frame);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
275
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
276 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
277 * Allocate memory for new data.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
278 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
279 frame->fr_raw_size = strlen(text) + 1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
280 frame->fr_raw_data = g_malloc(frame->fr_raw_size + 1);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
281
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
282 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
283 * Copy contents.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
284 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
285 *(gint8 *) frame->fr_raw_data = ID3_ENCODING_ISO_8859_1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
286 memcpy((char *) frame->fr_raw_data + 1, text, frame->fr_raw_size);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
287
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
288 frame->fr_altered = 1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
289 frame->fr_owner->id3_altered = 1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
290
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
291 frame->fr_data = frame->fr_raw_data;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
292 frame->fr_size = frame->fr_raw_size;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
293
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
294 return 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
295 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
296
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
297
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
298 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
299 * Function id3_set_text_number (frame, number)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
300 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
301 * Set number for the indicated frame (only ISO-8859-1 is currently
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
302 * supported). Return 0 upon success, or -1 if an error occured.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
303 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
304 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
305 int
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
306 id3_set_text_number(struct id3_frame *frame, int number)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
307 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
308 char buf[64];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
309 int pos;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
310 char *text;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
311
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
312 /* Type check */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
313 if (frame->fr_desc->fd_idstr[0] != 'T')
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
314 return -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
315
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
316 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
317 * Release memory occupied by previous data.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
318 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
319 id3_frame_clear_data(frame);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
320
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
321 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
322 * Create a string with a reversed number.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
323 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
324 pos = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
325 while (number > 0 && pos < 64) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
326 buf[pos++] = (number % 10) + '0';
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
327 number /= 10;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
328 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
329 if (pos == 64)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
330 return -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
331 if (pos == 0)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
332 buf[pos++] = '0';
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
333
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
334 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
335 * Allocate memory for new data.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
336 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
337 frame->fr_raw_size = pos + 1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
338 frame->fr_raw_data = g_malloc(frame->fr_raw_size + 1);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
339
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
340 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
341 * Insert contents.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
342 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
343 *(gint8 *) frame->fr_raw_data = ID3_ENCODING_ISO_8859_1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
344 text = (char *) frame->fr_raw_data + 1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
345 while (--pos >= 0)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
346 *text++ = buf[pos];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
347 *text = '\0';
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
348
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
349 frame->fr_altered = 1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
350 frame->fr_owner->id3_altered = 1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
351
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
352 frame->fr_data = frame->fr_raw_data;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
353 frame->fr_size = frame->fr_raw_size;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
354
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
355 return 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
356 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
357
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
358 gboolean
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
359 id3_frame_is_text(struct id3_frame * frame)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
360 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
361 if (frame && frame->fr_desc &&
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
362 (frame->fr_desc->fd_idstr[0] == 'T' ||
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
363 frame->fr_desc->fd_idstr[0] == 'W'))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
364 return TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
365 return FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
366 }