vlc_instance.c 24.4 KB
Newer Older
1 2 3 4
/*****************************************************************************
 * vlc_instance.c: vlc.Instance binding
 *****************************************************************************
 * Copyright (C) 2006 the VideoLAN team
5
 * $Id$
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
 *
 * Authors: Olivier Aubert <oaubert at bat710.univ-lyon1.fr>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/
#include "vlcglue.h"

25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
/* Helper functions */
static int
pyoptions_to_args(PyObject *py_options, char*** pppsz_args)
{
    int i_size;
    int i_index;
    char** ppsz_args = *pppsz_args;
    
    ppsz_args = NULL;

    Py_INCREF( py_options );
    if( ! PySequence_Check( py_options ) )
    {
        PyErr_SetString( PyExc_TypeError, "Parameter must be a sequence." );
        return -1;
    }
    i_size = PySequence_Size( py_options );
    ppsz_args = malloc( ( i_size + 1 ) * sizeof( char * ) );
    if( ! ppsz_args )
    {
        PyErr_SetString( PyExc_MemoryError, "Out of memory" );
        return -1;
    }

    for ( i_index = 0; i_index < i_size; i_index++ )
    {
        ppsz_args[i_index] =
            strdup( PyString_AsString( PyObject_Str(
                                           PySequence_GetItem( py_options,
                                                               i_index ) ) ) );
    }
    ppsz_args[i_size] = NULL;
    Py_DECREF( py_options );
    return i_size;
}

static void
free_args(int i_size, char** ppsz_args)
{
    int i_index;

    for ( i_index = 0; i_index < i_size; i_index++ )
        if( ppsz_args[i_index] )
            free(ppsz_args[i_index]);
    free( ppsz_args );
}

72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
/*****************************************************************************
 * Instance object implementation
 *****************************************************************************/

static PyObject *
vlcInstance_new( PyTypeObject *type, PyObject *args, PyObject *kwds )
{
    vlcInstance *self;
    libvlc_exception_t ex;
    PyObject* py_list = NULL;
    char** ppsz_args = NULL;
    int i_size = 0;

    self = PyObject_New( vlcInstance, &vlcInstance_Type );

87

88 89
    if( PyArg_ParseTuple( args, "O", &py_list ) )
    {
90 91
        i_size = pyoptions_to_args( py_list, &ppsz_args );
        if( i_size < 0 )
92 93 94 95 96 97 98 99 100 101 102 103
            return NULL;
    }
    else
    {
        /* No arguments were given. Clear the exception raised
           by PyArg_ParseTuple. */
        PyErr_Clear( );
    }

    Py_BEGIN_ALLOW_THREADS
    LIBVLC_TRY
    LIBVLC_INSTANCE->p_instance = libvlc_new( i_size, ppsz_args, &ex );
104
    free_args( i_size, ppsz_args );
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
    LIBVLC_EXCEPT
    Py_END_ALLOW_THREADS

    Py_INCREF( self );
    return ( PyObject * )self;
}

static void
vlcInstance_dealloc( PyObject *self )
{
    libvlc_exception_t ex;
    libvlc_destroy( LIBVLC_INSTANCE->p_instance, &ex );
    PyMem_DEL( self );
}

static PyObject *
vlcInstance_get_vlc_id( PyObject *self, PyObject *args )
{
    return Py_BuildValue( "i", libvlc_get_vlc_id( LIBVLC_INSTANCE->p_instance ) );
}

126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
/* Set loop variable */
static PyObject *
vlcInstance_playlist_loop( PyObject *self, PyObject *args )
{
    libvlc_exception_t ex;
    int i_loop = 0;

    if( !PyArg_ParseTuple( args, "i", &i_loop ) )
        return NULL;

    LIBVLC_TRY;
    libvlc_playlist_loop( LIBVLC_INSTANCE->p_instance, i_loop, &ex );
    LIBVLC_EXCEPT;

    Py_INCREF( Py_None );
    return Py_None;
}

144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
/* Playlist play. 2 parameters: i_id, the id to play
   l_options: a list of options */
