⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vlc.c

📁 VLC Player Source Code
💻 C
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************** * vlc.c: Generic lua interface functions ***************************************************************************** * Copyright (C) 2007-2008 the VideoLAN team * $Id$ * * Authors: Antoine Cellerier <dionoea at videolan tod org> *          Pierre d'Herbemont <pdherbemont # videolan.org> * * 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. *****************************************************************************//***************************************************************************** * Preamble *****************************************************************************/#ifndef  _GNU_SOURCE#   define  _GNU_SOURCE#endif#ifdef HAVE_CONFIG_H# include "config.h"#endif#include <assert.h>#include <vlc_common.h>#include <vlc_plugin.h>#include <vlc_meta.h>#include <vlc_charset.h>#include <vlc_aout.h>#include <lua.h>        /* Low level lua C API */#include <lauxlib.h>    /* Higher level C API */#include <lualib.h>     /* Lua libs */#include "vlc.h"/***************************************************************************** * Module descriptor *****************************************************************************/#define INTF_TEXT N_("Lua interface")#define INTF_LONGTEXT N_("Lua interface module to load")#define CONFIG_TEXT N_("Lua interface configuration")#define CONFIG_LONGTEXT N_("Lua interface configuration string. Format is: '[\"<interface module name>\"] = { <option> = <value>, ...}, ...'.")vlc_module_begin();        set_shortname( N_( "Lua Art" ) );        set_description( N_("Fetch artwork using lua scripts") );        set_capability( "art finder", 10 );        set_callbacks( FindArt, NULL );    add_submodule();        add_shortcut( "luaplaylist" );        set_category( CAT_INPUT );        set_subcategory( SUBCAT_INPUT_DEMUX );        set_shortname( N_("Lua Playlist") );        set_description( N_("Lua Playlist Parser Interface") );        set_capability( "demux", 2 );        set_callbacks( Import_LuaPlaylist, Close_LuaPlaylist );    add_submodule();        add_shortcut( "luaintf" );        add_shortcut( "luarc" );        /* add_shortcut( "rc" ); */        add_shortcut( "luahotkeys" );        /* add_shortcut( "hotkeys" ); */        add_shortcut( "luatelnet" );        /* add_shortcut( "telnet" ); */        add_shortcut( "luahttp" );        /* add_shortcut( "http" ); */        set_description( N_("Lua Interface Module") );        set_capability( "interface", 0 );        add_string( "lua-intf", "dummy", NULL,                    INTF_TEXT, INTF_LONGTEXT, false );        add_string( "lua-config", "", NULL,                    CONFIG_TEXT, CONFIG_LONGTEXT, false );        set_callbacks( Open_LuaIntf, Close_LuaIntf );vlc_module_end();/***************************************************************************** * *****************************************************************************/static int file_select( const char *file ){    int i = strlen( file );    return i > 4 && !strcmp( file+i-4, ".lua" );}static int file_compare( const char **a, const char **b ){    return strcmp( *a, *b );}int vlclua_dir_list( const char *luadirname, char **ppsz_dir_list ){    int i = 0;    char *datadir = config_GetUserDataDir();    if( datadir == NULL )        return VLC_ENOMEM;    if( asprintf( &ppsz_dir_list[i], "%s" DIR_SEP "lua" DIR_SEP "%s",                   datadir, luadirname ) < 0 )    {        free( datadir );        return VLC_ENOMEM;    }    free( datadir );    i++;#   if defined(__APPLE__) || defined(SYS_BEOS) || defined(WIN32)    {        const char *psz_vlcpath = config_GetDataDir();        if( asprintf( &ppsz_dir_list[i], "%s" DIR_SEP "lua" DIR_SEP "%s",                      psz_vlcpath, luadirname )  < 0 )            return VLC_ENOMEM;        i++;        if( asprintf( &ppsz_dir_list[i], "%s" DIR_SEP "share" DIR_SEP "lua" DIR_SEP "%s",                      psz_vlcpath, luadirname )  < 0 )            return VLC_ENOMEM;        i++;    }#   else    if( asprintf( &ppsz_dir_list[i], "%s" DIR_SEP "lua" DIR_SEP "%s",                  config_GetDataDir (), luadirname ) < 0 )        return VLC_ENOMEM;    i++;#   endif    return VLC_SUCCESS;}void vlclua_dir_list_free( char **ppsz_dir_list ){    char **ppsz_dir;    for( ppsz_dir = ppsz_dir_list; *ppsz_dir; ppsz_dir++ )        free( *ppsz_dir );}/***************************************************************************** * Will execute func on all scripts in luadirname, and stop if func returns * success. *****************************************************************************/int vlclua_scripts_batch_execute( vlc_object_t *p_this,                                  const char * luadirname,                                  int (*func)(vlc_object_t *, const char *, lua_State *, void *),                                  lua_State * L,                                  void * user_data){    int i_ret = VLC_EGENERIC;    char **ppsz_filelist = NULL;    char **ppsz_fileend  = NULL;    char **ppsz_file;    char  *ppsz_dir_list[] = { NULL, NULL, NULL, NULL };    char **ppsz_dir;    i_ret = vlclua_dir_list( luadirname, ppsz_dir_list );    if( i_ret != VLC_SUCCESS )        return i_ret;    i_ret = VLC_EGENERIC;    for( ppsz_dir = ppsz_dir_list; *ppsz_dir; ppsz_dir++ )    {        int i_files;        if( ppsz_filelist )        {            for( ppsz_file = ppsz_filelist; ppsz_file < ppsz_fileend;                 ppsz_file++ )                free( *ppsz_file );            free( ppsz_filelist );            ppsz_filelist = NULL;        }        msg_Dbg( p_this, "Trying Lua scripts in %s", *ppsz_dir );        i_files = utf8_scandir( *ppsz_dir, &ppsz_filelist, file_select,                                file_compare );        if( i_files < 1 ) continue;        ppsz_fileend = ppsz_filelist + i_files;        for( ppsz_file = ppsz_filelist; ppsz_file < ppsz_fileend; ppsz_file++ )        {            char  *psz_filename;            if( asprintf( &psz_filename,                          "%s" DIR_SEP "%s", *ppsz_dir, *ppsz_file ) < 0)            {                vlclua_dir_list_free( ppsz_dir_list );                return VLC_ENOMEM;            }            msg_Dbg( p_this, "Trying Lua playlist script %s", psz_filename );            i_ret = func( p_this, psz_filename, L, user_data );            free( psz_filename );            if( i_ret == VLC_SUCCESS ) break;        }        if( i_ret == VLC_SUCCESS ) break;    }    if( ppsz_filelist )    {        for( ppsz_file = ppsz_filelist; ppsz_file < ppsz_fileend;             ppsz_file++ )            free( *ppsz_file );        free( ppsz_filelist );    }    vlclua_dir_list_free( ppsz_dir_list );    return i_ret;}/***************************************************************************** * Meta data setters utility. * Playlist item table should be on top of the stack when these are called *****************************************************************************/void __vlclua_read_meta_data( vlc_object_t *p_this, lua_State *L,                              input_item_t *p_input ){#define TRY_META( a, b )                                        \    lua_getfield( L, -1, a );                                   \    if( lua_isstring( L, -1 ) )                                 \    {                                                           \        char *psz_value = strdup( lua_tostring( L, -1 ) );      \        EnsureUTF8( psz_value );                                \        msg_Dbg( p_this, #b ": %s", psz_value );                \        input_item_Set ## b ( p_input, psz_value );             \        free( psz_value );                                      \

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -