comparison Plugins/Input/mpg123/id3_frame_content.c @ 61:fa848bd484d8 trunk

[svn] Move plugins to Plugins/
author nenolod
date Fri, 28 Oct 2005 22:58:11 -0700
parents
children 539a0fa7f030
comparison
equal deleted inserted replaced
60:1771f253e1b2 61:fa848bd484d8
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 {
47 char *text, *text_beg, *ptr;
48 char buffer[256];
49 int spc = sizeof(buffer) - 1;
50
51 /* Type check */
52 if (frame->fr_desc->fd_id != ID3_TCON)
53 return NULL;
54
55 /* Check if frame is compressed */
56 if (id3_decompress_frame(frame) == -1)
57 return NULL;
58
59 if (*(guint8 *) frame->fr_data == ID3_ENCODING_ISO_8859_1)
60 text_beg = text = g_strdup((char *) frame->fr_data + 1);
61 else
62 text_beg = text = id3_utf16_to_ascii((char *) frame->fr_data + 1);
63
64 /*
65 * If content is just plain text, return it.
66 */
67 if (text[0] != '(') {
68 return text;
69 }
70
71 /*
72 * Expand ID3v1 genre numbers.
73 */
74 ptr = buffer;
75 while (text[0] == '(' && text[1] != '(' && spc > 0) {
76 const char *genre;
77 int num = 0;
78
79 if (text[1] == 'R' && text[2] == 'X') {
80 text += 4;
81 genre = _(" (Remix)");
82 if (ptr == buffer)
83 genre++;
84
85 }
86 else if (text[1] == 'C' && text[2] == 'R') {
87 text += 4;
88 genre = _(" (Cover)");
89 if (ptr == buffer)
90 genre++;
91
92 }
93 else {
94 /* Get ID3v1 genre number */
95 text++;
96 while (*text != ')') {
97 num *= 10;
98 num += *text++ - '0';
99 }
100 text++;
101
102 /* Boundary check */
103 if (num >= sizeof(mpg123_id3_genres) / sizeof(char *))
104 continue;
105
106 genre = gettext(mpg123_id3_genres[num]);
107
108 if (ptr != buffer && spc-- > 0)
109 *ptr++ = '/';
110 }
111
112 /* Expand string into buffer */
113 while (*genre != '\0' && spc > 0) {
114 *ptr++ = *genre++;
115 spc--;
116 }
117 }
118
119 /*
120 * Add plaintext refinement.
121 */
122 if (*text == '(')
123 text++;
124 if (*text != '\0' && ptr != buffer && spc-- > 0)
125 *ptr++ = ' ';
126 while (*text != '\0' && spc > 0) {
127 *ptr++ = *text++;
128 spc--;
129 }
130 *ptr = '\0';
131
132 g_free(text_beg);
133
134 /*
135 * Return the expanded content string.
136 */
137 return g_strdup(buffer);
138 }