static PyObject *
vlcInstance_playlist_play( PyObject *self, PyObject *args )
{
    libvlc_exception_t ex;
    int i_id = -1;
    PyObject *py_options = NULL;
    int i_size = 0;
    char** ppsz_args = NULL;

    if( !PyArg_ParseTuple( args, "|iO", &i_id, &py_options ) )
        return NULL;

    if( py_options )
159 160
    {        
        i_size = pyoptions_to_args( py_options, &ppsz_args );
161 162 163 164
    }

    LIBVLC_TRY;
    libvlc_playlist_play( LIBVLC_INSTANCE->p_instance, i_id, i_size, ppsz_args, &ex );
165
    free_args( i_size, ppsz_args );
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
    LIBVLC_EXCEPT;

    Py_INCREF( Py_None );
    return Py_None;
}

static PyObject *
vlcInstance_playlist_pause( PyObject *self, PyObject *args )
{
    libvlc_exception_t ex;
    LIBVLC_TRY;
    libvlc_playlist_pause( LIBVLC_INSTANCE->p_instance, &ex );
    LIBVLC_EXCEPT;
    Py_INCREF( Py_None );
    return Py_None;
}

static PyObject *
vlcInstance_playlist_isplaying( PyObject *self, PyObject *args )
{
    libvlc_exception_t ex;
    int i_ret;

    LIBVLC_TRY;
    i_ret = libvlc_playlist_isplaying( LIBVLC_INSTANCE->p_instance, &ex );
    LIBVLC_EXCEPT;
    return Py_BuildValue( "i", i_ret );
}

static PyObject *
vlcInstance_playlist_items_count( PyObject *self, PyObject *args )
{
    libvlc_exception_t ex;
    int i_ret;

    LIBVLC_TRY;
    i_ret = libvlc_playlist_items_count( LIBVLC_INSTANCE->p_instance, &ex );
    LIBVLC_EXCEPT;
    return Py_BuildValue( "i", i_ret );
}

static PyObject *
vlcInstance_playlist_stop( PyObject *self, PyObject *args )
{
    libvlc_exception_t ex;
    LIBVLC_TRY;
    libvlc_playlist_stop( LIBVLC_INSTANCE->p_instance, &ex );
    LIBVLC_EXCEPT;
    Py_INCREF( Py_None );
    return Py_None;
}

static PyObject *
vlcInstance_playlist_next( PyObject *self, PyObject *args )
{
    libvlc_exception_t ex;
    LIBVLC_TRY;
    libvlc_playlist_next( LIBVLC_INSTANCE->p_instance, &ex );
    LIBVLC_EXCEPT;
    Py_INCREF( Py_None );
    return Py_None;
}

static PyObject *
vlcInstance_playlist_prev( PyObject *self, PyObject *args )
{
    libvlc_exception_t ex;
    LIBVLC_TRY;
    libvlc_playlist_prev( LIBVLC_INSTANCE->p_instance, &ex );
    LIBVLC_EXCEPT;
    Py_INCREF( Py_None );
    return Py_None;
}

static PyObject *
vlcInstance_playlist_clear( PyObject *self, PyObject *args )
{
    libvlc_exception_t ex;
    LIBVLC_TRY;
    libvlc_playlist_clear( LIBVLC_INSTANCE->p_instance, &ex );
    LIBVLC_EXCEPT;
    Py_INCREF( Py_None );
    return Py_None;
}

/* Add a playlist item. Main parameter: URI.
   Optional parameters: name, options */
static PyObject *
vlcInstance_playlist_add( PyObject *self, PyObject *args)
{
    libvlc_exception_t ex;
    int i_ret;
    char* psz_uri = NULL;
    char* psz_name = NULL;
    PyObject *py_options = NULL;
    int i_size = 0;
    char** ppsz_args = NULL;

    if( !PyArg_ParseTuple( args, "s|sO", &psz_uri, &psz_name, &py_options ) )
        return NULL;

    if( !psz_name )
    {
        /* Set a default name */
        psz_name = strdup( psz_uri );
    }

    if( py_options )
274 275
    {        
        i_size = pyoptions_to_args( py_options, &ppsz_args );
276 277 278 279 280 281 282 283 284 285 286
    }

    LIBVLC_TRY;
    if( ppsz_args )
    {
        i_ret = libvlc_playlist_add_extended( LIBVLC_INSTANCE->p_instance,
                                              psz_uri,
                                              psz_name,
                                              i_size,
                                              ppsz_args,
                                              &ex );
287
        free_args( i_size, ppsz_args );
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436
    }
    else
    {
        i_ret = libvlc_playlist_add( LIBVLC_INSTANCE->p_instance,
                                     psz_uri,
                                     psz_name,
                                     &ex );
    }
    LIBVLC_EXCEPT;

    return Py_BuildValue( "i", i_ret );
}

