1 /*****************************************************************************
2 * vlc_mediadescriptor.c: vlc.MediaDescriptor binding
3 *****************************************************************************
4 * Copyright (C) 2007 the VideoLAN team
5 * $Id: vlc_input.c 22643 2007-10-17 13:30:02Z funman $
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 vlcMediaDescriptor_dealloc( PyObject *self )
32 libvlc_media_descriptor_release( LIBVLC_MEDIADESCRIPTOR->p_md );
37 vlcMediaDescriptor_add_option( PyObject *self, PyObject *args )
39 libvlc_exception_t ex;
40 char* psz_options = NULL;
42 if( !PyArg_ParseTuple( args, "s", &psz_options ) )
46 libvlc_media_descriptor_add_option( LIBVLC_MEDIADESCRIPTOR->p_md, psz_options, &ex);
53 vlcMediaDescriptor_get_mrl( PyObject *self, PyObject *args )
55 libvlc_exception_t ex;
60 psz_mrl = libvlc_media_descriptor_get_mrl( LIBVLC_MEDIADESCRIPTOR->p_md, &ex);
63 o_ret = Py_BuildValue( "s", psz_mrl );
69 vlcMediaDescriptor_get_state( PyObject *self, PyObject *args )
71 libvlc_exception_t ex;
72 libvlc_state_t i_state;
75 i_state = libvlc_media_descriptor_get_state( LIBVLC_MEDIADESCRIPTOR->p_md, &ex);
77 /* FIXME: return the defined state constant */
78 return Py_BuildValue( "i", i_state );
82 vlcMediaDescriptor_add_tag( PyObject *self, PyObject *args )
84 libvlc_exception_t ex;
88 if( !PyArg_ParseTuple( args, "ss", &psz_key, &psz_tag ) )
92 libvlc_media_descriptor_add_tag( LIBVLC_MEDIADESCRIPTOR->p_md, psz_key, ( libvlc_tag_t )psz_tag, &ex );
99 vlcMediaDescriptor_remove_tag( PyObject *self, PyObject *args )
101 libvlc_exception_t ex;
105 if( !PyArg_ParseTuple( args, "ss", &psz_key, &psz_tag ) )
109 libvlc_media_descriptor_remove_tag( LIBVLC_MEDIADESCRIPTOR->p_md, psz_key, ( libvlc_tag_t )psz_tag, &ex );
111 Py_INCREF( Py_None );
116 vlcMediaDescriptor_tags_count_for_key( PyObject *self, PyObject *args )
118 libvlc_exception_t ex;
122 if( !PyArg_ParseTuple( args, "s", &psz_tag ) )
126 i_ret=libvlc_media_descriptor_tags_count_for_key( LIBVLC_MEDIADESCRIPTOR->p_md, psz_tag, &ex );
128 return Py_BuildValue( "i", i_ret );
132 vlcMediaDescriptor_get_duration( PyObject *self, PyObject *args )
134 libvlc_exception_t ex;
137 i_ret = libvlc_media_descriptor_get_duration( LIBVLC_MEDIADESCRIPTOR->p_md, &ex);
139 return Py_BuildValue( "L", i_ret );
143 vlcMediaDescriptor_media_instance_new( PyObject *self, PyObject *args )
145 libvlc_exception_t ex;
146 libvlc_media_instance_t *p_mi;
147 vlcMediaInstance *p_ret;
150 p_mi = libvlc_media_instance_new_from_media_descriptor( LIBVLC_MEDIADESCRIPTOR->p_md, &ex);
153 p_ret = PyObject_New( vlcMediaInstance, &vlcMediaInstance_Type );
155 Py_INCREF( p_ret ); /* Ah bon ? */
156 return ( PyObject * )p_ret;
160 vlcMediaDescriptor_is_preparsed( PyObject *self, PyObject *args )
162 libvlc_exception_t ex;
165 i_ret = libvlc_media_descriptor_is_preparsed( LIBVLC_MEDIADESCRIPTOR->p_md, &ex);
167 return Py_BuildValue( "L", i_ret );
171 vlcMediaDescriptor_get_meta( PyObject *self, PyObject *args )
173 libvlc_exception_t ex;
174 char * psz_meta = NULL;
175 char * psz_ret = NULL;
179 static const char * meta_names[] = { "Title", "Artist", "Genre", "Copyright", "Album", "TrackNumber", "Description", "Rating", "Date", "Setting", "URL", "Language", "NowPlaying", "Publisher", "EncodedBy", "ArtworkURL", "TrackID", NULL };
181 if( !PyArg_ParseTuple( args, "s", &psz_meta ) )
183 while( !meta_names[i_loop] )
185 if( !strncmp(meta_names[i_loop], psz_meta, strlen(meta_names[i_loop])) )
193 PyObject *py_exc = vlcInstance_Exception;
194 PyErr_SetString( py_exc, "Unknown meta attribute" );
199 psz_ret = libvlc_media_descriptor_get_meta( LIBVLC_MEDIADESCRIPTOR->p_md, i_index, &ex);
202 o_ret = Py_BuildValue( "s", psz_ret );
207 static PyMethodDef vlcMediaDescriptor_methods[] =
209 { "add_option", vlcMediaDescriptor_add_option, METH_VARARGS,
210 "add_option(str) Add an option to the media descriptor." },
211 { "get_mrl", vlcMediaDescriptor_get_mrl, METH_VARARGS,
212 "get_mrl() -> str" },
213 { "get_state", vlcMediaDescriptor_get_state, METH_VARARGS,
214 "get_state() -> int" },
215 { "add_tag", vlcMediaDescriptor_add_tag, METH_VARARGS,
216 "add_tag(key=str, tag=str) Add tag to the media descriptor." },
217 { "remove_tag", vlcMediaDescriptor_remove_tag, METH_VARARGS,
218 "remove_tag(key=str, tag=str) Remove tag from the media descriptor." },
219 { "tags_count_for_key", vlcMediaDescriptor_tags_count_for_key, METH_VARARGS,
220 "tags_count_for_key(str) ." },
221 { "get_duration", vlcMediaDescriptor_get_duration, METH_VARARGS,
222 "get_duration() -> int" },
223 { "mediainstance_new", vlcMediaDescriptor_media_instance_new, METH_VARARGS,
224 "mediainstance_new() -> vlc.MediaInstance Create a Media Instance object from a Media Descriptor" },
225 { "is_preparsed", vlcMediaDescriptor_is_preparsed, METH_VARARGS,
226 "is_preparsed() -> int" },
227 { "get_meta", vlcMediaDescriptor_get_meta, METH_VARARGS,
228 "get_meta(str) -> str Read the meta of the media descriptor." },
230 { NULL } /* Sentinel */
233 static PyTypeObject vlcMediaDescriptor_Type =
235 PyObject_HEAD_INIT( NULL )
237 "vlc.MediaDescriptor", /*tp_name*/
238 sizeof( vlcMediaDescriptor_Type ), /*tp_basicsize*/
240 vlcMediaDescriptor_dealloc, /*tp_dealloc*/
247 0, /*tp_as_sequence*/
255 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
256 "vlc.MediaDescriptor object.", /* tp_doc */
259 0, /* tp_richcompare */
260 0, /* tp_weaklistoffset */
263 vlcMediaDescriptor_methods, /* tp_methods */
268 0, /* tp_descr_get */
269 0, /* tp_descr_set */
270 0, /* tp_dictoffset */