<commit_before>/*****************************************************************************
 * vlc_mediacontrol.c: vlc.MediaControl binding
 *****************************************************************************
 * Copyright (C) 2006 the VideoLAN team
 * $Id: $
 *
 * Authors: <NAME> <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"

/*****************************************************************************
 * VLC MediaControl object implementation
 *****************************************************************************/

/* The MediaControl constructor takes either an existing vlc.Instance or a
   list of strings */
static PyObject *
MediaControl_new( PyTypeObject *type, PyObject *args, PyObject *kwds )
{
    MediaControl *self;
    mediacontrol_Exception *exception = NULL;
    PyObject* py_param = NULL;
    char** ppsz_args = NULL;
    libvlc_instance_t* p_instance = NULL;
    
    self = PyObject_New( MediaControl, &MediaControl_Type );

    if( PyArg_ParseTuple( args, "O", &py_param ) )
    {
        Py_INCREF( py_param );
        if( PyObject_TypeCheck( py_param, &vlcInstance_Type ) == 1 )
        {
            p_instance = ((vlcInstance*)py_param)->p_instance;
        }
        else
        {
            int i_size;
            int i_index;

            if( ! PySequence_Check( py_param ) )
            {
                PyErr_SetString( PyExc_TypeError, "Parameter must be a vlc.Instance or a sequence of strings." );
                Py_DECREF( py_param );
                return NULL;
            }
            i_size = PySequence_Size( py_param );
            ppsz_args = malloc( ( i_size + 1 ) * sizeof( char * ) );
            if( ! ppsz_args )
            {
                PyErr_SetString( PyExc_MemoryError, "Out of memory" );
                Py_DECREF( py_param );
                return NULL;
            }

            for ( i_index = 0; i_index < i_size; i_index++ )
            {
                ppsz_args[i_index] =
                    strdup( PyString_AsString( PyObject_Str(
                                                   PySequence_GetItem( py_param,
                                                                       i_index ) ) ) );
            }
            ppsz_args[i_size] = NULL;
        }
        Py_DECREF( py_param );
    }
    else
    {
        /* No arguments were given. Clear the exception raised
           by PyArg_ParseTuple. */
        PyErr_Clear( );
    }

    Py_BEGIN_ALLOW_THREADS
    MC_TRY;
    if( p_instance )
    {
        self->mc = mediacontrol_new_from_instance( p_instance, exception );
    }
    else
    {
        self->mc = mediacontrol_new( ppsz_args, exception );
    }
    MC_EXCEPT;
    Py_END_ALLOW_THREADS

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

static void
MediaControl_dealloc( PyObject *self )
{
    PyMem_DEL( self );
}

static PyObject *
MediaControl_get_vlc_instance( PyObject *self, PyObject *args )
{
    vlcInstance *p_ret;

    p_ret = PyObject_New( vlcInstance, &vlcInstance_Type );
    if( !p_ret )
        return NULL;
    p_ret->p_instance = mediacontrol_get_libvlc_instance( SELF->mc );
    return ( PyObject * )p_ret;
}

/**
 *  Return the current position in the stream. The returned value can<commit_msg>bindings/mediacontrol-python/vlc_mediacontrol.c: use the new mediacontrol_new API<commit_after>/*****************************************************************************
 * vlc_mediacontrol.c: vlc.MediaControl binding
 *****************************************************************************
 * Copyright (C) 2006 the VideoLAN team
 * $Id: $
 *
 * Authors: <NAME> <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"

/*****************************************************************************
 * VLC MediaControl object implementation
 *****************************************************************************/

/* The MediaControl constructor takes either an existing vlc.Instance or a
   list of strings */
static PyObject *
MediaControl_new( PyTypeObject *type, PyObject *args, PyObject *kwds )
{
    MediaControl *self;
    mediacontrol_Exception *exception = NULL;
    PyObject* py_param = NULL;
    char** ppsz_args = NULL;
    libvlc_instance_t* p_instance = NULL;
    int i_size = 0;
    
    self = PyObject_New( MediaControl, &MediaControl_Type );

    if( PyArg_ParseTuple( args, "O", &py_param ) )
    {
        Py_INCREF( py_param );
        if( PyObject_TypeCheck( py_param, &vlcInstance_Type ) == 1 )
        {
            p_instance = ((vlcInstance*)py_param)->p_instance;
        }
        else
        {
            int i_index;

            if( ! PySequence_Check( py_param ) )
            {
                PyErr_SetString( PyExc_TypeError, "Parameter must be a vlc.Instance or a sequence of strings." );
                Py_DECREF( py_param );
                return NULL;
            }
            i_size = PySequence_Size( py_param );
            ppsz_args = malloc( ( i_size + 1 ) * sizeof( char * ) );
            if( ! ppsz_args )
            {
                PyErr_SetString( PyExc_MemoryError, "Out of memory" );
                Py_DECREF( py_param );
                return NULL;
            }

            for ( i_index = 0; i_index < i_size; i_index++ )
            {
                ppsz_args[i_index] =
                    strdup( PyString_AsString( PyObject_Str(
                                                   PySequence_GetItem( py_param,
                                                                       i_index ) ) ) );
            }
            ppsz_args[i_size] = NULL;
        }
        Py_DECREF( py_param );
    }
    else
    {
        /* No arguments were given. Clear the exception raised
           by PyArg_ParseTuple. */
        PyErr_Clear( );
    }

    Py_BEGIN_ALLOW_THREADS
    MC_TRY;
    if( p_instance )
    {
        self->mc = mediacontrol_new_from_instance( p_instance, exception );
    }
    else
    {
        self->mc = mediacontrol_new( i_size, ppsz_args, exception );
    }
    MC_EXCEPT;
    Py_END_ALLOW_THREADS

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

static void
MediaControl_dealloc( PyObject *self )
{
    PyMem_DEL( self );
}

static PyObject *
MediaControl_get_vlc_instance( PyObject *self, PyObject *args )
{
    vlcInstance *p_ret;

    p_ret = PyObject_New( vlcInstance, &vlcInstance_Type );
    if( !p_ret )
        return NULL;
    p_ret->p_instance = mediacontrol_get_libvlc_instance( SELF->mc );
    return ( PyObject * )p_ret;
}

/**
 *  Return the current position in the stream. The returned value can
{'fraction_non_alphanumeric': 0.16947702834799608, 'fraction_numerical': 0.005742913000977517, 'mean_word_length': 2.434746118338229, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4034855', 'n_tokens_mistral': 2319, 'n_tokens_neox': 2234, 'n_words': 652}