static PyObject *
vlcInstance_playlist_delete_item( PyObject *self, PyObject *args )
{
    libvlc_exception_t ex;
    int i_id;
    int i_ret;

    if( !PyArg_ParseTuple( args, "i", &i_id ) )
        return NULL;

    LIBVLC_TRY;
    i_ret = libvlc_playlist_delete_item( LIBVLC_INSTANCE->p_instance, i_id, &ex );
    LIBVLC_EXCEPT;

    return Py_BuildValue( "i", i_ret );
}

static PyObject *
vlcInstance_playlist_get_input( PyObject *self, PyObject *args )
{
    libvlc_exception_t ex;
    libvlc_input_t *p_input;
    vlcInput *p_ret;

    LIBVLC_TRY;
    p_input = libvlc_playlist_get_input( LIBVLC_INSTANCE->p_instance, &ex );
    LIBVLC_EXCEPT;

    p_ret = PyObject_New( vlcInput, &vlcInput_Type );
    p_ret->p_input = p_input;
    Py_INCREF( p_ret ); /* Ah bon ? */
    return ( PyObject * )p_ret;
}

static PyObject *
vlcInstance_video_set_parent( PyObject *self, PyObject *args )
{
    libvlc_exception_t ex;
    int i_drawable;

    if( !PyArg_ParseTuple( args, "i", &i_drawable ) )
        return NULL;

    LIBVLC_TRY;
    libvlc_video_set_parent( LIBVLC_INSTANCE->p_instance, (libvlc_drawable_t) i_drawable, &ex );
    LIBVLC_EXCEPT;

    Py_INCREF( Py_None );
    return Py_None;
}

static PyObject *
vlcInstance_video_set_size( PyObject *self, PyObject *args )
{
    libvlc_exception_t ex;
    int i_width;
    int i_height;

    if( !PyArg_ParseTuple( args, "ii", &i_width, &i_height ) )
        return NULL;

    LIBVLC_TRY;
    libvlc_video_set_size( LIBVLC_INSTANCE->p_instance, i_width, i_height, &ex );
    LIBVLC_EXCEPT;

    Py_INCREF( Py_None );
    return Py_None;
}

static PyObject *
vlcInstance_audio_toggle_mute( PyObject *self, PyObject *args )
{
    libvlc_exception_t ex;
    LIBVLC_TRY;
    libvlc_audio_toggle_mute( LIBVLC_INSTANCE->p_instance, &ex );
    LIBVLC_EXCEPT;
    Py_INCREF( Py_None );
    return Py_None;
}

static PyObject *
vlcInstance_audio_get_mute( PyObject *self, PyObject *args )
{
    libvlc_exception_t ex;
    int i_ret;

    LIBVLC_TRY;
    i_ret = libvlc_audio_get_mute( LIBVLC_INSTANCE->p_instance, &ex );
    LIBVLC_EXCEPT;
    return Py_BuildValue( "i", i_ret );
}

static PyObject *
vlcInstance_audio_set_mute( PyObject *self, PyObject *args )
{
    libvlc_exception_t ex;
    int i_mute;

    if( !PyArg_ParseTuple( args, "i", &i_mute ) )
        return NULL;

    LIBVLC_TRY;
    libvlc_audio_set_mute( LIBVLC_INSTANCE->p_instance, i_mute, &ex );
    LIBVLC_EXCEPT;
    Py_INCREF( Py_None );
    return Py_None;
}

static PyObject *
vlcInstance_audio_get_volume( PyObject *self, PyObject *args )
{
    libvlc_exception_t ex;
    int i_ret;

    LIBVLC_TRY;
    i_ret = libvlc_audio_get_volume( LIBVLC_INSTANCE->p_instance, &ex );
    LIBVLC_EXCEPT;
    return Py_BuildValue( "i", i_ret );
}

static PyObject *
vlcInstance_audio_set_volume( PyObject *self, PyObject *args )
{
    libvlc_exception_t ex;
    int i_volume;

    if( !PyArg_ParseTuple( args, "i", &i_volume ) )
        return NULL;

    LIBVLC_TRY;
    libvlc_audio_set_mute( LIBVLC_INSTANCE->p_instance, i_volume, &ex );
    LIBVLC_EXCEPT;
    Py_INCREF( Py_None );
    return Py_None;
}

