]> git.sesse.net Git - vlc/blob - bindings/python/vlc_media.c
python bindings: rename some files
[vlc] / bindings / python / vlc_media.c
1 /*****************************************************************************
2  * vlc_mediadescriptor.c: vlc.MediaDescriptor binding
3  *****************************************************************************
4  * Copyright (C) 2007 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Olivier Aubert <oaubert at liris.cnrs.fr>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23 #include "vlcglue.h"
24
25 /***********************************************************************
26  * vlc.MediaDescriptor
27  ***********************************************************************/
28
29 static void
30 vlcMediaDescriptor_dealloc( PyObject *self )
31 {
32     libvlc_media_release( LIBVLC_MEDIADESCRIPTOR->p_md );
33     PyObject_DEL( self );
34 }
35
36 static PyObject *
37 vlcMediaDescriptor_add_option( PyObject *self, PyObject *args )
38 {
39     libvlc_exception_t ex;
40     char* psz_options = NULL;
41
42     if( !PyArg_ParseTuple( args, "s", &psz_options ) )
43         return NULL;
44
45     LIBVLC_TRY;
46     libvlc_media_add_option( LIBVLC_MEDIADESCRIPTOR->p_md, psz_options, &ex);
47     LIBVLC_EXCEPT;
48     Py_INCREF( Py_None );
49     return Py_None;
50 }
51
52 static PyObject *
53 vlcMediaDescriptor_get_mrl( PyObject *self, PyObject *args )
54 {
55     libvlc_exception_t ex;
56     char * psz_mrl;
57     PyObject * o_ret;
58
59     LIBVLC_TRY;
60     psz_mrl = libvlc_media_get_mrl( LIBVLC_MEDIADESCRIPTOR->p_md, &ex);
61     LIBVLC_EXCEPT;
62
63     o_ret = Py_BuildValue( "s", psz_mrl );
64     free( psz_mrl );
65     return o_ret;
66 }
67
68 static PyObject *
69 vlcMediaDescriptor_get_state( PyObject *self, PyObject *args )
70 {
71     libvlc_exception_t ex;
72     libvlc_state_t i_state;
73
74     LIBVLC_TRY;
75     i_state = libvlc_media_get_state( LIBVLC_MEDIADESCRIPTOR->p_md, &ex);
76     LIBVLC_EXCEPT;
77     /* FIXME: return the defined state constant */
78     return Py_BuildValue( "i", i_state );
79 }
80
81 static PyObject *
82 vlcMediaDescriptor_add_tag( PyObject *self, PyObject *args )
83 {
84     libvlc_exception_t ex;
85     char* psz_key;
86     char* psz_tag;
87
88     if( !PyArg_ParseTuple( args, "ss", &psz_key, &psz_tag ) )
89         return NULL;
90
91     LIBVLC_TRY;
92     libvlc_media_add_tag( LIBVLC_MEDIADESCRIPTOR->p_md, psz_key, ( libvlc_tag_t )psz_tag, &ex );
93     LIBVLC_EXCEPT;
94     Py_INCREF( Py_None );
95     return Py_None;
96 }
97
98 static PyObject *
99 vlcMediaDescriptor_remove_tag( PyObject *self, PyObject *args )
100 {
101     libvlc_exception_t ex;
102     char* psz_key;
103     char* psz_tag;
104
105     if( !PyArg_ParseTuple( args, "ss", &psz_key, &psz_tag ) )
106         return NULL;
107
108     LIBVLC_TRY;
109     libvlc_media_remove_tag( LIBVLC_MEDIADESCRIPTOR->p_md, psz_key, ( libvlc_tag_t )psz_tag, &ex );
110     LIBVLC_EXCEPT;
111     Py_INCREF( Py_None );
112     return Py_None;
113 }
114
115 static PyObject *
116 vlcMediaDescriptor_tags_count_for_key( PyObject *self, PyObject *args )
117 {
118     libvlc_exception_t ex;
119     char* psz_tag;
120     int i_ret;
121
122     if( !PyArg_ParseTuple( args, "s", &psz_tag ) )
123         return NULL;
124
125     LIBVLC_TRY;
126     i_ret=libvlc_media_tags_count_for_key( LIBVLC_MEDIADESCRIPTOR->p_md, psz_tag, &ex );
127     LIBVLC_EXCEPT;
128     return Py_BuildValue( "i", i_ret );
129 }
130
131 static PyObject *
132 vlcMediaDescriptor_get_duration( PyObject *self, PyObject *args )
133 {
134     libvlc_exception_t ex;
135     libvlc_time_t i_ret;
136     LIBVLC_TRY;
137     i_ret = libvlc_media_get_duration( LIBVLC_MEDIADESCRIPTOR->p_md, &ex);
138     LIBVLC_EXCEPT;
139     return Py_BuildValue( "L", i_ret );
140 }
141
142 static PyObject *
143 vlcMediaDescriptor_media_player_new( PyObject *self, PyObject *args )
144 {
145     libvlc_exception_t ex;
146     libvlc_media_player_t *p_mi;
147     vlcMediaInstance *p_ret;
148
149     LIBVLC_TRY;
150     p_mi = libvlc_media_player_new_from_media( LIBVLC_MEDIADESCRIPTOR->p_md, &ex);
151     LIBVLC_EXCEPT;
152
153     p_ret = PyObject_New( vlcMediaInstance, &vlcMediaInstance_Type );
154     p_ret->p_mi = p_mi;
155     Py_INCREF( p_ret ); /* Ah bon ? */
156     return ( PyObject * )p_ret;
157 }
158
159 static PyObject *
160 vlcMediaDescriptor_is_preparsed( PyObject *self, PyObject *args )
161 {
162     libvlc_exception_t ex;
163     int i_ret;
164     LIBVLC_TRY;
165     i_ret = libvlc_media_is_preparsed( LIBVLC_MEDIADESCRIPTOR->p_md, &ex);
166     LIBVLC_EXCEPT;
167     return Py_BuildValue( "L", i_ret );
168 }
169
170 static PyObject *
171 vlcMediaDescriptor_get_meta( PyObject *self, PyObject *args )
172 {
173     libvlc_exception_t ex;
174     char * psz_meta = NULL;
175     char * psz_ret = NULL;
176     PyObject* o_ret;
177     int i_index = -1;
178     int i_loop = 0;
179     static const char * meta_names[] = { "Title", "Artist", "Genre", "Copyright", "Album", "TrackNumber", "Description", "Rating", "Date", "Setting", "URL", "Language", "NowPlaying", "Publisher", "EncodedBy", "ArtworkURL", "TrackID", NULL };
180
181     if( !PyArg_ParseTuple( args, "s", &psz_meta ) )
182         return NULL;
183     while( meta_names[i_loop] )
184     {
185         if( !strncmp(meta_names[i_loop], psz_meta, strlen(meta_names[i_loop])) )
186         {
187             i_index = i_loop;
188             break;
189         }
190         i_loop++;
191     }
192     if( i_index < 0 )
193     {
194         PyObject *py_exc = vlc_Exception;
195         PyErr_SetString( py_exc, "Unknown meta attribute" );
196         return NULL;
197     }
198
199     LIBVLC_TRY;
200     psz_ret = libvlc_media_get_meta( LIBVLC_MEDIADESCRIPTOR->p_md, i_index, &ex);
201     LIBVLC_EXCEPT;
202
203     o_ret = Py_BuildValue( "s", psz_ret );
204     free( psz_ret );
205     return o_ret;
206 }
207
208 static PyMethodDef vlcMediaDescriptor_methods[] =
209 {
210     { "add_option", vlcMediaDescriptor_add_option, METH_VARARGS,
211       "add_option(str) Add an option to the media descriptor." },
212     { "get_mrl", vlcMediaDescriptor_get_mrl, METH_VARARGS,
213       "get_mrl() -> str" },
214     { "get_state", vlcMediaDescriptor_get_state, METH_VARARGS,
215       "get_state() -> int" },
216     { "add_tag", vlcMediaDescriptor_add_tag, METH_VARARGS,
217       "add_tag(key=str, tag=str) Add tag to the media descriptor." },
218     { "remove_tag", vlcMediaDescriptor_remove_tag, METH_VARARGS,
219       "remove_tag(key=str, tag=str) Remove tag from the media descriptor." },
220     { "tags_count_for_key", vlcMediaDescriptor_tags_count_for_key, METH_VARARGS,
221       "tags_count_for_key(str) ." },
222     { "get_duration", vlcMediaDescriptor_get_duration, METH_VARARGS,
223       "get_duration() -> int" },
224     { "mediainstance_new", vlcMediaDescriptor_media_player_new, METH_VARARGS,
225       "mediainstance_new() -> vlc.MediaInstance   Create a Media Instance object from a Media Descriptor" },
226     { "is_preparsed", vlcMediaDescriptor_is_preparsed, METH_VARARGS,
227       "is_preparsed() -> int" },
228     { "get_meta", vlcMediaDescriptor_get_meta, METH_VARARGS,
229       "get_meta(str) -> str   Read the meta of the media descriptor." },
230     
231     { NULL }  /* Sentinel */
232 };
233
234 static PyTypeObject vlcMediaDescriptor_Type =
235 {
236     PyObject_HEAD_INIT( NULL )
237     0,                         /*ob_size*/
238     "vlc.MediaDescriptor",            /*tp_name*/
239     sizeof( vlcMediaDescriptor_Type ),   /*tp_basicsize*/
240     0,                         /*tp_itemsize*/
241     vlcMediaDescriptor_dealloc, /*tp_dealloc*/
242     0,                         /*tp_print*/
243     0,                         /*tp_getattr*/
244     0,                         /*tp_setattr*/
245     0,                         /*tp_compare*/
246     0,                         /*tp_repr*/
247     0,                         /*tp_as_number*/
248     0,                         /*tp_as_sequence*/
249     0,                         /*tp_as_mapping*/
250     0,                         /*tp_hash */
251     0,                         /*tp_call*/
252     0,                         /*tp_str*/
253     0,                         /*tp_getattro*/
254     0,                         /*tp_setattro*/
255     0,                         /*tp_as_buffer*/
256     Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
257     "vlc.MediaDescriptor object.",  /* tp_doc */
258     0,                        /* tp_traverse */
259     0,                        /* tp_clear */
260     0,                         /* tp_richcompare */
261     0,                         /* tp_weaklistoffset */
262     0,                         /* tp_iter */
263     0,                          /* tp_iternext */
264     vlcMediaDescriptor_methods,          /* tp_methods */
265     0,                         /* tp_members */
266     0,                         /* tp_getset */
267     0,                         /* tp_base */
268     0,                         /* tp_dict */
269     0,                         /* tp_descr_get */
270     0,                         /* tp_descr_set */
271     0,                         /* tp_dictoffset */
272     0,                         /* tp_init */
273     0,                         /* tp_alloc */
274     0,                         /* tp_new */
275 };
276