~ubuntu-branches/ubuntu/utopic/rhythmbox/utopic-proposed

« back to all changes in this revision

Viewing changes to metadata/rb-metadata-xine.c

Tags: upstream-0.9.2
ImportĀ upstreamĀ versionĀ 0.9.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  arch-tag: Implementation of xine-lib metadata loading
3
 
 *
4
 
 *  Copyright (C) 2003-2004 Bastien Nocera <hadess@hadess.net>
5
 
 *
6
 
 *  This program is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; either version 2 of the License, or
9
 
 *  (at your option) any later version.
10
 
 *
11
 
 *  This program is distributed in the hope that it will be useful,
12
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
 *  GNU General Public License for more details.
15
 
 *
16
 
 *  You should have received a copy of the GNU General Public License
17
 
 *  along with this program; if not, write to the Free Software
18
 
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
 
 *
20
 
 */
21
 
 
22
 
#include <libgnomevfs/gnome-vfs.h>
23
 
#include <string.h>
24
 
#include <stdlib.h>
25
 
#include <stdio.h>
26
 
 
27
 
#include <xine.h>
28
 
 
29
 
#include "rb-string-helpers.h"
30
 
 
31
 
#include "rb-metadata.h"
32
 
 
33
 
static void rb_metadata_class_init (RBMetaDataClass *klass);
34
 
static void rb_metadata_init (RBMetaData *md);
35
 
static void rb_metadata_finalize (GObject *object);
36
 
 
37
 
struct RBMetaDataPrivate
38
 
{
39
 
        xine_t *xine;
40
 
        xine_stream_t *stream;
41
 
};
42
 
 
43
 
static GObjectClass *parent_class = NULL;
44
 
 
45
 
GType
46
 
rb_metadata_get_type (void)
47
 
{
48
 
        static GType type = 0;
49
 
 
50
 
        if (type == 0)
51
 
        {
52
 
                static const GTypeInfo our_info =
53
 
                {
54
 
                        sizeof (RBMetaDataClass),
55
 
                        NULL,
56
 
                        NULL,
57
 
                        (GClassInitFunc) rb_metadata_class_init,
58
 
                        NULL,
59
 
                        NULL,
60
 
                        sizeof (RBMetaData),
61
 
                        0,
62
 
                        (GInstanceInitFunc) rb_metadata_init
63
 
                };
64
 
 
65
 
                type = g_type_register_static (G_TYPE_OBJECT,
66
 
                                               "RBMetaData",
67
 
                                               &our_info, 0);
68
 
        }
69
 
 
70
 
        return type;
71
 
}
72
 
 
73
 
static void
74
 
rb_metadata_class_init (RBMetaDataClass *klass)
75
 
{
76
 
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
77
 
 
78
 
        parent_class = g_type_class_peek_parent (klass);
79
 
 
80
 
        object_class->finalize = rb_metadata_finalize;
81
 
}
82
 
 
83
 
static void
84
 
rb_metadata_init (RBMetaData *md)
85
 
{
86
 
        char *path;
87
 
 
88
 
        md->priv = g_new0 (RBMetaDataPrivate, 1);
89
 
        md->priv->xine = xine_new ();
90
 
        path = g_build_filename (g_get_home_dir(), ".gnome2",
91
 
                                 "xine-config", NULL);
92
 
        xine_config_load (md->priv->xine, path);
93
 
 
94
 
        xine_init (md->priv->xine);
95
 
        md->priv->stream = xine_stream_new (md->priv->xine, NULL, NULL);
96
 
}
97
 
 
98
 
RBMetaData *
99
 
rb_metadata_new (void)
100
 
{
101
 
        return RB_METADATA (g_object_new (RB_TYPE_METADATA, NULL));
102
 
}
103
 
 
104
 
static void
105
 
rb_metadata_finalize (GObject *object)
106
 
{
107
 
        RBMetaData *md;
108
 
 
109
 
        md = RB_METADATA (object);
110
 
 
111
 
        xine_close (md->priv->stream);
112
 
        xine_dispose (md->priv->stream);
113
 
        xine_exit (md->priv->xine);
114
 
 
115
 
        g_free (md->priv);
116
 
 
117
 
        G_OBJECT_CLASS (parent_class)->finalize (object);
118
 
}
119
 
 
120
 
/* FIXME implement error collapsing like in Totem */
121
 
static gboolean
122
 
xine_error (RBMetaData *md, GError **error)
123
 