437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467
static PyObject *
vlcInstance_audio_get_channel( PyObject *self, PyObject *args )
{
    libvlc_exception_t ex;
    char* psz_ret;
    PyObject* o_ret;

    LIBVLC_TRY;
    psz_ret = libvlc_audio_get_channel( LIBVLC_INSTANCE->p_instance, &ex );
    LIBVLC_EXCEPT;
    o_ret=Py_BuildValue( "s", psz_ret );
    free( psz_ret );
    return o_ret;
}

static PyObject *
vlcInstance_audio_set_channel( PyObject *self, PyObject *args )
{
    libvlc_exception_t ex;
    char* psz_channel;

    if( !PyArg_ParseTuple( args, "s", &psz_channel ) )
        return NULL;

    LIBVLC_TRY;
    libvlc_audio_set_channel( LIBVLC_INSTANCE->p_instance, psz_channel, &ex );
    LIBVLC_EXCEPT;
    Py_INCREF( Py_None );
    return Py_None;
}

468 469 470 471
/* vlm_add_broadcast : name, input MRL, output MRL
   Keywords: options, enable, loop */
static PyObject *
vlcInstance_vlm_add_broadcast( PyObject *self, PyObject *args, PyObject *kwds )
472 473
{
    libvlc_exception_t ex;
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495
    static char *kwlist[] = { "name", "input", "output", 
                              "options", "enable", "loop", NULL};
    char* psz_name = NULL;
    char* psz_input = NULL;
    char* psz_output = NULL;
    PyObject* py_options = NULL;
    int i_enable = 1;
    int i_loop = 0;
    int i_size = 0;
    char** ppsz_args = NULL;

    if( !PyArg_ParseTupleAndKeywords( args, kwds, "sss|Oii", kwlist, 
                                      &psz_name,
				      &psz_input, &psz_output,
				      &py_options, &i_enable, &i_loop ) )
        return NULL;
    
    if( py_options )
    {
        i_size = pyoptions_to_args( py_options, &ppsz_args );
    }
   
496
    LIBVLC_TRY;
497 498 499 500
    libvlc_vlm_add_broadcast( LIBVLC_INSTANCE->p_instance, 
                              psz_name, psz_input, psz_output,
                              i_size, ppsz_args, i_enable, i_loop, &ex);
    free_args( i_size, ppsz_args );
501 502 503 504 505 506 507 508 509
    LIBVLC_EXCEPT;
    Py_INCREF( Py_None );
    return Py_None;
}

static PyObject *
vlcInstance_vlm_del_media( PyObject *self, PyObject *args )
{
    libvlc_exception_t ex;
510 511 512 513 514
    char* psz_name;

    if( !PyArg_ParseTuple( args, "s", &psz_name ) )
        return NULL;

515
    LIBVLC_TRY;
516
    libvlc_vlm_del_media( LIBVLC_INSTANCE->p_instance, psz_name, &ex);
517 518 519 520 521 522 523 524 525
    LIBVLC_EXCEPT;
    Py_INCREF( Py_None );
    return Py_None;
}

static PyObject *
vlcInstance_vlm_set_enabled( PyObject *self, PyObject *args )
{
    libvlc_exception_t ex;
526 527 528 529 530 531
    char* psz_name;
    int i_enabled;
    
    if( !PyArg_ParseTuple( args, "si", &psz_name, &i_enabled ) )
        return NULL;

532
    LIBVLC_TRY;
533
    libvlc_vlm_set_enabled( LIBVLC_INSTANCE->p_instance, psz_name, i_enabled, &ex);
534 535 536 537 538 539 540 541 542
    LIBVLC_EXCEPT;
    Py_INCREF( Py_None );
    return Py_None;
}

static PyObject *
vlcInstance_vlm_set_output( PyObject *self, PyObject *args )
{
    libvlc_exception_t ex;
543 544 545 546 547 548
    char* psz_name;
    char* psz_output;
    
    if( !PyArg_ParseTuple( args, "ss", &psz_name, &psz_output ) )
        return NULL;

549
    LIBVLC_TRY;
550
    libvlc_vlm_set_output( LIBVLC_INSTANCE->p_instance, psz_name, psz_output, &ex);
551 552 553 554 555 556 557 558 559
    LIBVLC_EXCEPT;
    Py_INCREF( Py_None );
    return Py_None;
}

