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