Mercurial > audlegacy
annotate Plugins/Input/mpg123/id3_frame_content.c @ 917:822114b4b8a8 trunk
[svn] - more progress
author | nenolod |
---|---|
date | Wed, 05 Apr 2006 11:13:52 -0700 |
parents | d539e5c5f730 |
children |
rev | line source |
---|---|
61 | 1 /********************************************************************* |
2 * | |
3 * Copyright (C) 1999, 2002, Espen Skoglund | |
4 * Department of Computer Science, University of Tromsų | |
5 * | |
6 * Filename: id3_frame_content.c | |
7 * Description: Code for handling ID3 content frames. | |
8 * Author: Espen Skoglund <espensk@stud.cs.uit.no> | |
9 * Created at: Mon Feb 8 17:13:46 1999 | |
10 * | |
11 * $Id: id3_frame_content.c,v 1.7 2004/07/20 21:47:22 descender Exp $ | |
12 * | |
13 * This program is free software; you can redistribute it and/or | |
14 * modify it under the terms of the GNU General Public License | |
15 * as published by the Free Software Foundation; either version 2 | |
16 * of the License, or (at your option) any later version. | |
17 * | |
18 * This program is distributed in the hope that it will be useful, | |
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 * GNU General Public License for more details. | |
22 * | |
23 * You should have received a copy of the GNU General Public License | |
24 * along with this program; if not, write to the Free Software | |
25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
26 * | |
27 ********************************************************************/ | |
28 | |
29 #include <glib.h> | |
30 #include <glib/gi18n.h> | |
31 | |
32 #include "xmms-id3.h" | |
33 | |
34 #include "mpg123.h" | |
35 | |
36 | |
37 /* | |
38 * Function id3_get_content (frame) | |
39 * | |
40 * Expand content type string of frame and return it. Return NULL | |
41 * upon error. | |
42 * | |
43 */ | |
44 char * | |
45 id3_get_content(struct id3_frame *frame) | |
46 { | |
240
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
47 char *text, *text_beg, *ptr; |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
48 char buffer[256]; |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
49 int spc = sizeof(buffer) - 1; |
61 | 50 |
240
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
51 /* Type check */ |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
52 if (frame->fr_desc->fd_id != ID3_TCON) |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
53 return NULL; |
227
539a0fa7f030
[svn] Unicode support fixes, based on an XMMS patch written by Ilya Konstantinov. <ikonst@users.sourceforge.net>:
nenolod
parents:
61
diff
changeset
|
54 |
240
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
55 /* Check if frame is compressed */ |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
56 if (id3_decompress_frame(frame) == -1) |
61 | 57 return NULL; |
58 | |
240
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
59 if (*(guint8 *) frame->fr_data == ID3_ENCODING_ISO_8859_1) |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
60 text_beg = text = g_strdup((char *) frame->fr_data + 1); |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
61 else |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
62 text_beg = text = id3_utf16_to_ascii((char *) frame->fr_data + 1); |
61 | 63 |
240
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
64 /* |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
65 * If content is just plain text, return it. |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
66 */ |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
67 if (text[0] != '(') { |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
68 return text; |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
69 } |
61 | 70 |
240
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
71 /* |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
72 * Expand ID3v1 genre numbers. |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
73 */ |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
74 ptr = buffer; |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
75 while (text[0] == '(' && text[1] != '(' && spc > 0) { |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
76 const char *genre; |
701
d539e5c5f730
[svn] Fixes of the remaining GCC 4.1 warnings from external contributor Diego "Flameeyes" Petteno (Gentoo).
chainsaw
parents:
240
diff
changeset
|
77 size_t num = 0; |
240
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
78 |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
79 if (text[1] == 'R' && text[2] == 'X') { |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
80 text += 4; |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
81 genre = _(" (Remix)"); |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
82 if (ptr == buffer) |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
83 genre++; |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
84 |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
85 } |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
86 else if (text[1] == 'C' && text[2] == 'R') { |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
87 text += 4; |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
88 genre = _(" (Cover)"); |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
89 if (ptr == buffer) |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
90 genre++; |
61 | 91 |
240
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
92 } |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
93 else { |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
94 /* Get ID3v1 genre number */ |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
95 text++; |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
96 while (*text != ')') { |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
97 num *= 10; |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
98 num += *text++ - '0'; |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
99 } |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
100 text++; |
61 | 101 |
240
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
102 /* Boundary check */ |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
103 if (num >= sizeof(mpg123_id3_genres) / sizeof(char *)) |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
104 continue; |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
105 |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
106 genre = gettext(mpg123_id3_genres[num]); |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
107 |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
108 if (ptr != buffer && spc-- > 0) |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
109 *ptr++ = '/'; |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
110 } |
61 | 111 |
240
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
112 /* Expand string into buffer */ |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
113 while (*genre != '\0' && spc > 0) { |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
114 *ptr++ = *genre++; |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
115 spc--; |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
116 } |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
117 } |
61 | 118 |
240
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
119 /* |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
120 * Add plaintext refinement. |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
121 */ |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
122 if (*text == '(') |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
123 text++; |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
124 if (*text != '\0' && ptr != buffer && spc-- > 0) |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
125 *ptr++ = ' '; |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
126 while (*text != '\0' && spc > 0) { |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
127 *ptr++ = *text++; |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
128 spc--; |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
129 } |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
130 *ptr = '\0'; |
61 | 131 |
240
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
132 g_free(text_beg); |
61 | 133 |
240
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
134 /* |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
135 * Return the expanded content string. |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
136 */ |
18cb7405b5e9
[svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents:
228
diff
changeset
|
137 return g_strdup(buffer); |
61 | 138 } |