static PyObject *
vlcInstance_vlm_set_input( PyObject *self, PyObject *args )
{
    libvlc_exception_t ex;
560 561 562 563 564 565
    char* psz_name;
    char* psz_input;
    
    if( !PyArg_ParseTuple( args, "ss", &psz_name, &psz_input ) )
        return NULL;

566
    LIBVLC_TRY;
567
    libvlc_vlm_set_input( LIBVLC_INSTANCE->p_instance, psz_name, psz_input, &ex);
568 569 570 571 572 573 574 575 576
    LIBVLC_EXCEPT;
    Py_INCREF( Py_None );
    return Py_None;
}

static PyObject *
vlcInstance_vlm_set_loop( PyObject *self, PyObject *args )
{
    libvlc_exception_t ex;
577 578 579 580 581 582
    char* psz_name;
    int i_loop;
    
    if( !PyArg_ParseTuple( args, "si", &psz_name, &i_loop ) )
        return NULL;

583
    LIBVLC_TRY;
584
    libvlc_vlm_set_loop( LIBVLC_INSTANCE->p_instance, psz_name, i_loop, &ex);
585 586 587 588 589 590
    LIBVLC_EXCEPT;
    Py_INCREF( Py_None );
    return Py_None;
}

static PyObject *
591
vlcInstance_vlm_change_media( PyObject *self, PyObject *args, PyObject *kwds )
592 593
{
    libvlc_exception_t ex;
594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615
    static char *kwlist[] = { "name", "input", "output", 
                              "options", "enable", "loop", NULL};
    char* psz_name = NULL;
    char* psz_input = NULL;
    char* psz_output = NULL;
    PyObject* py_options = NULL;
    int i_enable = 1;
    int i_loop = 0;
    int i_size = 0;
    char** ppsz_args = NULL;

    if( !PyArg_ParseTupleAndKeywords( args, kwds, "sss|Oii", kwlist, 
                                      &psz_name,
				      &psz_input, &psz_output,
				      &py_options, &i_enable, &i_loop ) )
        return NULL;
    
    if( py_options )
    {
        i_size = pyoptions_to_args( py_options, &ppsz_args );
    }
   
616
    LIBVLC_TRY;
617 618 619 620
    libvlc_vlm_change_media( LIBVLC_INSTANCE->p_instance, 
                              psz_name, psz_input, psz_output,
                              i_size, ppsz_args, i_enable, i_loop, &ex);
    free_args( i_size, ppsz_args );
621 622 623 624 625 626 627 628 629
    LIBVLC_EXCEPT;
    Py_INCREF( Py_None );
    return Py_None;
}

static PyObject *
vlcInstance_vlm_play_media( PyObject *self, PyObject *args )
{
    libvlc_exception_t ex;
630 631 632 633 634
    char* psz_name;
    
    if( !PyArg_ParseTuple( args, "s", &psz_name ) )
        return NULL;

635
    LIBVLC_TRY;
636
    libvlc_vlm_play_media( LIBVLC_INSTANCE->p_instance, psz_name, &ex);
637 638 639 640 641 642 643 644 645
    LIBVLC_EXCEPT;
    Py_INCREF( Py_None );
    return Py_None;
}

static PyObject *
vlcInstance_vlm_stop_media( PyObject *self, PyObject *args )
{
    libvlc_exception_t ex;
646
    char* psz_name;
647

648 649 650
    if( !PyArg_ParseTuple( args, "s", &psz_name ) )
        return NULL;

651
    LIBVLC_TRY;
652
    libvlc_vlm_stop_media( LIBVLC_INSTANCE->p_instance, psz_name, &ex);
653 654 655 656 657 658 659 660 661
    LIBVLC_EXCEPT;
    Py_INCREF( Py_None );
    return Py_None;
}

static PyObject *
vlcInstance_vlm_pause_media( PyObject *self, PyObject *args )
{
    libvlc_exception_t ex;
662 663 664 665 666
    char* psz_name;
    
    if( !PyArg_ParseTuple( args, "s", &psz_name ) )
        return NULL;

667
    LIBVLC_TRY;
668
    libvlc_vlm_pause_media( LIBVLC_INSTANCE->p_instance, psz_name, &ex);
669 670 671 672 673
    LIBVLC_EXCEPT;
    Py_INCREF( Py_None );
    return Py_None;
}