{
124
 
        int err;
125
 
 
126
 
        err = xine_get_error (md->priv->stream);
127
 
        if (err == XINE_ERROR_NONE)
128
 
                return TRUE;
129
 
 
130
 
        /* FIXME actualise to the current metadata errors */
131
 
#if 0
132
 
        switch (err)
133
 
        {
134
 
        case XINE_ERROR_NO_INPUT_PLUGIN:
135
 
        case XINE_ERROR_NO_DEMUX_PLUGIN:
136
 
                *error = g_error_new (RB_METADATA_ERROR, RB_METADATA_ERROR_OPEN_FAILED, _("There is no plugin to handle this song"));
137
 
                break;
138
 
        case XINE_ERROR_DEMUX_FAILED:
139
 
                *error = g_error_new (RB_METADATA_ERROR, RB_METADATA_ERROR_OPEN_FAILED, _("This song is broken and can not be played further"));
140
 
                break;
141
 
        case XINE_ERROR_MALFORMED_MRL:
142
 
                *error = g_error_new (RB_METADATA_ERROR, RB_METADATA_ERROR_OPEN_FAILED, _("This location is not a valid one"));
143
 
                break;
144
 
        case XINE_ERROR_INPUT_FAILED:
145
 
                *error = g_error_new (RB_METADATA_ERROR, RB_METADATA_ERROR_OPEN_FAILED, _("This song could not be opened"));                break;
146
 
        default:
147
 
                *error = g_error_new (RB_METADATA_ERROR, RB_METADATA_ERROR_OPEN_FAILED, _("Generic Error"));
148
 
                break;
149
 
        }
150
 
#endif
151
 
        return FALSE;
152
 
}
153
 
 
154
 
void
155
 
rb_metadata_load (RBMetaData *md, const char *uri, GError **error)
156
 
{
157
 
        int err;
158
 
 
159
 
        xine_close (md->priv->stream);
160
 
        err = xine_open (md->priv->stream, uri);
161
 
 
162
 
        if (error == 0)
163
 
        {
164
 
                if (xine_error (md, error) == FALSE)
165
 
                {
166
 
                        xine_close (md->priv->stream);
167
 
                        g_object_set (G_OBJECT (md), "error", error, NULL);
168
 
                        return;
169
 
                }
170
 
        }
171
 
 
172
 
        if (xine_get_stream_info (md->priv->stream,
173
 
                                XINE_STREAM_INFO_HAS_AUDIO) == FALSE)
174
 
        {
175
 
#if 0
176
 
                error = g_error_new (RB_METADATA_ERROR,
177
 
                                     RB_METADATA_ERROR_OPEN_FAILED,
178
 
                                     _("File is not an audio file"));
179
 
                g_object_set (G_OBJECT (md), "error", error, NULL);
180
 
#endif
181
 
                return;
182
 
        }
183
 
 
184
 
        if (xine_get_stream_info (md->priv->stream,
185
 
                                XINE_STREAM_INFO_AUDIO_HANDLED) == FALSE)
186
 
        {
187
 
#if 0
188
 
                error = g_error_new (RB_METADATA_ERROR,
189
 
                                     RB_METADATA_ERROR_OPEN_FAILED,
190
 
                                     _("Song is not handled"));
191
 
                g_object_set (G_OBJECT (md), "error", error, NULL);
192
 
#endif
193
 
                return;
194
 
        }
195
 
}
196
 
 
197
 
gboolean
198
 
rb_metadata_get (RBMetaData *md,
199
 
                                RBMetaDataField field,
200
 
                                GValue *value)
201
 
