[vlc-devel] [PATCH 2/4] finder/fetcher: always use scripts doing local access
Francois Cartegnie
fcvlcdev at free.fr
Tue May 13 17:12:36 CEST 2014
---
include/vlc_art_finder.h | 8 ++++
modules/lua/meta.c | 95 +++++++++++++++++++++++++++++++++---------------
modules/lua/vlc.h | 8 ++--
src/playlist/fetcher.c | 28 +++++++++-----
src/playlist/preparser.c | 6 +--
5 files changed, 99 insertions(+), 46 deletions(-)
diff --git a/include/vlc_art_finder.h b/include/vlc_art_finder.h
index a8b4c45..52941c9 100644
--- a/include/vlc_art_finder.h
+++ b/include/vlc_art_finder.h
@@ -21,10 +21,18 @@
#ifndef VLC_ART_FINDER_H
#define VLC_ART_FINDER_H 1
+typedef enum meta_fetcher_scope_t
+{
+ FETCHER_SCOPE_LOCAL,
+ FETCHER_SCOPE_NETWORK,
+ FETCHER_SCOPE_ANY
+} meta_fetcher_scope_t;
+
typedef struct art_finder_t
{
VLC_COMMON_MEMBERS
input_item_t *p_item;
+ meta_fetcher_scope_t e_scope;
} art_finder_t;
#endif
diff --git a/modules/lua/meta.c b/modules/lua/meta.c
index a0c40d1..0e4910c 100644
--- a/modules/lua/meta.c
+++ b/modules/lua/meta.c
@@ -46,6 +46,17 @@
#include "libs.h"
/*****************************************************************************
+ * Local prototypes
+ *****************************************************************************/
+typedef struct luabatch_context_t luabatch_context_t;
+struct luabatch_context_t
+{
+ input_item_t *p_item;
+ meta_fetcher_scope_t e_scope;
+ bool (*pf_validator)( const luabatch_context_t *, meta_fetcher_scope_t );
+};
+
+/*****************************************************************************
* Init lua
*****************************************************************************/
static const luaL_Reg p_reg[] = { { NULL, NULL } };
@@ -89,7 +100,8 @@ static lua_State * init( vlc_object_t *p_this, input_item_t * p_item, const char
* Run a lua entry point function
*****************************************************************************/
static int run( vlc_object_t *p_this, const char * psz_filename,
- lua_State * L, const char *luafunction )
+ lua_State * L, const char *luafunction,
+ const luabatch_context_t *p_context )
{
/* Ugly hack to delete previous versions of the fetchart()
* functions. */
@@ -104,6 +116,26 @@ static int run( vlc_object_t *p_this, const char * psz_filename,
goto error;
}
+
+ meta_fetcher_scope_t e_scope = FETCHER_SCOPE_NETWORK; /* default to restricted one */
+ lua_getglobal( L, "descriptor" );
+ if( lua_isfunction( L, lua_gettop( L ) ) && !lua_pcall( L, 0, 1, 0 ) )
+ {
+ lua_getfield( L, -1, "scope" );
+ char *psz_scope = luaL_strdupornull( L, -1 );
+ if ( psz_scope && !strcmp( psz_scope, "local" ) )
+ e_scope = FETCHER_SCOPE_LOCAL;
+ free( psz_scope );
+ lua_pop( L, 1 );
+ }
+ lua_pop( L, 1 );
+
+ if ( p_context && p_context->pf_validator && !p_context->pf_validator( p_context, e_scope ) )
+ {
+ msg_Dbg( p_this, "skipping script (unmatched scope) %s", psz_filename );
+ goto error;
+ }
+
lua_getglobal( L, luafunction );
if( !lua_isfunction( L, lua_gettop( L ) ) )
@@ -131,16 +163,22 @@ error:
* Called through lua_scripts_batch_execute to call 'fetch_art' on the script
* pointed by psz_filename.
*****************************************************************************/
-static int fetch_art( vlc_object_t *p_this, const char * psz_filename,
- void * user_data )
+static bool validate_scope( const luabatch_context_t *p_context, meta_fetcher_scope_t e_scope )
{
- input_item_t * p_item = user_data;
+ if ( p_context->e_scope == FETCHER_SCOPE_ANY )
+ return true;
+ else
+ return ( p_context->e_scope == e_scope );
+}
- lua_State *L = init( p_this, p_item, psz_filename );
+static int fetch_art( vlc_object_t *p_this, const char * psz_filename,
+ const luabatch_context_t *p_context )
+{
+ lua_State *L = init( p_this, p_context->p_item, psz_filename );
if( !L )
return VLC_EGENERIC;
- int i_ret = run(p_this, psz_filename, L, "fetch_art");
+ int i_ret = run(p_this, psz_filename, L, "fetch_art", p_context);
if(i_ret != VLC_SUCCESS)
{
lua_close( L );
@@ -157,7 +195,7 @@ static int fetch_art( vlc_object_t *p_this, const char * psz_filename,
if( psz_value && *psz_value != 0 )
{
lua_Dbg( p_this, "setting arturl: %s", psz_value );
- input_item_SetArtURL ( p_item, psz_value );
+ input_item_SetArtURL ( p_context->p_item, psz_value );
lua_close( L );
return VLC_SUCCESS;
}
@@ -182,14 +220,17 @@ static int fetch_art( vlc_object_t *p_this, const char * psz_filename,
* pointed by psz_filename.
*****************************************************************************/
static int read_meta( vlc_object_t *p_this, const char * psz_filename,
- void * user_data )
+ const luabatch_context_t *p_context )
{
- input_item_t * p_item = user_data;
- lua_State *L = init( p_this, p_item, psz_filename );
+ /* FIXME: merge with finder */
+ demux_meta_t *p_demux_meta = (demux_meta_t *)p_this;
+ VLC_UNUSED( p_context );
+
+ lua_State *L = init( p_this, p_demux_meta->p_item, psz_filename );
if( !L )
return VLC_EGENERIC;
- int i_ret = run(p_this, psz_filename, L, "read_meta");
+ int i_ret = run(p_this, psz_filename, L, "read_meta", NULL);
lua_close( L );
// Continue even if an error occurred: all "meta reader" are always run.
@@ -202,14 +243,13 @@ static int read_meta( vlc_object_t *p_this, const char * psz_filename,
* pointed by psz_filename.
*****************************************************************************/
static int fetch_meta( vlc_object_t *p_this, const char * psz_filename,
- void * user_data )
+ const luabatch_context_t *p_context )
{
- input_item_t * p_item = user_data;
- lua_State *L = init( p_this, p_item, psz_filename );
+ lua_State *L = init( p_this, p_context->p_item, psz_filename );
if( !L )
return VLC_EGENERIC;
- int ret = run(p_this, psz_filename, L, "fetch_meta");
+ int ret = run(p_this, psz_filename, L, "fetch_meta", p_context);
lua_close( L );
return ret;
@@ -219,13 +259,10 @@ static int fetch_meta( vlc_object_t *p_this, const char * psz_filename,
* Read meta.
*****************************************************************************/
-int ReadMeta( vlc_object_t *p_this )
+int ReadMeta( demux_meta_t *p_this )
{
- demux_meta_t *p_demux_meta = (demux_meta_t *)p_this;
- input_item_t *p_item = p_demux_meta->p_item;
-
return vlclua_scripts_batch_execute( p_this, "meta"DIR_SEP"reader",
- &read_meta, p_item );
+ &read_meta, NULL );
}
@@ -233,25 +270,23 @@ int ReadMeta( vlc_object_t *p_this )
* Read meta.
*****************************************************************************/
-int FetchMeta( vlc_object_t *p_this )
+int FetchMeta( art_finder_t *p_finder )
{
- demux_meta_t *p_demux_meta = (demux_meta_t *)p_this;
- input_item_t *p_item = p_demux_meta->p_item;
+ luabatch_context_t context = { p_finder->p_item, p_finder->e_scope, validate_scope };
- return vlclua_scripts_batch_execute( p_this, "meta"DIR_SEP"fetcher",
- &fetch_meta, p_item );
+ return vlclua_scripts_batch_execute( p_finder, "meta"DIR_SEP"fetcher",
+ &fetch_meta, &context );
}
/*****************************************************************************
* Module entry point for art.
*****************************************************************************/
-int FindArt( vlc_object_t *p_this )
+int FindArt( art_finder_t *p_finder )
{
- art_finder_t *p_finder = (art_finder_t *)p_this;
- input_item_t *p_item = p_finder->p_item;
+ luabatch_context_t context = { p_finder->p_item, p_finder->e_scope, validate_scope };
- return vlclua_scripts_batch_execute( p_this, "meta"DIR_SEP"art",
- &fetch_art, p_item );
+ return vlclua_scripts_batch_execute( p_finder, "meta"DIR_SEP"art",
+ &fetch_art, &context );
}
diff --git a/modules/lua/vlc.h b/modules/lua/vlc.h
index d54a5d3..8ded87c 100644
--- a/modules/lua/vlc.h
+++ b/modules/lua/vlc.h
@@ -32,9 +32,11 @@
#include <vlc_input.h>
#include <vlc_playlist.h>
#include <vlc_meta.h>
+#include <vlc_art_finder.h>
#include <vlc_url.h>
#include <vlc_strings.h>
#include <vlc_stream.h>
+#include <vlc_demux.h>
#define LUA_COMPAT_MODULE
#include <lua.h> /* Low level lua C API */
@@ -49,9 +51,9 @@
/*****************************************************************************
* Module entry points
*****************************************************************************/
-int ReadMeta( vlc_object_t * );
-int FetchMeta( vlc_object_t * );
-int FindArt( vlc_object_t * );
+int ReadMeta( demux_meta_t * );
+int FetchMeta( art_finder_t * );
+int FindArt( art_finder_t * );
int Import_LuaPlaylist( vlc_object_t * );
void Close_LuaPlaylist( vlc_object_t * );
diff --git a/src/playlist/fetcher.c b/src/playlist/fetcher.c
index 6901f94..e91d5e4 100644
--- a/src/playlist/fetcher.c
+++ b/src/playlist/fetcher.c
@@ -53,6 +53,7 @@ struct playlist_fetcher_t
input_item_t **pp_waiting;
DECL_ARRAY(playlist_album_t) albums;
+ meta_fetcher_scope_t e_scope;
};
static void *Thread( void * );
@@ -73,6 +74,13 @@ playlist_fetcher_t *playlist_fetcher_New( vlc_object_t *parent )
p_fetcher->b_live = false;
p_fetcher->i_waiting = 0;
p_fetcher->pp_waiting = NULL;
+
+ int i_policy = var_InheritInteger( parent, "album-art" );
+ if ( i_policy == ALBUM_ART_ALL )
+ p_fetcher->e_scope = FETCHER_SCOPE_ANY;
+ else
+ p_fetcher->e_scope = FETCHER_SCOPE_LOCAL;
+
ARRAY_INIT( p_fetcher->albums );
return p_fetcher;
@@ -224,6 +232,7 @@ static int FindArt( playlist_fetcher_t *p_fetcher, input_item_t *p_item )
module_t *p_module;
p_finder->p_item = p_item;
+ p_finder->e_scope = p_fetcher->e_scope;
p_module = module_need( p_finder, "art finder", NULL, false );
if( p_module )
@@ -332,18 +341,19 @@ error:
*/
static void FetchMeta( playlist_fetcher_t *p_fetcher, input_item_t *p_item )
{
- demux_meta_t *p_demux_meta = vlc_custom_create(p_fetcher->object,
- sizeof(*p_demux_meta), "demux meta" );
- if( !p_demux_meta )
+ art_finder_t *p_finder =
+ vlc_custom_create( p_fetcher->object, sizeof( *p_finder ), "art finder" );
+ if ( !p_finder )
return;
- p_demux_meta->p_demux = NULL;
- p_demux_meta->p_item = p_item;
+ p_finder->e_scope = p_fetcher->e_scope;
+ p_finder->p_item = p_item;
+
+ module_t *p_module = module_need( p_finder, "meta fetcher", NULL, false );
+ if( p_module )
+ module_unneed( p_finder, p_module );
- module_t *p_meta_fetcher = module_need( p_demux_meta, "meta fetcher", NULL, false );
- if( p_meta_fetcher )
- module_unneed( p_demux_meta, p_meta_fetcher );
- vlc_object_release( p_demux_meta );
+ vlc_object_release( p_finder );
}
static void *Thread( void *p_data )
diff --git a/src/playlist/preparser.c b/src/playlist/preparser.c
index eb07817..c1b6320 100644
--- a/src/playlist/preparser.c
+++ b/src/playlist/preparser.c
@@ -171,10 +171,8 @@ static void Art( playlist_preparser_t *p_preparser, input_item_t *p_item )
const char *psz_arturl = vlc_meta_Get( p_item->p_meta, vlc_meta_ArtworkURL );
const char *psz_name = vlc_meta_Get( p_item->p_meta, vlc_meta_Title );
- if( p_preparser->i_art_policy == ALBUM_ART_ALL &&
- ( !psz_arturl ||
- ( strncmp( psz_arturl, "file://", 7 ) &&
- strncmp( psz_arturl, "attachment://", 13 ) ) ) )
+ if( !psz_arturl || ( strncmp( psz_arturl, "file://", 7 ) &&
+ strncmp( psz_arturl, "attachment://", 13 ) ) )
{
msg_Dbg( obj, "meta ok for %s, need to fetch art",
psz_name ? psz_name : "(null)" );
--
1.9.0
More information about the vlc-devel
mailing list