674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708
static PyObject *
vlcInstance_vlm_seek_media( PyObject *self, PyObject *args )
{
    libvlc_exception_t ex;
    char* psz_name;
    float f_percentage;
    
    if( !PyArg_ParseTuple( args, "sf", &psz_name, &f_percentage ) )
        return NULL;

    LIBVLC_TRY;
    libvlc_vlm_seek_media( LIBVLC_INSTANCE->p_instance, psz_name, f_percentage, &ex);
    LIBVLC_EXCEPT;
    Py_INCREF( Py_None );
    return Py_None;
}

static PyObject *
vlcInstance_vlm_show_media( PyObject *self, PyObject *args )
{
    libvlc_exception_t ex;
    char* psz_name;
    char* psz_ret;
    PyObject* o_ret;

    if( !PyArg_ParseTuple( args, "s", &psz_name ) )
        return NULL;
    LIBVLC_TRY;
    psz_ret = libvlc_vlm_show_media( LIBVLC_INSTANCE->p_instance, psz_name, &ex );
    LIBVLC_EXCEPT;
    o_ret = Py_BuildValue( "s", psz_ret );
    free( psz_ret );
    return o_ret;
}

709 710 711 712 713
/* Method table */
static PyMethodDef vlcInstance_methods[] =
{
    { "get_vlc_id", vlcInstance_get_vlc_id, METH_VARARGS,
      "get_vlc_id( ) -> int        Get the instance id."},
714 715
    { "playlist_loop", vlcInstance_playlist_loop, METH_VARARGS,
      "playlist_loop(bool)         Set loop variable" },
716
    { "playlist_play", vlcInstance_playlist_play, METH_VARARGS,
717
      "playlist_play(id=int, options=list)   Play the given playlist item (-1 for current item) with optional options (a list of strings)" },
718 719 720 721 722 723 724 725 726 727 728 729 730 731 732
    { "playlist_pause", vlcInstance_playlist_pause, METH_VARARGS,
      "playlist_pause()            Pause the current stream"},
    { "playlist_isplaying", vlcInstance_playlist_isplaying, METH_VARARGS,
      "playlist_isplaying() -> int     Return True if the playlist if playing"},
    { "playlist_items_count", vlcInstance_playlist_items_count, METH_VARARGS,
      "playlist_items_count() -> int   Return the number of items in the playlist"},
    { "playlist_stop", vlcInstance_playlist_stop, METH_VARARGS,
      "playlist_stop()             Stop the current stream"},
    { "playlist_next", vlcInstance_playlist_next, METH_VARARGS,
      "playlist_next()             Play the next item"},
    { "playlist_prev", vlcInstance_playlist_prev, METH_VARARGS,
      "playlist_prev()             Play the previous item"},
    { "playlist_clear", vlcInstance_playlist_clear, METH_VARARGS,
      "playlist_clear()            Clear the playlist"},
    { "playlist_add", vlcInstance_playlist_add, METH_VARARGS,
733
      "playlist_add(mrl=str, name=str, options=list) -> int  Add a new item to the playlist. options is a list of strings."},
734
    { "playlist_delete_item", vlcInstance_playlist_delete_item, METH_VARARGS,
735
      "playlist_delete_item(id=int)   Delete the given item"},
736 737 738
    { "playlist_get_input", vlcInstance_playlist_get_input, METH_VARARGS,
      "playlist_get_input() -> object   Return the current input"},
    { "video_set_parent", vlcInstance_video_set_parent, METH_VARARGS,
739
      "video_set_parent(xid=int)       Set the parent xid or HWND"},
740
    { "video_set_size", vlcInstance_video_set_size, METH_VARARGS,
741
      "video_set_size(width=int, height=int)    Set the video width and height"},
742 743 744 745 746
    { "audio_toggle_mute", vlcInstance_audio_toggle_mute, METH_VARARGS,
      "audio_toggle_mute()         Toggle the mute state"},
    { "audio_get_mute", vlcInstance_audio_get_mute, METH_VARARGS,
      "audio_get_mute() -> int     Get the mute state"},
    { "audio_set_mute", vlcInstance_audio_set_mute, METH_VARARGS,
747
      "audio_set_mute(state=int)         Set the mute state"},
748 749 750
    { "audio_get_volume", vlcInstance_audio_get_volume, METH_VARARGS,
      "audio_get_volume() -> int   Get the audio volume"},
    { "audio_set_volume", vlcInstance_audio_set_volume, METH_VARARGS,
751
      "audio_set_volume(volume=int)       Set the audio volume"},
752 753 754 755
    { "audio_get_channel", vlcInstance_audio_get_channel, METH_VARARGS,
      "audio_get_channel() -> int  Get current audio channel" },
    { "audio_set_channel", vlcInstance_audio_set_channel, METH_VARARGS,
      "audio_set_channel(int)      Set current audio channel" },
756
    { "vlm_add_broadcast", vlcInstance_vlm_add_broadcast, METH_VARARGS | METH_KEYWORDS,
757 758 759 760 761 762 763 764 765 766 767
      "vlm_add_broadcast(name=str, input=str, output=str, options=list, enable=int, loop=int)   Add a new broadcast" },
    { "vlm_del_media", vlcInstance_vlm_del_media, METH_VARARGS,
      "vlm_del_media(name=str)    Delete a media" },
    { "vlm_set_enabled", vlcInstance_vlm_set_enabled, METH_VARARGS,
      "vlm_set_enabled(name=str, enabled=int)    Enable/disable a media" },
    { "vlm_set_output", vlcInstance_vlm_set_output, METH_VARARGS,
      "vlm_set_output(name=str, output=str)      Set the output" },
    { "vlm_set_input", vlcInstance_vlm_set_input, METH_VARARGS,
      "vlm_set_input(name=str, output=str)       Set the input" },
    { "vlm_set_loop", vlcInstance_vlm_set_loop, METH_VARARGS,
      "vlm_set_loop(name=str, loop=int)          Change the looping value" },
768
    { "vlm_change_media", vlcInstance_vlm_change_media, METH_VARARGS | METH_KEYWORDS,
769 770
      "vlm_change_media(name=str, input=str, output=str, options=list, enable=int, loop=int)   Change the broadcast parameters" },
    { "vlm_play_media", vlcInstance_vlm_play_media, METH_VARARGS,
771
      "vlm_play_media(name=str)       Plays the named broadcast." },
772
    { "vlm_stop_media", vlcInstance_vlm_stop_media, METH_VARARGS,
773
      "vlm_stop_media(name=str)       Stops the named broadcast." },
774
    { "vlm_pause_media", vlcInstance_vlm_pause_media, METH_VARARGS,
775 776 777 778 779
      "vlm_pause_media(name=str)      Pauses the named broadcast." },
    { "vlm_seek_media", vlcInstance_vlm_seek_media, METH_VARARGS,
      "vlm_seek_media(name=str, percentage=float)  Seeks in the named broadcast." },
    { "vlm_show_media", vlcInstance_vlm_show_media, METH_VARARGS,
      "vlm_show_media(name=str)       Return information of the named broadcast." },
780

781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806
    { NULL, NULL, 0, NULL },
};

