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