#include <vlc_services_discovery.h>
#include <vlc_playlist.h>
#include <vlc_charset.h>
+#include <vlc_md5.h>
#include "../vlc.h"
#include "../libs.h"
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;
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],
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,
}
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;
}