1 /*****************************************************************************
2 * vlc_media.c: vlc.Media binding
3 *****************************************************************************
4 * Copyright (C) 2007 the VideoLAN team
7 * Authors: Olivier Aubert <oaubert at liris.cnrs.fr>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
25 /***********************************************************************
27 ***********************************************************************/
30 vlcMedia_new( PyTypeObject *type, PyObject *args, PyObject *kwds )
32 fprintf(stderr, "vlcMedia_new called\n");
33 PyErr_SetString( PyExc_TypeError, "vlc.Media can be instantiated by itself. You should use vlc.Instance().media_new(mrl)." );
38 vlcMedia_dealloc( PyObject *self )
40 libvlc_media_release( LIBVLC_MEDIA(self) );
45 vlcMedia_add_option( PyObject *self, PyObject *args )
47 libvlc_exception_t ex;
48 char* psz_options = NULL;
50 if( !PyArg_ParseTuple( args, "s", &psz_options ) )
54 libvlc_media_add_option( LIBVLC_MEDIA(self), psz_options, &ex);
61 vlcMedia_get_mrl( PyObject *self, PyObject *args )
63 libvlc_exception_t ex;
68 psz_mrl = libvlc_media_get_mrl( LIBVLC_MEDIA(self), &ex);
71 o_ret = Py_BuildValue( "s", psz_mrl );
77 vlcMedia_get_state( PyObject *self, PyObject *args )
79 libvlc_exception_t ex;
80 libvlc_state_t i_state;
83 i_state = libvlc_media_get_state( LIBVLC_MEDIA(self), &ex);
85 /* FIXME: return the defined state constant */
86 return Py_BuildValue( "i", i_state );
90 vlcMedia_get_duration( PyObject *self, PyObject *args )
92 libvlc_exception_t ex;
95 i_ret = libvlc_media_get_duration( LIBVLC_MEDIA(self), &ex);
97 return Py_BuildValue( "L", i_ret );
101 vlcMedia_media_player_new( PyObject *self, PyObject *args )
103 libvlc_exception_t ex;
104 libvlc_media_player_t *p_mp;
105 vlcMediaPlayer *p_ret;
108 p_mp = libvlc_media_player_new_from_media( LIBVLC_MEDIA(self), &ex);
111 p_ret = PyObject_New( vlcMediaPlayer, &vlcMediaPlayer_Type );
113 Py_INCREF( p_ret ); /* Ah bon ? */
114 return ( PyObject * )p_ret;
118 vlcMedia_is_preparsed( PyObject *self, PyObject *args )
120 libvlc_exception_t ex;
123 i_ret = libvlc_media_is_preparsed( LIBVLC_MEDIA(self), &ex);
125 return Py_BuildValue( "L", i_ret );
129 vlcMedia_get_meta( PyObject *self, PyObject *args )
131 libvlc_exception_t ex;
132 char * psz_meta = NULL;
133 char * psz_ret = NULL;
137 static const char * meta_names[] = { "Title", "Artist", "Genre", "Copyright", "Album", "TrackNumber", "Description", "Rating", "Date", "Setting", "URL", "Language", "NowPlaying", "Publisher", "EncodedBy", "ArtworkURL", "TrackID", NULL };
139 if( !PyArg_ParseTuple( args, "s", &psz_meta ) )
141 while( meta_names[i_loop] )
143 if( !strncmp(meta_names[i_loop], psz_meta, strlen(meta_names[i_loop])) )
152 PyObject *py_exc = vlc_Exception;
153 PyErr_SetString( py_exc, "Unknown meta attribute" );
158 psz_ret = libvlc_media_get_meta( LIBVLC_MEDIA(self), i_index, &ex);
161 o_ret = Py_BuildValue( "s", psz_ret );
166 static PyMethodDef vlcMedia_methods[] =
168 { "add_option", vlcMedia_add_option, METH_VARARGS,
169 "add_option(str) Add an option to the media." },
170 { "get_mrl", vlcMedia_get_mrl, METH_VARARGS,
171 "get_mrl() -> str" },
172 { "get_state", vlcMedia_get_state, METH_VARARGS,
173 "get_state() -> int" },
174 { "get_duration", vlcMedia_get_duration, METH_VARARGS,
175 "get_duration() -> int" },
176 { "mediaplayer_new", vlcMedia_media_player_new, METH_VARARGS,
177 "mediaplayer_new() -> vlc.MediaPlayer Create a MediaPlayer object from a Media" },
178 { "is_preparsed", vlcMedia_is_preparsed, METH_VARARGS,
179 "is_preparsed() -> int" },
180 { "get_meta", vlcMedia_get_meta, METH_VARARGS,
181 "get_meta(str) -> str Read the meta of the media." },
183 { NULL } /* Sentinel */
186 static PyTypeObject vlcMedia_Type =
188 PyObject_HEAD_INIT( NULL )
190 "vlc.Media", /*tp_name*/
191 sizeof( vlcMedia_Type ), /*tp_basicsize*/
193 vlcMedia_dealloc, /*tp_dealloc*/
200 0, /*tp_as_sequence*/
208 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
209 "vlc.Media object.", /* tp_doc */
212 0, /* tp_richcompare */
213 0, /* tp_weaklistoffset */
216 vlcMedia_methods, /* tp_methods */
221 0, /* tp_descr_get */
222 0, /* tp_descr_set */
223 0, /* tp_dictoffset */
226 vlcMedia_new, /* tp_new */