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
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, 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_content.c
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
7 * Description: Code for handling ID3 content 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: Mon Feb 8 17:13:46 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_content.c,v 1.7 2004/07/20 21:47:22 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
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
29 #include <glib.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
30 #include <glib/gi18n.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
31
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
32 #include "xmms-id3.h"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
33
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
34 #include "mpg123.h"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
35
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 * Function id3_get_content (frame)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
39 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
40 * Expand content type string of frame and return it. Return NULL
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
41 * upon error.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
42 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
43 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
44 char *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
45 id3_get_content(struct id3_frame *frame)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
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
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
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
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
57 return NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
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
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
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
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
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
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
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
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
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
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
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
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
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
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
131
240
18cb7405b5e9 [svn] Revert unicode fixes, cause player to bomb out.
nenolod
parents: 228
diff changeset
132 g_free(text_beg);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
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
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
138 }