{
202
 
        const char *tmp = NULL;
203
 
 
204
 
        switch (field)
205
 
        {
206
 
        /* tags */
207
 
        case RB_METADATA_FIELD_TITLE:
208
 
                g_value_init (value, G_TYPE_STRING);
209
 
                tmp = xine_get_meta_info (md->priv->stream,
210
 
                                XINE_META_INFO_TITLE);
211
 
                g_value_set_string (value, tmp);
212
 
                break;
213
 
        case RB_METADATA_FIELD_ARTIST:
214
 
                g_value_init (value, G_TYPE_STRING);
215
 
                tmp = xine_get_meta_info (md->priv->stream,
216
 
                                XINE_META_INFO_ARTIST);
217
 
                g_value_set_string (value, tmp);
218
 
                break;
219
 
        case RB_METADATA_FIELD_ALBUM:
220
 
                g_value_init (value, G_TYPE_STRING);
221
 
                tmp = xine_get_meta_info (md->priv->stream,
222
 
                                XINE_META_INFO_ALBUM);
223
 
                g_value_set_string (value, tmp);
224
 
                break;
225
 
        case RB_METADATA_FIELD_DATE:
226
 
                g_value_init (value, G_TYPE_STRING);
227
 
                tmp = xine_get_meta_info (md->priv->stream,
228
 
                                XINE_META_INFO_YEAR);
229
 
                g_value_set_string (value, tmp);
230
 
                break;
231
 
        case RB_METADATA_FIELD_GENRE:
232
 
                g_value_init (value, G_TYPE_STRING);
233
 
                tmp = xine_get_meta_info (md->priv->stream,
234
 
                                XINE_META_INFO_GENRE);
235
 
                g_value_set_string (value, tmp);
236
 
                break;
237
 
        case RB_METADATA_FIELD_COMMENT:
238
 
                g_value_init (value, G_TYPE_STRING);
239
 
                tmp = xine_get_meta_info (md->priv->stream,
240
 
                                XINE_META_INFO_COMMENT);
241
 
                g_value_set_string (value, tmp);
242
 
                break;
243
 
        case RB_METADATA_FIELD_TRACK_NUMBER:
244
 
#if 0
245
 
                g_value_init (value, G_TYPE_INT);
246
 
                g_value_set_int (value, xine_get_stream_info (md->priv->stream,
247
 
                                        XINE_STREAM_INFO_TRACK_NUMBER));
248
 
#endif
249
 
                break;
250
 
        case RB_METADATA_FIELD_MAX_TRACK_NUMBER:
251
 
#if 0
252
 
                g_value_init (value, G_TYPE_INT);
253
 
                g_value_set_int (value, xine_get_stream_info (md->priv->stream,
254
 
                                        XINE_STREAM_INFO_MAX_TRACK_NUMBER));
255
 
#endif
256
 
                break;
257
 
        case RB_METADATA_FIELD_DESCRIPTION:
258
 
        case RB_METADATA_FIELD_VERSION:
259
 
        case RB_METADATA_FIELD_ISRC:
260
 
        case RB_METADATA_FIELD_ORGANIZATION:
261
 
        case RB_METADATA_FIELD_COPYRIGHT:
262
 
        case RB_METADATA_FIELD_CONTACT:
263
 
        case RB_METADATA_FIELD_LICENSE:
264
 
        case RB_METADATA_FIELD_PERFORMER:
265
 
                g_value_init (value, G_TYPE_STRING);
266
 
                g_value_set_string (value, "");
267
 
                break;
268
 
        case RB_METADATA_FIELD_DURATION:
269
 
                {
270
 
                        int length = 0;
271
 
                        int pos_stream, pos_time;
272
 
 
273
 
                        xine_get_pos_length (md->priv->stream,
274
 
                                        &pos_stream, &pos_time, &length);
275
 
 
276
 
                        g_value_init (value, G_TYPE_LONG);
277
 
                        g_value_set_long (value, length / 1000);
278
 
                }
279
 
                break;
280
 
        case RB_METADATA_FIELD_CODEC:
281
 
                g_value_init (value, G_TYPE_STRING);
282
 
                tmp = xine_get_meta_info (md->priv->stream,
283
 
                                XINE_META_INFO_AUDIOCODEC);
284
 
                g_value_set_string (value, tmp);
285
 
                break;
286
 
        case RB_METADATA_FIELD_BITRATE:
287
 
                g_value_init (value, G_TYPE_INT);
288
 
                g_value_set_int (value, xine_get_stream_info (md->priv->stream,
289
 
                                        XINE_STREAM_INFO_AUDIO_BITRATE) / 1000);
290
 
                break;
291
 
        case RB_METADATA_FIELD_ALBUM_GAIN:
292
 
        case RB_METADATA_FIELD_TRACK_GAIN:
293
 
        case RB_METADATA_FIELD_ALBUM_PEAK:
294
 
        case RB_METADATA_FIELD_TRACK_PEAK:
295
 
                g_value_init (value, G_TYPE_DOUBLE);
296
 
                g_value_set_double (value, 0.0);
297
 
                break;
298
 
 
299
 
        /* default */
300
 
        default:
301
 
                g_warning ("Invalid field!");
302
 
                g_value_init (value, G_TYPE_NONE);
303
 
                break;
304
 
        }
305
 
 
306
 
        return TRUE;
307
 
}
308
 
 
309
 
gboolean
310
 
rb_metadata_set (RBMetaData *md,
311
 
                                RBMetaDataField field,
312
 
                                const GValue *value)
313
 
{
314
 
        return FALSE;
315
 
}
316
 
 
317
 
gboolean
318
 
rb_metadata_can_save (RBMetaData *md, const char *mimetype)
319
 
{
320
 
        return FALSE;
321
 
}
322
 
 
323
 
const char *
324
 
rb_metadata_get_mime (RBMetaData *md)
325
 
{
326
 
        return "application/x-fixme";
327
 
}
328
 
 
329
 
void
330
 
rb_metadata_save (RBMetaData *md, GError **error)
331
 
{
332
 
        return;
333
 
}
334