Commit 8fa822f7 authored by Francois Cartegnie's avatar Francois Cartegnie

Flag some input_item with uid to speed up cached elements based on lua retrievals

parent ac5631c7
......@@ -37,6 +37,7 @@
#include <vlc_services_discovery.h>
#include <vlc_playlist.h>
#include <vlc_charset.h>
#include <vlc_md5.h>
#include "../vlc.h"
#include "../libs.h"
......@@ -256,6 +257,27 @@ static int vlclua_sd_add_item( lua_State *L )
else
services_discovery_AddItem( p_sd, p_input, NULL );
lua_pop( L, 1 );
/* string to build the input item uid */
lua_getfield( L, -1, "uiddata" );
if( lua_isstring( L, -1 ) )
{
char *s = strdup( luaL_checkstring( L, -1 ) );
if ( s )
{
struct md5_s md5;
InitMD5( &md5 );
AddMD5( &md5, s, strlen( s ) );
EndMD5( &md5 );
free( s );
s = psz_md5_hash( &md5 );
if ( s )
input_item_AddInfo( p_input, "uid", "md5", "%s", s );
free( s );
}
}
lua_pop( L, 1 );
input_item_t **udata = (input_item_t **)
lua_newuserdata( L, sizeof( input_item_t * ) );
*udata = p_input;
......
......@@ -43,6 +43,8 @@ function main()
title=station_name,
genre=station.children_map["genre"][1].children[1],
nowplaying=station.children_map["current_song"][1].children[1],
uiddata=station.children_map["listen_url"][1].children[1]
.. station.children_map["listen_url"][1].children[1],
meta={
["Listing Source"]="dir.xiph.org",
["Icecast Bitrate"]=station.children_map["bitrate"][1].children[1],
......
......@@ -204,6 +204,61 @@ int playlist_FindArtInCache( input_item_t *p_item )
return b_found ? VLC_SUCCESS : VLC_EGENERIC;
}
static char * GetDirByItemUIDs( char *psz_uid )
{
char *psz_cachedir = config_GetUserDir(VLC_CACHE_DIR);
char *psz_dir;
if( asprintf( &psz_dir, "%s" DIR_SEP
"by-iiuid" DIR_SEP
"%s",
psz_cachedir, psz_uid ) == -1 )
{
psz_dir = NULL;
}
free( psz_cachedir );
return psz_dir;
}
static char * GetFileByItemUID( char *psz_dir, const char *psz_type )
{
char *psz_file;
if( asprintf( &psz_file, "%s" DIR_SEP "%s", psz_dir, psz_type ) == -1 )
{
psz_file = NULL;
}
return psz_file;
}
int playlist_FindArtInCacheUsingItemUID( input_item_t *p_item )
{
char *uid = input_item_GetInfo( p_item, "uid", "md5" );
if ( !uid ) return VLC_EGENERIC;
/* we have an input item uid set */
bool b_done = false;
char *psz_byuiddir = GetDirByItemUIDs( uid );
char *psz_byuidfile = GetFileByItemUID( psz_byuiddir, "arturl" );
free( psz_byuiddir );
if( psz_byuidfile )
{
FILE *fd = vlc_fopen( psz_byuidfile, "rb" );
if ( fd )
{
char sz_cachefile[2049];
/* read the cache hash url */
if ( fgets( sz_cachefile, 2048, fd ) != NULL )
{
input_item_SetArtURL( p_item, sz_cachefile );
b_done = true;
}
fclose( fd );
}
free( psz_byuidfile );
}
free( uid );
if ( b_done ) return VLC_SUCCESS;
return VLC_EGENERIC;
}
/* */
int playlist_SaveArt( playlist_t *p_playlist, input_item_t *p_item,
......@@ -246,8 +301,32 @@ int playlist_SaveArt( playlist_t *p_playlist, input_item_t *p_item,
}
fclose( f );
}
free( psz_filename );
free( psz_uri );
/* save uid info */
char *uid = input_item_GetInfo( p_item, "uid", "md5" );
if ( !uid ) goto end;
char *psz_byuiddir = GetDirByItemUIDs( uid );
char *psz_byuidfile = GetFileByItemUID( psz_byuiddir, "arturl" );
ArtCacheCreateDir( psz_byuiddir );
free( psz_byuiddir );
if ( psz_byuidfile )
{
f = vlc_fopen( psz_byuidfile, "wb" );
if ( f )
{
if( fputs( "file://", f ) < 0 || fputs( psz_filename, f ) < 0 )
msg_Err( p_playlist, "Error writing %s: %m", psz_byuidfile );
fclose( f );
}
free( psz_byuidfile );
}
free( uid );
/* !save uid info */
end:
free( psz_filename );
return VLC_SUCCESS;
}
......@@ -35,6 +35,7 @@ typedef struct
} playlist_album_t;
int playlist_FindArtInCache( input_item_t * );
int playlist_FindArtInCacheUsingItemUID( input_item_t * );
int playlist_SaveArt( playlist_t *, input_item_t *, const uint8_t *p_buffer, int i_buffer, const char *psz_type );
......
......@@ -177,7 +177,10 @@ static int FindArt( playlist_fetcher_t *p_fetcher, input_item_t *p_item )
free( psz_artist );
free( psz_album );
playlist_FindArtInCache( p_item );
if ( playlist_FindArtInCacheUsingItemUID( p_item ) != VLC_SUCCESS )
playlist_FindArtInCache( p_item );
else
msg_Dbg( p_fetcher->p_playlist, "successfully retrieved arturl by uid" );
char *psz_arturl = input_item_GetArtURL( p_item );
if( psz_arturl )
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment