| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
#ifndef _GNU_SOURCE |
|---|
| 29 |
# define _GNU_SOURCE |
|---|
| 30 |
#endif |
|---|
| 31 |
|
|---|
| 32 |
#ifdef HAVE_CONFIG_H |
|---|
| 33 |
# include "config.h" |
|---|
| 34 |
#endif |
|---|
| 35 |
|
|---|
| 36 |
#include <vlc_common.h> |
|---|
| 37 |
#include <vlc_input.h> |
|---|
| 38 |
#include <vlc_playlist.h> |
|---|
| 39 |
#include <vlc_meta.h> |
|---|
| 40 |
#include <vlc_url.h> |
|---|
| 41 |
#include <vlc_strings.h> |
|---|
| 42 |
#include <vlc_stream.h> |
|---|
| 43 |
#include <vlc_charset.h> |
|---|
| 44 |
|
|---|
| 45 |
#include "vlc.h" |
|---|
| 46 |
#include "libs.h" |
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
static int fetch_art( vlc_object_t *p_this, const char * psz_filename, |
|---|
| 53 |
lua_State * L, void * user_data ); |
|---|
| 54 |
static lua_State *vlclua_meta_init( vlc_object_t *p_this, |
|---|
| 55 |
input_item_t * p_item ); |
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
static const luaL_Reg p_reg[] = { { NULL, NULL } }; |
|---|
| 62 |
|
|---|
| 63 |
static lua_State * vlclua_meta_init( vlc_object_t *p_this, input_item_t * p_item ) |
|---|
| 64 |
{ |
|---|
| 65 |
lua_State * L = luaL_newstate(); |
|---|
| 66 |
if( !L ) |
|---|
| 67 |
{ |
|---|
| 68 |
msg_Err( p_this, "Could not create new Lua State" ); |
|---|
| 69 |
return NULL; |
|---|
| 70 |
} |
|---|
| 71 |
char *psz_meta; |
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
luaL_openlibs( L ); |
|---|
| 75 |
|
|---|
| 76 |
luaL_register( L, "vlc", p_reg ); |
|---|
| 77 |
|
|---|
| 78 |
luaopen_msg( L ); |
|---|
| 79 |
luaopen_stream( L ); |
|---|
| 80 |
luaopen_strings( L ); |
|---|
| 81 |
luaopen_variables( L ); |
|---|
| 82 |
luaopen_object( L ); |
|---|
| 83 |
luaopen_misc( L ); |
|---|
| 84 |
|
|---|
| 85 |
lua_pushlightuserdata( L, p_this ); |
|---|
| 86 |
lua_setfield( L, -2, "private" ); |
|---|
| 87 |
|
|---|
| 88 |
psz_meta = input_item_GetName( p_item ); |
|---|
| 89 |
lua_pushstring( L, psz_meta ); |
|---|
| 90 |
lua_setfield( L, -2, "name" ); |
|---|
| 91 |
free( psz_meta ); |
|---|
| 92 |
|
|---|
| 93 |
psz_meta = input_item_GetArtist( p_item ); |
|---|
| 94 |
lua_pushstring( L, psz_meta ); |
|---|
| 95 |
lua_setfield( L, -2, "artist" ); |
|---|
| 96 |
free( psz_meta ); |
|---|
| 97 |
|
|---|
| 98 |
psz_meta = input_item_GetTitle( p_item ) ; |
|---|
| 99 |
lua_pushstring( L, psz_meta ); |
|---|
| 100 |
lua_setfield( L, -2, "title" ); |
|---|
| 101 |
free( psz_meta ); |
|---|
| 102 |
|
|---|
| 103 |
psz_meta = input_item_GetAlbum( p_item ); |
|---|
| 104 |
lua_pushstring( L, psz_meta ); |
|---|
| 105 |
lua_setfield( L, -2, "album" ); |
|---|
| 106 |
free( psz_meta ); |
|---|
| 107 |
|
|---|
| 108 |
psz_meta = input_item_GetArtURL( p_item ); |
|---|
| 109 |
lua_pushstring( L, psz_meta ); |
|---|
| 110 |
lua_setfield( L, -2, "arturl" ); |
|---|
| 111 |
free( psz_meta ); |
|---|
| 112 |
|
|---|
| 113 |
|
|---|
| 114 |
return L; |
|---|
| 115 |
} |
|---|
| 116 |
|
|---|
| 117 |
|
|---|
| 118 |
|
|---|
| 119 |
|
|---|
| 120 |
|
|---|
| 121 |
static int fetch_art( vlc_object_t *p_this, const char * psz_filename, |
|---|
| 122 |
lua_State * L, void * user_data ) |
|---|
| 123 |
{ |
|---|
| 124 |
int i_ret = VLC_EGENERIC; |
|---|
| 125 |
input_item_t * p_input = user_data; |
|---|
| 126 |
int s; |
|---|
| 127 |
|
|---|
| 128 |
|
|---|
| 129 |
|
|---|
| 130 |
lua_pushnil( L ); |
|---|
| 131 |
lua_setglobal( L, "fetch_art" ); |
|---|
| 132 |
|
|---|
| 133 |
|
|---|
| 134 |
if( luaL_dofile( L, psz_filename ) ) |
|---|
| 135 |
{ |
|---|
| 136 |
msg_Warn( p_this, "Error loading script %s: %s", psz_filename, |
|---|
| 137 |
lua_tostring( L, lua_gettop( L ) ) ); |
|---|
| 138 |
lua_pop( L, 1 ); |
|---|
| 139 |
return VLC_EGENERIC; |
|---|
| 140 |
} |
|---|
| 141 |
|
|---|
| 142 |
lua_getglobal( L, "fetch_art" ); |
|---|
| 143 |
|
|---|
| 144 |
if( !lua_isfunction( L, lua_gettop( L ) ) ) |
|---|
| 145 |
{ |
|---|
| 146 |
msg_Warn( p_this, "Error while runing script %s, " |
|---|
| 147 |
"function fetch_art() not found", psz_filename ); |
|---|
| 148 |
lua_pop( L, 1 ); |
|---|
| 149 |
return VLC_EGENERIC; |
|---|
| 150 |
} |
|---|
| 151 |
|
|---|
| 152 |
if( lua_pcall( L, 0, 1, 0 ) ) |
|---|
| 153 |
{ |
|---|
| 154 |
msg_Warn( p_this, "Error while runing script %s, " |
|---|
| 155 |
"function fetch_art(): %s", psz_filename, |
|---|
| 156 |
lua_tostring( L, lua_gettop( L ) ) ); |
|---|
| 157 |
lua_pop( L, 1 ); |
|---|
| 158 |
return VLC_EGENERIC; |
|---|
| 159 |
} |
|---|
| 160 |
|
|---|
| 161 |
if((s = lua_gettop( L ))) |
|---|
| 162 |
{ |
|---|
| 163 |
const char * psz_value; |
|---|
| 164 |
|
|---|
| 165 |
if( lua_isstring( L, s ) ) |
|---|
| 166 |
{ |
|---|
| 167 |
psz_value = lua_tostring( L, s ); |
|---|
| 168 |
if( psz_value && *psz_value != 0 ) |
|---|
| 169 |
{ |
|---|
| 170 |
lua_Dbg( p_this, "setting arturl: %s", psz_value ); |
|---|
| 171 |
input_item_SetArtURL ( p_input, psz_value ); |
|---|
| 172 |
i_ret = VLC_SUCCESS; |
|---|
| 173 |
} |
|---|
| 174 |
} |
|---|
| 175 |
else if( !lua_isnil( L, s ) ) |
|---|
| 176 |
{ |
|---|
| 177 |
msg_Err( p_this, "Lua art fetcher script %s: " |
|---|
| 178 |
"didn't return a string", psz_filename ); |
|---|
| 179 |
} |
|---|
| 180 |
} |
|---|
| 181 |
else |
|---|
| 182 |
{ |
|---|
| 183 |
msg_Err( p_this, "Script went completely foobar" ); |
|---|
| 184 |
} |
|---|
| 185 |
|
|---|
| 186 |
return i_ret; |
|---|
| 187 |
} |
|---|
| 188 |
|
|---|
| 189 |
|
|---|
| 190 |
|
|---|
| 191 |
|
|---|
| 192 |
int FindArt( vlc_object_t *p_this ) |
|---|
| 193 |
{ |
|---|
| 194 |
playlist_t *p_playlist = (playlist_t *)p_this; |
|---|
| 195 |
input_item_t *p_item = (input_item_t *)(p_playlist->p_private); |
|---|
| 196 |
lua_State *L = vlclua_meta_init( p_this, p_item ); |
|---|
| 197 |
|
|---|
| 198 |
int i_ret = vlclua_scripts_batch_execute( p_this, "meta", &fetch_art, L, p_item ); |
|---|
| 199 |
lua_close( L ); |
|---|
| 200 |
return i_ret; |
|---|
| 201 |
} |
|---|
| 202 |
|
|---|