]> git.sesse.net Git - vlc/blob - bindings/python/vlc_instance.c
23459be8a1ac429388a4b8f497d639e6a8290f4f
[vlc] / bindings / python / vlc_instance.c
1 /*****************************************************************************
2  * vlc_instance.c: vlc.Instance binding
3  *****************************************************************************
4  * Copyright (C) 2006 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Olivier Aubert <oaubert at bat710.univ-lyon1.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 /* Helper functions */
26 static Py_ssize_t
27 pyoptions_to_args(PyObject *py_options, char*** pppsz_args)
28 {
29     Py_ssize_t i_size;
30     Py_ssize_t  i_index;
31     char** ppsz_args = *pppsz_args;
32  
33     ppsz_args = NULL;
34
35     Py_INCREF( py_options );
36     if( ! PySequence_Check( py_options ) )
37     {
38         PyErr_SetString( PyExc_TypeError, "Parameter must be a sequence." );
39         return -1;
40     }
41     i_size = PySequence_Size( py_options );
42     ppsz_args = malloc( ( i_size + 1 ) * sizeof( char * ) );
43     if( ! ppsz_args )
44     {
45         PyErr_SetString( PyExc_MemoryError, "Out of memory" );
46         return -1;
47     }
48
49     for ( i_index = 0; i_index < i_size; i_index++ )
50     {
51         ppsz_args[i_index] =
52             strdup( PyString_AsString( PyObject_Str(
53                                            PySequence_GetItem( py_options,
54                                                                i_index ) ) ) );
55     }
56     ppsz_args[i_size] = NULL;
57     Py_DECREF( py_options );
58     return i_size;
59 }
60
61 static void
62 free_args(int i_size, char** ppsz_args)
63 {
64     int i_index;
65
66     for ( i_index = 0; i_index < i_size; i_index++ )
67         if( ppsz_args[i_index] )
68             free(ppsz_args[i_index]);
69     free( ppsz_args );
70 }
71
72 /*****************************************************************************
73  * Instance object implementation
74  *****************************************************************************/
75
76 static PyObject *
77 vlcInstance_new( PyTypeObject *type, PyObject *args, PyObject *kwds )
78 {
79     vlcInstance *self;
80     libvlc_exception_t ex;
81     PyObject* py_list = NULL;
82     char** ppsz_args = NULL;
83     int i_size = 0;
84
85     if( PyArg_ParseTuple( args, "O", &py_list ) )
86     {
87         i_size = pyoptions_to_args( py_list, &ppsz_args );
88         if( i_size < 0 )
89             return NULL;
90     }
91     else
92     {
93         /* No arguments were given. Clear the exception raised
94            by PyArg_ParseTuple. */
95         PyErr_Clear( );
96     }
97
98     self = PyObject_New( vlcInstance, &vlcInstance_Type );
99
100     Py_BEGIN_ALLOW_THREADS
101     LIBVLC_TRY
102     LIBVLC_INSTANCE->p_instance = libvlc_new( i_size, ppsz_args, &ex );
103     free_args( i_size, ppsz_args );
104     LIBVLC_EXCEPT
105     Py_END_ALLOW_THREADS
106
107     Py_INCREF( self );
108     return ( PyObject * )self;
109 }
110
111 static void
112 vlcInstance_dealloc( PyObject *self )
113 {
114     libvlc_release( LIBVLC_INSTANCE->p_instance );
115     PyObject_DEL( self );
116 }
117
118 static PyObject *
119 vlcInstance_get_vlc_id( PyObject *self, PyObject *args )
120 {
121     return Py_BuildValue( "i", libvlc_get_vlc_id( LIBVLC_INSTANCE->p_instance ) );
122 }
123
124 /* Set loop variable */
125 static PyObject *
126 vlcInstance_playlist_loop( PyObject *self, PyObject *args )
127 {
128     libvlc_exception_t ex;
129     int i_loop = 0;
130
131     if( !PyArg_ParseTuple( args, "i", &i_loop ) )
132         return NULL;
133
134     LIBVLC_TRY;
135     libvlc_playlist_loop( LIBVLC_INSTANCE->p_instance, i_loop, &ex );
136     LIBVLC_EXCEPT;
137
138     Py_INCREF( Py_None );
139     return Py_None;
140 }
141
142 /* Playlist play. 2 parameters: i_id, the id to play
143    l_options: a list of options */
144 static PyObject *
145 vlcInstance_playlist_play( PyObject *self, PyObject *args )
146 {
147     libvlc_exception_t ex;
148     int i_id = -1;
149     PyObject *py_options = NULL;
150     int i_size = 0;
151     char** ppsz_args = NULL;
152
153     if( !PyArg_ParseTuple( args, "|iO", &i_id, &py_options ) )
154         return NULL;
155
156     if( py_options )
157     {
158         i_size = pyoptions_to_args( py_options, &ppsz_args );
159     }
160
161     LIBVLC_TRY;
162     libvlc_playlist_play( LIBVLC_INSTANCE->p_instance, i_id, i_size, ppsz_args, &ex );
163     free_args( i_size, ppsz_args );
164     LIBVLC_EXCEPT;
165
166     Py_INCREF( Py_None );
167     return Py_None;
168 }
169
170 static PyObject *
171 vlcInstance_playlist_pause( PyObject *self, PyObject *args )
172 {
173     libvlc_exception_t ex;
174     LIBVLC_TRY;
175     libvlc_playlist_pause( LIBVLC_INSTANCE->p_instance, &ex );
176     LIBVLC_EXCEPT;
177     Py_INCREF( Py_None );
178     return Py_None;
179 }
180
181 static PyObject *
182 vlcInstance_playlist_isplaying( PyObject *self, PyObject *args )
183 {
184     libvlc_exception_t ex;
185     int i_ret;
186
187     LIBVLC_TRY;
188     i_ret = libvlc_playlist_isplaying( LIBVLC_INSTANCE->p_instance, &ex );
189     LIBVLC_EXCEPT;
190     return Py_BuildValue( "i", i_ret );
191 }
192
193 static PyObject *
194 vlcInstance_playlist_items_count( PyObject *self, PyObject *args )
195 {
196     libvlc_exception_t ex;
197     int i_ret;
198
199     LIBVLC_TRY;
200     i_ret = libvlc_playlist_items_count( LIBVLC_INSTANCE->p_instance, &ex );
201     LIBVLC_EXCEPT;
202     return Py_BuildValue( "i", i_ret );
203 }
204
205 static PyObject *
206 vlcInstance_playlist_stop( PyObject *self, PyObject *args )
207 {
208     libvlc_exception_t ex;
209     LIBVLC_TRY;
210     libvlc_playlist_stop( LIBVLC_INSTANCE->p_instance, &ex );
211     LIBVLC_EXCEPT;
212     Py_INCREF( Py_None );
213     return Py_None;
214 }
215
216 static PyObject *
217 vlcInstance_playlist_next( PyObject *self, PyObject *args )
218 {
219     libvlc_exception_t ex;
220     LIBVLC_TRY;
221     libvlc_playlist_next( LIBVLC_INSTANCE->p_instance, &ex );
222     LIBVLC_EXCEPT;
223     Py_INCREF( Py_None );
224     return Py_None;
225 }
226
227 static PyObject *
228 vlcInstance_playlist_prev( PyObject *self, PyObject *args )
229 {
230     libvlc_exception_t ex;
231     LIBVLC_TRY;
232     libvlc_playlist_prev( LIBVLC_INSTANCE->p_instance, &ex );
233     LIBVLC_EXCEPT;
234     Py_INCREF( Py_None );
235     return Py_None;
236 }
237
238 static PyObject *
239 vlcInstance_playlist_clear( PyObject *self, PyObject *args )
240 {
241     libvlc_exception_t ex;
242     LIBVLC_TRY;
243     libvlc_playlist_clear( LIBVLC_INSTANCE->p_instance, &ex );
244     LIBVLC_EXCEPT;
245     Py_INCREF( Py_None );
246     return Py_None;
247 }
248
249 /* Add a playlist item. Main parameter: URI.
250    Optional parameters: name, options */
251 static PyObject *
252 vlcInstance_playlist_add( PyObject *self, PyObject *args)
253 {
254     libvlc_exception_t ex;
255     int i_ret;
256     char* psz_uri = NULL;
257     char* psz_name = NULL;
258     PyObject *py_options = NULL;
259     int i_size = 0;
260     char** ppsz_args = NULL;
261
262     if( !PyArg_ParseTuple( args, "s|sO", &psz_uri, &psz_name, &py_options ) )
263         return NULL;
264
265     if( !psz_name )
266     {
267         /* Set a default name */
268         psz_name = strdup( psz_uri );
269     }
270
271     if( py_options )
272     {
273         i_size = pyoptions_to_args( py_options, &ppsz_args );
274     }
275
276     LIBVLC_TRY;
277     if( ppsz_args )
278     {
279         i_ret = libvlc_playlist_add_extended( LIBVLC_INSTANCE->p_instance,
280                                               psz_uri,
281                                               psz_name,
282                                               i_size,
283                                               ppsz_args,
284                                               &ex );
285         free_args( i_size, ppsz_args );
286     }
287     else
288     {
289         i_ret = libvlc_playlist_add( LIBVLC_INSTANCE->p_instance,
290                                      psz_uri,
291                                      psz_name,
292                                      &ex );
293     }
294     LIBVLC_EXCEPT;
295
296     return Py_BuildValue( "i", i_ret );
297 }
298
299 static PyObject *
300 vlcInstance_playlist_delete_item( PyObject *self, PyObject *args )
301 {
302     libvlc_exception_t ex;
303     int i_id;
304     int i_ret;
305
306     if( !PyArg_ParseTuple( args, "i", &i_id ) )
307         return NULL;
308
309     LIBVLC_TRY;
310     i_ret = libvlc_playlist_delete_item( LIBVLC_INSTANCE->p_instance, i_id, &ex );
311     LIBVLC_EXCEPT;
312
313     return Py_BuildValue( "i", i_ret );
314 }
315
316 static PyObject *
317 vlcInstance_playlist_get_media_instance( PyObject *self, PyObject *args )
318 {
319     libvlc_exception_t ex;
320     libvlc_media_instance_t *p_mi;
321     vlcMediaInstance *p_ret;
322
323     LIBVLC_TRY;
324     p_mi = libvlc_playlist_get_media_instance( LIBVLC_INSTANCE->p_instance, &ex );
325     LIBVLC_EXCEPT;
326
327     p_ret = PyObject_New( vlcMediaInstance, &vlcMediaInstance_Type );
328     p_ret->p_mi = p_mi;
329     Py_INCREF( p_ret ); /* Ah bon ? */
330     return ( PyObject * )p_ret;
331 }
332
333 static PyObject *
334 vlcInstance_video_set_parent( PyObject *self, PyObject *args )
335 {
336     libvlc_exception_t ex;
337     int i_drawable;
338
339     if( !PyArg_ParseTuple( args, "i", &i_drawable ) )
340         return NULL;
341
342     LIBVLC_TRY;
343     libvlc_video_set_parent( LIBVLC_INSTANCE->p_instance, (libvlc_drawable_t) i_drawable, &ex );
344     LIBVLC_EXCEPT;
345
346     Py_INCREF( Py_None );
347     return Py_None;
348 }
349
350 static PyObject *
351 vlcInstance_video_get_parent( PyObject *self, PyObject *args )
352 {
353     libvlc_exception_t ex;
354     libvlc_drawable_t i_ret;
355
356     LIBVLC_TRY;
357     i_ret = libvlc_video_get_parent( LIBVLC_INSTANCE->p_instance, &ex );
358     LIBVLC_EXCEPT;
359
360     return Py_BuildValue( "L", i_ret );
361 }
362
363 static PyObject *
364 vlcInstance_video_set_size( PyObject *self, PyObject *args )
365 {
366     libvlc_exception_t ex;
367     int i_width;
368     int i_height;
369
370     if( !PyArg_ParseTuple( args, "ii", &i_width, &i_height ) )
371         return NULL;
372
373     LIBVLC_TRY;
374     libvlc_video_set_size( LIBVLC_INSTANCE->p_instance, i_width, i_height, &ex );
375     LIBVLC_EXCEPT;
376
377     Py_INCREF( Py_None );
378     return Py_None;
379 }
380
381 static PyObject *
382 vlcInstance_audio_toggle_mute( PyObject *self, PyObject *args )
383 {
384     libvlc_exception_t ex;
385     LIBVLC_TRY;
386     libvlc_audio_toggle_mute( LIBVLC_INSTANCE->p_instance, &ex );
387     LIBVLC_EXCEPT;
388     Py_INCREF( Py_None );
389     return Py_None;
390 }
391
392 static PyObject *
393 vlcInstance_audio_get_mute( PyObject *self, PyObject *args )
394 {
395     libvlc_exception_t ex;
396     int i_ret;
397
398     LIBVLC_TRY;
399     i_ret = libvlc_audio_get_mute( LIBVLC_INSTANCE->p_instance, &ex );
400     LIBVLC_EXCEPT;
401     return Py_BuildValue( "i", i_ret );
402 }
403
404 static PyObject *
405 vlcInstance_audio_set_mute( PyObject *self, PyObject *args )
406 {
407     libvlc_exception_t ex;
408     int i_mute;
409
410     if( !PyArg_ParseTuple( args, "i", &i_mute ) )
411         return NULL;
412
413     LIBVLC_TRY;
414     libvlc_audio_set_mute( LIBVLC_INSTANCE->p_instance, i_mute, &ex );
415     LIBVLC_EXCEPT;
416     Py_INCREF( Py_None );
417     return Py_None;
418 }
419
420 static PyObject *
421 vlcInstance_audio_get_volume( PyObject *self, PyObject *args )
422 {
423     libvlc_exception_t ex;
424     int i_ret;
425
426     LIBVLC_TRY;
427     i_ret = libvlc_audio_get_volume( LIBVLC_INSTANCE->p_instance, &ex );
428     LIBVLC_EXCEPT;
429     return Py_BuildValue( "i", i_ret );
430 }
431
432 static PyObject *
433 vlcInstance_audio_set_volume( PyObject *self, PyObject *args )
434 {
435     libvlc_exception_t ex;
436     int i_volume;
437
438     if( !PyArg_ParseTuple( args, "i", &i_volume ) )
439         return NULL;
440
441     LIBVLC_TRY;
442     libvlc_audio_set_volume( LIBVLC_INSTANCE->p_instance, i_volume, &ex );
443     LIBVLC_EXCEPT;
444     Py_INCREF( Py_None );
445     return Py_None;
446 }
447
448 static PyObject *
449 vlcInstance_audio_get_channel( PyObject *self, PyObject *args )
450 {
451     libvlc_exception_t ex;
452     int i_ret;
453
454     LIBVLC_TRY;
455     i_ret = libvlc_audio_get_channel( LIBVLC_INSTANCE->p_instance, &ex );
456     LIBVLC_EXCEPT;
457     return Py_BuildValue( "i", i_ret );
458 }
459
460 static PyObject *
461 vlcInstance_audio_set_channel( PyObject *self, PyObject *args )
462 {
463     libvlc_exception_t ex;
464     int i_channel;
465
466     if( !PyArg_ParseTuple( args, "i", &i_channel ) )
467         return NULL;
468
469     LIBVLC_TRY;
470     libvlc_audio_set_channel( LIBVLC_INSTANCE->p_instance, i_channel, &ex );
471     LIBVLC_EXCEPT;
472     Py_INCREF( Py_None );
473     return Py_None;
474 }
475
476 /* vlm_add_broadcast : name, input MRL, output MRL
477    Keywords: options, enable, loop */
478 static PyObject *
479 vlcInstance_vlm_add_broadcast( PyObject *self, PyObject *args, PyObject *kwds )
480 {
481     libvlc_exception_t ex;
482     static char *kwlist[] = { "name", "input", "output",
483                               "options", "enable", "loop", NULL};
484     char* psz_name = NULL;
485     char* psz_input = NULL;
486     char* psz_output = NULL;
487     PyObject* py_options = NULL;
488     int i_enable = 1;
489     int i_loop = 0;
490     int i_size = 0;
491     char** ppsz_args = NULL;
492
493     if( !PyArg_ParseTupleAndKeywords( args, kwds, "sss|Oii", kwlist,
494                                       &psz_name,
495                       &psz_input, &psz_output,
496                       &py_options, &i_enable, &i_loop ) )
497         return NULL;
498  
499     if( py_options )
500     {
501         i_size = pyoptions_to_args( py_options, &ppsz_args );
502     }
503  
504     LIBVLC_TRY;
505     libvlc_vlm_add_broadcast( LIBVLC_INSTANCE->p_instance,
506                               psz_name, psz_input, psz_output,
507                               i_size, ppsz_args, i_enable, i_loop, &ex);
508     free_args( i_size, ppsz_args );
509     LIBVLC_EXCEPT;
510     Py_INCREF( Py_None );
511     return Py_None;
512 }
513
514 static PyObject *
515 vlcInstance_vlm_del_media( PyObject *self, PyObject *args )
516 {
517     libvlc_exception_t ex;
518     char* psz_name;
519
520     if( !PyArg_ParseTuple( args, "s", &psz_name ) )
521         return NULL;
522
523     LIBVLC_TRY;
524     libvlc_vlm_del_media( LIBVLC_INSTANCE->p_instance, psz_name, &ex);
525     LIBVLC_EXCEPT;
526     Py_INCREF( Py_None );
527     return Py_None;
528 }
529
530 static PyObject *
531 vlcInstance_vlm_set_enabled( PyObject *self, PyObject *args )
532 {
533     libvlc_exception_t ex;
534     char* psz_name;
535     int i_enabled;
536  
537     if( !PyArg_ParseTuple( args, "si", &psz_name, &i_enabled ) )
538         return NULL;
539
540     LIBVLC_TRY;
541     libvlc_vlm_set_enabled( LIBVLC_INSTANCE->p_instance, psz_name, i_enabled, &ex);
542     LIBVLC_EXCEPT;
543     Py_INCREF( Py_None );
544     return Py_None;
545 }
546
547 static PyObject *
548 vlcInstance_vlm_set_output( PyObject *self, PyObject *args )
549 {
550     libvlc_exception_t ex;
551     char* psz_name;
552     char* psz_output;
553  
554     if( !PyArg_ParseTuple( args, "ss", &psz_name, &psz_output ) )
555         return NULL;
556
557     LIBVLC_TRY;
558     libvlc_vlm_set_output( LIBVLC_INSTANCE->p_instance, psz_name, psz_output, &ex);
559     LIBVLC_EXCEPT;
560     Py_INCREF( Py_None );
561     return Py_None;
562 }
563
564 static PyObject *
565 vlcInstance_vlm_set_input( PyObject *self, PyObject *args )
566 {
567     libvlc_exception_t ex;
568     char* psz_name;
569     char* psz_input;
570  
571     if( !PyArg_ParseTuple( args, "ss", &psz_name, &psz_input ) )
572         return NULL;
573
574     LIBVLC_TRY;
575     libvlc_vlm_set_input( LIBVLC_INSTANCE->p_instance, psz_name, psz_input, &ex);
576     LIBVLC_EXCEPT;
577     Py_INCREF( Py_None );
578     return Py_None;
579 }
580
581 static PyObject *
582 vlcInstance_vlm_add_input( PyObject *self, PyObject *args )
583 {
584     libvlc_exception_t ex;
585     char* psz_name;
586     char* psz_input;
587  
588     if( !PyArg_ParseTuple( args, "ss", &psz_name, &psz_input ) )
589         return NULL;
590
591     LIBVLC_TRY;
592     libvlc_vlm_add_input( LIBVLC_INSTANCE->p_instance, psz_name, psz_input, &ex);
593     LIBVLC_EXCEPT;
594     Py_INCREF( Py_None );
595     return Py_None;
596 }
597
598 static PyObject *
599 vlcInstance_vlm_set_loop( PyObject *self, PyObject *args )
600 {
601     libvlc_exception_t ex;
602     char* psz_name;
603     int i_loop;
604  
605     if( !PyArg_ParseTuple( args, "si", &psz_name, &i_loop ) )
606         return NULL;
607
608     LIBVLC_TRY;
609     libvlc_vlm_set_loop( LIBVLC_INSTANCE->p_instance, psz_name, i_loop, &ex);
610     LIBVLC_EXCEPT;
611     Py_INCREF( Py_None );
612     return Py_None;
613 }
614
615 static PyObject *
616 vlcInstance_vlm_change_media( PyObject *self, PyObject *args, PyObject *kwds )
617 {
618     libvlc_exception_t ex;
619     static char *kwlist[] = { "name", "input", "output",
620                               "options", "enable", "loop", NULL};
621     char* psz_name = NULL;
622     char* psz_input = NULL;
623     char* psz_output = NULL;
624     PyObject* py_options = NULL;
625     int i_enable = 1;
626     int i_loop = 0;
627     int i_size = 0;
628     char** ppsz_args = NULL;
629
630     if( !PyArg_ParseTupleAndKeywords( args, kwds, "sss|Oii", kwlist,
631                                       &psz_name,
632                       &psz_input, &psz_output,
633                       &py_options, &i_enable, &i_loop ) )
634         return NULL;
635  
636     if( py_options )
637     {
638         i_size = pyoptions_to_args( py_options, &ppsz_args );
639     }
640  
641     LIBVLC_TRY;
642     libvlc_vlm_change_media( LIBVLC_INSTANCE->p_instance,
643                               psz_name, psz_input, psz_output,
644                               i_size, ppsz_args, i_enable, i_loop, &ex);
645     free_args( i_size, ppsz_args );
646     LIBVLC_EXCEPT;
647     Py_INCREF( Py_None );
648     return Py_None;
649 }
650
651 static PyObject *
652 vlcInstance_vlm_play_media( PyObject *self, PyObject *args )
653 {
654     libvlc_exception_t ex;
655     char* psz_name;
656  
657     if( !PyArg_ParseTuple( args, "s", &psz_name ) )
658         return NULL;
659
660     LIBVLC_TRY;
661     libvlc_vlm_play_media( LIBVLC_INSTANCE->p_instance, psz_name, &ex);
662     LIBVLC_EXCEPT;
663     Py_INCREF( Py_None );
664     return Py_None;
665 }
666
667 static PyObject *
668 vlcInstance_vlm_stop_media( PyObject *self, PyObject *args )
669 {
670     libvlc_exception_t ex;
671     char* psz_name;
672
673     if( !PyArg_ParseTuple( args, "s", &psz_name ) )
674         return NULL;
675
676     LIBVLC_TRY;
677     libvlc_vlm_stop_media( LIBVLC_INSTANCE->p_instance, psz_name, &ex);
678     LIBVLC_EXCEPT;
679     Py_INCREF( Py_None );
680     return Py_None;
681 }
682
683 static PyObject *
684 vlcInstance_vlm_pause_media( PyObject *self, PyObject *args )
685 {
686     libvlc_exception_t ex;
687     char* psz_name;
688  
689     if( !PyArg_ParseTuple( args, "s", &psz_name ) )
690         return NULL;
691
692     LIBVLC_TRY;
693     libvlc_vlm_pause_media( LIBVLC_INSTANCE->p_instance, psz_name, &ex);
694     LIBVLC_EXCEPT;
695     Py_INCREF( Py_None );
696     return Py_None;
697 }
698
699 static PyObject *
700 vlcInstance_vlm_seek_media( PyObject *self, PyObject *args )
701 {
702     libvlc_exception_t ex;
703     char* psz_name;
704     float f_percentage;
705  
706     if( !PyArg_ParseTuple( args, "sf", &psz_name, &f_percentage ) )
707         return NULL;
708
709     LIBVLC_TRY;
710     libvlc_vlm_seek_media( LIBVLC_INSTANCE->p_instance, psz_name, f_percentage, &ex);
711     LIBVLC_EXCEPT;
712     Py_INCREF( Py_None );
713     return Py_None;
714 }
715
716 static PyObject *
717 vlcInstance_vlm_show_media( PyObject *self, PyObject *args )
718 {
719     libvlc_exception_t ex;
720     char* psz_name;
721     char* psz_ret;
722     PyObject* o_ret;
723
724     if( !PyArg_ParseTuple( args, "s", &psz_name ) )
725         return NULL;
726     LIBVLC_TRY;
727     psz_ret = libvlc_vlm_show_media( LIBVLC_INSTANCE->p_instance, psz_name, &ex );
728     LIBVLC_EXCEPT;
729     o_ret = Py_BuildValue( "s", psz_ret );
730     free( psz_ret );
731     return o_ret;
732 }
733
734 static PyObject *
735 vlcInstance_media_descriptor_new( PyObject *self, PyObject *args )
736 {
737     libvlc_exception_t ex;
738     libvlc_media_descriptor_t *p_md;
739     char* psz_mrl = NULL;
740     vlcMediaDescriptor *p_ret;
741
742     if( !PyArg_ParseTuple( args, "s", &psz_mrl ) )
743         return NULL;
744
745     LIBVLC_TRY;
746     p_md = libvlc_media_descriptor_new( LIBVLC_INSTANCE->p_instance, psz_mrl, &ex );
747     LIBVLC_EXCEPT;
748
749     p_ret = PyObject_New( vlcMediaDescriptor, &vlcMediaDescriptor_Type );
750     p_ret->p_md = p_md;
751     Py_INCREF( p_ret ); /* Ah bon ? */
752     return ( PyObject * )p_ret;
753 }
754
755 /* Method table */
756 static PyMethodDef vlcInstance_methods[] =
757 {
758     { "get_vlc_id", vlcInstance_get_vlc_id, METH_VARARGS,
759       "get_vlc_id( ) -> int        Get the instance id."},
760     { "playlist_loop", vlcInstance_playlist_loop, METH_VARARGS,
761       "playlist_loop(bool)         Set loop variable" },
762     { "playlist_play", vlcInstance_playlist_play, METH_VARARGS,
763       "playlist_play(id=int, options=list)   Play the given playlist item (-1 for current item) with optional options (a list of strings)" },
764     { "playlist_pause", vlcInstance_playlist_pause, METH_VARARGS,
765       "playlist_pause()            Pause the current stream"},
766     { "playlist_isplaying", vlcInstance_playlist_isplaying, METH_VARARGS,
767       "playlist_isplaying() -> int     Return True if the playlist if playing"},
768     { "playlist_items_count", vlcInstance_playlist_items_count, METH_VARARGS,
769       "playlist_items_count() -> int   Return the number of items in the playlist"},
770     { "playlist_stop", vlcInstance_playlist_stop, METH_VARARGS,
771       "playlist_stop()             Stop the current stream"},
772     { "playlist_next", vlcInstance_playlist_next, METH_VARARGS,
773       "playlist_next()             Play the next item"},
774     { "playlist_prev", vlcInstance_playlist_prev, METH_VARARGS,
775       "playlist_prev()             Play the previous item"},
776     { "playlist_clear", vlcInstance_playlist_clear, METH_VARARGS,
777       "playlist_clear()            Clear the playlist"},
778     { "playlist_add", vlcInstance_playlist_add, METH_VARARGS,
779       "playlist_add(mrl=str, name=str, options=list) -> int  Add a new item to the playlist. options is a list of strings."},
780     { "playlist_delete_item", vlcInstance_playlist_delete_item, METH_VARARGS,
781       "playlist_delete_item(id=int)   Delete the given item"},
782     { "playlist_get_media_instance", vlcInstance_playlist_get_media_instance, METH_VARARGS,
783       "playlist_get_media_instance() -> object   Return the current media instance"},
784     { "video_set_parent", vlcInstance_video_set_parent, METH_VARARGS,
785       "video_set_parent(xid=int)       Set the parent xid/HWND/CGrafPort"},
786     { "video_get_parent", vlcInstance_video_get_parent, METH_VARARGS,
787       "video_get_parent(xid=int)       Get the parent xid/HWND/CGrafPort"},
788     { "video_set_size", vlcInstance_video_set_size, METH_VARARGS,
789       "video_set_size(width=int, height=int)    Set the video width and height"},
790     { "audio_toggle_mute", vlcInstance_audio_toggle_mute, METH_VARARGS,
791       "audio_toggle_mute()         Toggle the mute state"},
792     { "audio_get_mute", vlcInstance_audio_get_mute, METH_VARARGS,
793       "audio_get_mute() -> int     Get the mute state"},
794     { "audio_set_mute", vlcInstance_audio_set_mute, METH_VARARGS,
795       "audio_set_mute(state=int)         Set the mute state"},
796     { "audio_get_volume", vlcInstance_audio_get_volume, METH_VARARGS,
797       "audio_get_volume() -> int   Get the audio volume"},
798     { "audio_set_volume", vlcInstance_audio_set_volume, METH_VARARGS,
799       "audio_set_volume(volume=int)       Set the audio volume"},
800     { "audio_get_channel", vlcInstance_audio_get_channel, METH_VARARGS,
801       "audio_get_channel() -> int  Get current audio channel" },
802     { "audio_set_channel", vlcInstance_audio_set_channel, METH_VARARGS,
803       "audio_set_channel(int)      Set current audio channel" },
804
805     { "media_descriptor_new", vlcInstance_media_descriptor_new, METH_VARARGS,
806       "media_descriptor_new(str) -> object   Create a media descriptor with the given mrl."},
807
808     { "vlm_add_broadcast", vlcInstance_vlm_add_broadcast, METH_VARARGS | METH_KEYWORDS,
809       "vlm_add_broadcast(name=str, input=str, output=str, options=list, enable=int, loop=int)   Add a new broadcast" },
810     { "vlm_del_media", vlcInstance_vlm_del_media, METH_VARARGS,
811       "vlm_del_media(name=str)    Delete a media" },
812     { "vlm_set_enabled", vlcInstance_vlm_set_enabled, METH_VARARGS,
813       "vlm_set_enabled(name=str, enabled=int)    Enable/disable a media" },
814     { "vlm_set_output", vlcInstance_vlm_set_output, METH_VARARGS,
815       "vlm_set_output(name=str, output=str)      Set the output" },
816     { "vlm_set_input", vlcInstance_vlm_set_input, METH_VARARGS,
817       "vlm_set_input(name=str, output=str)       Set the input" },
818     { "vlm_add_input", vlcInstance_vlm_add_input, METH_VARARGS,
819       "vlm_add_input(name=str, output=str)       Add a media's input MRL" },
820     { "vlm_set_loop", vlcInstance_vlm_set_loop, METH_VARARGS,
821       "vlm_set_loop(name=str, loop=int)          Change the looping value" },
822     { "vlm_change_media", vlcInstance_vlm_change_media, METH_VARARGS | METH_KEYWORDS,
823       "vlm_change_media(name=str, input=str, output=str, options=list, enable=int, loop=int)   Change the broadcast parameters" },
824     { "vlm_play_media", vlcInstance_vlm_play_media, METH_VARARGS,
825       "vlm_play_media(name=str)       Plays the named broadcast." },
826     { "vlm_stop_media", vlcInstance_vlm_stop_media, METH_VARARGS,
827       "vlm_stop_media(name=str)       Stops the named broadcast." },
828     { "vlm_pause_media", vlcInstance_vlm_pause_media, METH_VARARGS,
829       "vlm_pause_media(name=str)      Pauses the named broadcast." },
830     { "vlm_seek_media", vlcInstance_vlm_seek_media, METH_VARARGS,
831       "vlm_seek_media(name=str, percentage=float)  Seeks in the named broadcast." },
832     { "vlm_show_media", vlcInstance_vlm_show_media, METH_VARARGS,
833       "vlm_show_media(name=str)       Return information of the named broadcast." },
834
835     { NULL, NULL, 0, NULL },
836 };
837
838 static PyTypeObject vlcInstance_Type =
839 {
840     PyObject_HEAD_INIT( NULL )
841     0,                          /*ob_size*/
842     "vlc.Instance",             /*tp_name*/
843     sizeof( vlcInstance_Type ), /*tp_basicsize*/
844     0,                          /*tp_itemsize*/
845     ( destructor )vlcInstance_dealloc,      /*tp_dealloc*/
846     0,                         /*tp_print*/
847     0,                         /*tp_getattr*/
848     0,                         /*tp_setattr*/
849     0,                         /*tp_compare*/
850     0,                         /*tp_repr*/
851     0,                         /*tp_as_number*/
852     0,                         /*tp_as_sequence*/
853     0,                         /*tp_as_mapping*/
854     0,                         /*tp_hash */
855     0,                         /*tp_call*/
856     0,                         /*tp_str*/
857     0,                         /*tp_getattro*/
858     0,                         /*tp_setattro*/
859     0,                         /*tp_as_buffer*/
860     Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
861     "VLC Instance(args)\n\nNote: if args is specified, the first arg is interpreted as an executable name to get the directory of the VLC plugins.",  /* tp_doc */
862     0,                     /* tp_traverse */
863     0,                     /* tp_clear */
864     0,                     /* tp_richcompare */
865     0,                     /* tp_weaklistoffset */
866     0,                     /* tp_iter */
867     0,                     /* tp_iternext */
868     vlcInstance_methods,             /* tp_methods */
869     0,             /* tp_members */
870     0,                         /* tp_getset */
871     0,                         /* tp_base */
872     0,                         /* tp_dict */
873     0,                         /* tp_descr_get */
874     0,                         /* tp_descr_set */
875     0,                         /* tp_dictoffset */
876     0,                         /* tp_init */
877     0,                         /* tp_alloc */
878     vlcInstance_new,          /* tp_new */
879 };