static PyTypeObject vlcInstance_Type =
{
    PyObject_HEAD_INIT( NULL )
    0,                          /*ob_size*/
    "vlc.Instance",             /*tp_name*/
    sizeof( vlcInstance_Type ), /*tp_basicsize*/
    0,                          /*tp_itemsize*/
    ( destructor )vlcInstance_dealloc,      /*tp_dealloc*/
    0,                         /*tp_print*/
    0,                         /*tp_getattr*/
    0,                         /*tp_setattr*/
    0,                         /*tp_compare*/
    0,                         /*tp_repr*/
    0,                         /*tp_as_number*/
    0,                         /*tp_as_sequence*/
    0,                         /*tp_as_mapping*/
    0,                         /*tp_hash */
    0,                         /*tp_call*/
    0,                         /*tp_str*/
    0,                         /*tp_getattro*/
    0,                         /*tp_setattro*/
    0,                         /*tp_as_buffer*/
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
807
    "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 */
808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825
    0,                     /* tp_traverse */
    0,                     /* tp_clear */
    0,                     /* tp_richcompare */
    0,                     /* tp_weaklistoffset */
    0,                     /* tp_iter */
    0,                     /* tp_iternext */
    vlcInstance_methods,             /* tp_methods */
    0,             /* tp_members */
    0,                         /* tp_getset */
    0,                         /* tp_base */
    0,                         /* tp_dict */
    0,                         /* tp_descr_get */
    0,                         /* tp_descr_set */
    0,                         /* tp_dictoffset */
    0,                         /* tp_init */
    0,                         /* tp_alloc */
    vlcInstance_new,          /* tp_new */
};