Commit 3f1e3abe authored by Clément Stenac's avatar Clément Stenac

Auto load and save media library (Closes:#433)

parent f787ec76
......@@ -260,6 +260,8 @@ enum
STATS_LOST_PICTURES,
STATS_TIMER_PLAYLIST_WALK,
STATS_TIMER_ML_LOAD,
STATS_TIMER_ML_DUMP,
STATS_TIMER_INTERACTION,
STATS_TIMER_PREPARSE,
......
......@@ -142,6 +142,9 @@ struct playlist_t
vlc_bool_t b_always_tree;/**< Always display as tree */
vlc_bool_t b_never_tree;/**< Never display as tree */
vlc_bool_t b_doing_ml; /**< Doing media library stuff, */
/*get quicker */
/* Runtime */
input_thread_t * p_input; /**< the input thread associated
* with the current item */
......@@ -260,6 +263,8 @@ VLC_EXPORT( int, playlist_RecursiveNodeSort, ( playlist_t *, playlist_item_t *,
/* Load/Save */
VLC_EXPORT( int, playlist_Import, ( playlist_t *, const char *, playlist_item_t *, vlc_bool_t ) );
VLC_EXPORT( int, playlist_Export, ( playlist_t *, const char *, playlist_item_t *, const char * ) );
int playlist_MLLoad( playlist_t *p_playlist );
int playlist_MLDump( playlist_t *p_playlist );
/********************************************************
* Item management
......
......@@ -76,31 +76,10 @@ static void vlc_input_item_Destroy ( gc_object_t *p_this )
playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_obj,
VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
utf8_fprintf( stderr, "Destroying %s\n", p_input->psz_name );
vlc_input_item_Clean( p_input );
if( p_playlist )
{
#if 0
i_bottom = 0; i_top = p_playlist->i_input_items - 1;
i = i_top / 2;
while( p_playlist->pp_input_items[i]->i_id != p_input->i_id &&
i_top > i_bottom )
{
if( p_playlist->pp_input_items[i]->i_id < p_input->i_id )
i_bottom = i + 1;
else
i_top = i -1;
i = i_bottom + ( i_top - i_bottom ) / 2;
}
if( p_playlist->pp_input_items[i]->i_id == p_input->i_id )
{
REMOVE_ELEM( p_playlist->pp_input_items,
p_playlist->i_input_items, i );
}
#endif
for( i = 0 ; i< p_playlist->i_input_items ; i++ )
{
if( p_playlist->pp_input_items[i]->i_id == p_input->i_id )
......
......@@ -81,6 +81,8 @@ playlist_t * playlist_Create( vlc_object_t *p_parent )
p_playlist->b_always_tree = (i_tree == 1);
p_playlist->b_never_tree = (i_tree == 2);
p_playlist->b_doing_ml = VLC_FALSE;
p_playlist->p_root_category = playlist_NodeCreate( p_playlist, NULL, NULL);
p_playlist->p_root_onelevel = playlist_NodeCreate( p_playlist, NULL, NULL);
......@@ -106,6 +108,7 @@ playlist_t * playlist_Create( vlc_object_t *p_parent )
p_playlist->p_ml_onelevel->i_flags |= PLAYLIST_RO_FLAG;
p_playlist->p_ml_onelevel->p_input->i_id =
p_playlist->p_ml_category->p_input->i_id;
}
else
{
......@@ -114,7 +117,7 @@ playlist_t * playlist_Create( vlc_object_t *p_parent )
/* Initial status */
p_playlist->status.p_item = NULL;
p_playlist->status.p_node = p_playlist->p_root_onelevel;
p_playlist->status.p_node = p_playlist->p_local_onelevel;
p_playlist->request.b_request = VLC_FALSE;
p_playlist->status.i_status = PLAYLIST_STOPPED;
......@@ -122,6 +125,8 @@ playlist_t * playlist_Create( vlc_object_t *p_parent )
p_playlist->i_order = ORDER_NORMAL;
vlc_object_attach( p_playlist, p_parent );
playlist_MLLoad( p_playlist );
return p_playlist;
}
......@@ -132,6 +137,9 @@ void playlist_Destroy( playlist_t *p_playlist )
playlist_ServicesDiscoveryRemove( p_playlist,
p_playlist->pp_sds[0]->psz_module );
}
playlist_MLDump( p_playlist );
vlc_thread_join( p_playlist->p_preparse );
vlc_thread_join( p_playlist );
......
......@@ -219,7 +219,9 @@ int playlist_AddInput( playlist_t* p_playlist, input_item_t *p_input,
{
playlist_item_t *p_item_cat, *p_item_one;
PL_DEBUG( "adding item `%s' ( %s )", p_input->psz_name, p_input->psz_uri );
if( !p_playlist->b_doing_ml )
PL_DEBUG( "adding item `%s' ( %s )", p_input->psz_name,
p_input->psz_uri );
vlc_mutex_lock( &p_playlist->object_lock );
......@@ -392,16 +394,15 @@ playlist_item_t *playlist_ItemToNode( playlist_t *p_playlist,
p_playlist->p_root_onelevel );
ChangeToNode( p_playlist, p_item_in_category );
if( p_item_in_one->p_parent == p_playlist->p_root_onelevel )
{
ChangeToNode( p_playlist, p_item_in_one );
}
else
{
playlist_DeleteFromInput( p_playlist, p_item_in_one->p_input->i_id,
p_playlist->p_root_onelevel, VLC_FALSE );
}
p_playlist->b_reset_random = VLC_TRUE;
var_SetInteger( p_playlist, "item-change", p_item->p_input->i_id );
var_SetInteger( p_playlist, "item-change", p_item_in_category->
p_input->i_id );
return p_item_in_category;
}
else
......@@ -572,7 +573,7 @@ void AddItem( playlist_t *p_playlist, playlist_item_t *p_item,
{
playlist_NodeInsert( p_playlist, p_item, p_node, i_pos );
}
if( !p_playlist->b_doing_ml )
playlist_SendAddNotify( p_playlist, p_item->i_id, p_node->i_id );
}
......
......@@ -33,7 +33,11 @@
#include "vlc_playlist.h"
#include "charset.h"
#define PLAYLIST_FILE_HEADER "# vlc playlist file version 0.5"
#if defined( WIN32 ) || defined( UNDER_CE )
# define DIR_SEP "\\"
#else
# define DIR_SEP "/"
#endif
/**
* Import a playlist file at a given point of a given view
......@@ -55,44 +59,10 @@ int playlist_Import( playlist_t * p_playlist, const char *psz_filename,
vlc_input_item_AddOption( p_input, psz_opt );
free( psz_opt );
}
if( p_root == p_playlist->p_ml_category )
p_input->i_id = p_playlist->p_ml_category->p_input->i_id;
playlist_PlaylistAddInput( p_playlist, p_input, PLAYLIST_APPEND,
PLAYLIST_END );
input_Read( p_playlist, p_input, VLC_TRUE );
free( psz_uri );
return VLC_SUCCESS;
}
/**
* Load a playlist file to the playlist. It will create a new node in
* category
*
* \param p_playlist the playlist to which the new items will be added
* \param psz_filename the name of the playlistfile to import
* \return VLC_SUCCESS on success
*/
int playlist_Load( playlist_t * p_playlist, const char *psz_filename )
{
playlist_item_t *p_item;
char *psz_uri;
int i_id;
msg_Info( p_playlist, "clearing playlist");
playlist_Clear( p_playlist );
psz_uri = (char *)malloc(sizeof(char)*strlen(psz_filename) + 17 );
sprintf( psz_uri, "file/playlist://%s", psz_filename);
i_id = playlist_PlaylistAdd( p_playlist, psz_uri, psz_uri,
PLAYLIST_INSERT , PLAYLIST_END);
vlc_mutex_lock( &p_playlist->object_lock );
p_item = playlist_ItemGetById( p_playlist, i_id );
vlc_mutex_unlock( &p_playlist->object_lock );
playlist_Play(p_playlist);
return VLC_SUCCESS;
}
......@@ -160,3 +130,52 @@ int playlist_Export( playlist_t * p_playlist, const char *psz_filename ,
return VLC_SUCCESS;
}
int playlist_MLLoad( playlist_t *p_playlist )
{
char *psz_uri, *psz_homedir =p_playlist->p_vlc->psz_homedir;
input_item_t *p_input;
if( !config_GetInt( p_playlist, "media-library") ) return VLC_SUCCESS;
if( !psz_homedir )
{
msg_Err( p_playlist, "no home directory, cannot load media library") ;
return VLC_EGENERIC;
}
asprintf( &psz_uri, "file/xspf-open://%s" DIR_SEP CONFIG_DIR DIR_SEP
"ml.xsp", psz_homedir );
p_input = input_ItemNewExt( p_playlist, psz_uri,
_("Media Library"), 0, NULL, -1 );
p_playlist->p_ml_category->p_input = p_input;
p_playlist->p_ml_onelevel->p_input = p_input;
p_playlist->b_doing_ml = VLC_TRUE;
stats_TimerStart( p_playlist, "ML Load", STATS_TIMER_ML_LOAD );
input_Read( p_playlist, p_input, VLC_TRUE );
stats_TimerStop( p_playlist,STATS_TIMER_ML_LOAD );
p_playlist->b_doing_ml = VLC_FALSE;
free( psz_uri );
return VLC_SUCCESS;
}
int playlist_MLDump( playlist_t *p_playlist )
{
char *psz_uri, *psz_homedir =p_playlist->p_vlc->psz_homedir;
if( !config_GetInt( p_playlist, "media-library") ) return VLC_SUCCESS;
if( !psz_homedir )
{
msg_Err( p_playlist, "no home directory, cannot load media library") ;
return VLC_EGENERIC;
}
asprintf( &psz_uri, "%s" DIR_SEP CONFIG_DIR DIR_SEP
"ml.xsp", psz_homedir );
stats_TimerStart( p_playlist, "ML Dump", STATS_TIMER_ML_DUMP );
playlist_Export( p_playlist, psz_uri, p_playlist->p_ml_category,
"export-xspf" );
stats_TimerStop( p_playlist, STATS_TIMER_ML_DUMP );
free( psz_uri );
return VLC_SUCCESS;
}
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