Commit a0cbc6ed authored by zorglub's avatar zorglub
Browse files

Improve meta/art logic

parent 71079c79
......@@ -474,10 +474,11 @@ VLC_EXPORT( void, input_StopThread, ( input_thread_t * ) );
VLC_EXPORT( void, input_DestroyThread, ( input_thread_t * ) );
#define input_MetaFetch(a,b) __input_MetaFetch(VLC_OBJECT(a),b)
VLC_EXPORT( int, __input_MetaFetch, ( vlc_object_t *, input_item_t * ) );
#define input_ArtFetch(a,b) __input_ArtFetch(VLC_OBJECT(a),b)
VLC_EXPORT( int, __input_ArtFetch, ( vlc_object_t *, input_item_t * ) );
int input_MetaFetch ( playlist_t *, input_item_t * );
int input_ArtFetch ( playlist_t *, input_item_t * );
vlc_bool_t input_MetaSatisfied ( playlist_t*, input_item_t*,
uint32_t*, uint32_t*, vlc_bool_t );
int input_DownloadAndCacheArt ( playlist_t *, input_item_t * );
enum input_query_e
{
......@@ -540,7 +541,6 @@ VLC_EXPORT( void, input_DecoderDecode,( decoder_t *, block_t * ) );
VLC_EXPORT( vlc_bool_t, input_AddSubtitles, ( input_thread_t *, char *, vlc_bool_t ) );
VLC_EXPORT( int, input_DownloadAndCacheArt, ( vlc_object_t *p_parent, input_item_t *p_item ) );
#endif
......@@ -225,6 +225,6 @@ struct meta_engine_t
input_item_t *p_item;
};
VLC_EXPORT( uint32_t, input_GetMetaEngineFlags, ( vlc_meta_t *p_meta ) );
uint32_t input_CurrentMetaFlags( vlc_meta_t *p_meta );
#endif
......@@ -543,10 +543,10 @@ struct module_symbols_t
char * (*input_ItemGetInfo_inner) (input_item_t *p_i, const char *psz_cat,const char *psz_name);
int (*input_ItemAddInfo_inner) (input_item_t *p_i, const char *psz_cat, const char *psz_name, const char *psz_format, ...);
void (*input_ItemAddOptionNoDup_inner) (input_item_t *, const char *);
int (*__input_MetaFetch_inner) (vlc_object_t *, input_item_t *);
int (*input_DownloadAndCacheArt_inner) (vlc_object_t *p_parent, input_item_t *p_item);
uint32_t (*input_GetMetaEngineFlags_inner) (vlc_meta_t *p_meta);
int (*__input_ArtFetch_inner) (vlc_object_t *, input_item_t *);
void *__input_MetaFetch_deprecated;
void *input_DownloadAndCacheArt_deprecated;
void *input_GetMetaEngineFlags_deprecated;
void *__input_ArtFetch_deprecated;
void *input_AskForArt_deprecated;
int (*playlist_AskForArtEnqueue_inner) (playlist_t *, input_item_t *);
};
......@@ -1022,10 +1022,6 @@ struct module_symbols_t
# define input_ItemGetInfo (p_symbols)->input_ItemGetInfo_inner
# define input_ItemAddInfo (p_symbols)->input_ItemAddInfo_inner
# define input_ItemAddOptionNoDup (p_symbols)->input_ItemAddOptionNoDup_inner
# define __input_MetaFetch (p_symbols)->__input_MetaFetch_inner
# define input_DownloadAndCacheArt (p_symbols)->input_DownloadAndCacheArt_inner
# define input_GetMetaEngineFlags (p_symbols)->input_GetMetaEngineFlags_inner
# define __input_ArtFetch (p_symbols)->__input_ArtFetch_inner
# define playlist_AskForArtEnqueue (p_symbols)->playlist_AskForArtEnqueue_inner
# elif defined (HAVE_DYNAMIC_PLUGINS) && !defined (__BUILTIN__)
/******************************************************************
......@@ -1503,10 +1499,6 @@ struct module_symbols_t
((p_symbols)->input_ItemGetInfo_inner) = input_ItemGetInfo; \
((p_symbols)->input_ItemAddInfo_inner) = input_ItemAddInfo; \
((p_symbols)->input_ItemAddOptionNoDup_inner) = input_ItemAddOptionNoDup; \
((p_symbols)->__input_MetaFetch_inner) = __input_MetaFetch; \
((p_symbols)->input_DownloadAndCacheArt_inner) = input_DownloadAndCacheArt; \
((p_symbols)->input_GetMetaEngineFlags_inner) = input_GetMetaEngineFlags; \
((p_symbols)->__input_ArtFetch_inner) = __input_ArtFetch; \
((p_symbols)->playlist_AskForArtEnqueue_inner) = playlist_AskForArtEnqueue; \
(p_symbols)->net_ConvertIPv4_deprecated = NULL; \
(p_symbols)->vlc_input_item_GetInfo_deprecated = NULL; \
......@@ -1561,6 +1553,10 @@ struct module_symbols_t
(p_symbols)->__intf_IntfProgress_deprecated = NULL; \
(p_symbols)->streaming_ChainToPsz_deprecated = NULL; \
(p_symbols)->__input_SecondaryPreparse_deprecated = NULL; \
(p_symbols)->__input_MetaFetch_deprecated = NULL; \
(p_symbols)->input_DownloadAndCacheArt_deprecated = NULL; \
(p_symbols)->input_GetMetaEngineFlags_deprecated = NULL; \
(p_symbols)->__input_ArtFetch_deprecated = NULL; \
(p_symbols)->input_AskForArt_deprecated = NULL; \
# endif /* __PLUGIN__ */
......
......@@ -32,48 +32,50 @@
# include <sys/stat.h>
#endif
int input_FindArtInCache( vlc_object_t *p_parent, input_item_t *p_item );
int input_FindArtInCache( playlist_t *p_playlist, input_item_t *p_item );
int __input_MetaFetch( vlc_object_t *p_parent, input_item_t *p_item )
vlc_bool_t input_MetaSatisfied( playlist_t *p_playlist, input_item_t *p_item,
uint32_t *pi_mandatory, uint32_t *pi_optional,
vlc_bool_t b_check_cache )
{
// FIXME don't var_Stuff at each loop
int i_policy = var_CreateGetInteger( p_playlist, "album-art" );
if( b_check_cache )
input_FindArtInCache( p_playlist, p_item );
*pi_mandatory = VLC_META_ENGINE_TITLE | VLC_META_ENGINE_ARTIST |
(i_policy == ALBUM_ART_ALL ? VLC_META_ENGINE_ART_URL : 0 );
uint32_t i_meta = input_CurrentMetaFlags( p_item->p_meta );
*pi_mandatory &= ~i_meta;
*pi_optional = 0; /// Todo
return *pi_mandatory ? VLC_FALSE:VLC_TRUE;
}
int input_MetaFetch( playlist_t *p_playlist, input_item_t *p_item )
{
struct meta_engine_t *p_me;
uint32_t i_mandatory = 0, i_optional = 0, i_meta;
int i_policy;
uint32_t i_mandatory, i_optional;
if( !p_item->p_meta ) return VLC_EGENERIC;
i_policy = var_CreateGetInteger( p_parent, "album-art" );
i_mandatory = VLC_META_ENGINE_TITLE
| VLC_META_ENGINE_ARTIST;
if( i_policy == ALBUM_ART_ALL )
{
i_mandatory |= VLC_META_ENGINE_ART_URL;
}
else
{
i_optional |= VLC_META_ENGINE_ART_URL;
}
input_FindArtInCache( p_parent, p_item );
i_meta = input_GetMetaEngineFlags( p_item->p_meta );
i_mandatory &= ~i_meta;
i_optional &= ~i_meta;
input_MetaSatisfied( p_playlist, p_item,
&i_mandatory, &i_optional, VLC_FALSE );
if( !i_mandatory ) return VLC_SUCCESS;
// Meta shouldn't magically appear
assert( i_mandatory );
p_me = vlc_object_create( p_parent, VLC_OBJECT_META_ENGINE );
p_me = vlc_object_create( p_playlist, VLC_OBJECT_META_ENGINE );
p_me->i_flags |= OBJECT_FLAGS_NOINTERACT;
p_me->i_mandatory = i_mandatory;
p_me->i_optional = i_optional;
p_me->p_item = p_item;
p_me->p_module = module_Need( p_me, "meta fetcher", 0, VLC_FALSE );
vlc_object_attach( p_me, p_parent );
vlc_object_attach( p_me, p_playlist );
if( !p_me->p_module )
{
msg_Err( p_parent, "no suitable meta fetcher module" );
msg_Dbg( p_playlist, "unable to fetch meta" );
vlc_object_detach( p_me );
vlc_object_destroy( p_me );
return VLC_EGENERIC;
......@@ -87,27 +89,34 @@ int __input_MetaFetch( vlc_object_t *p_parent, input_item_t *p_item )
return VLC_SUCCESS;
}
int __input_ArtFetch( vlc_object_t *p_parent, input_item_t *p_item )
int input_ArtFetch( playlist_t *p_playlist, input_item_t *p_item )
{
if( !p_item->p_meta )
return VLC_EGENERIC;
/* TODO: call art fetcher modules */
if( !p_item->p_meta ) return VLC_EGENERIC;
if( !p_item->p_meta->psz_arturl || !*p_item->p_meta->psz_arturl )
return VLC_EGENERIC;
if( strncmp( "file://", p_item->p_meta->psz_arturl, 7 ) )
{
return input_DownloadAndCacheArt( p_parent, p_item );
module_t *p_module;
PL_LOCK;
p_playlist->p_private = p_item;
p_module = module_Need( p_playlist, "art finder", 0, VLC_FALSE );
if( !p_module )
{
msg_Dbg( p_playlist, "unable to find art" );
return VLC_EGENERIC;
}
module_Unneed( p_playlist, p_module );
p_playlist->p_private = NULL;
if( !p_item->p_meta->psz_arturl || !*p_item->p_meta->psz_arturl )
return VLC_EGENERIC;
}
return VLC_SUCCESS;
return input_DownloadAndCacheArt( p_playlist, p_item );
}
#ifndef MAX_PATH
# define MAX_PATH 250
#endif
int input_FindArtInCache( vlc_object_t *p_parent, input_item_t *p_item )
int input_FindArtInCache( playlist_t *p_playlist, input_item_t *p_item )
{
char *psz_artist;
char *psz_album;
......@@ -126,20 +135,19 @@ int input_FindArtInCache( vlc_object_t *p_parent, input_item_t *p_item )
snprintf( psz_filename, MAX_PATH,
"file://%s" DIR_SEP CONFIG_DIR DIR_SEP "art"
DIR_SEP "%s" DIR_SEP "%s" DIR_SEP "art%s",
p_parent->p_libvlc->psz_homedir,
p_playlist->p_libvlc->psz_homedir,
psz_artist, psz_album, ppsz_type[i] );
/* Check if file exists */
if( utf8_stat( psz_filename+7, &a ) == 0 )
{
msg_Dbg( p_parent, "album art %s already exists in cache"
msg_Dbg( p_playlist, "album art %s already exists in cache"
, psz_filename );
vlc_meta_SetArtURL( p_item->p_meta, psz_filename );
return VLC_SUCCESS;
}
}
/* Use a art finder module to find the URL */
return VLC_EGENERIC;
}
......@@ -147,7 +155,7 @@ int input_FindArtInCache( vlc_object_t *p_parent, input_item_t *p_item )
* Download the art using the URL or an art downloaded
* This function should be called only if data is not already in cache
*/
int input_DownloadAndCacheArt( vlc_object_t *p_parent, input_item_t *p_item )
int input_DownloadAndCacheArt( playlist_t *p_playlist, input_item_t *p_item )
{
int i_status = VLC_EGENERIC;
stream_t *p_stream;
......@@ -169,27 +177,27 @@ int input_DownloadAndCacheArt( vlc_object_t *p_parent, input_item_t *p_item )
snprintf( psz_filename, MAX_PATH,
"file://%s" DIR_SEP CONFIG_DIR DIR_SEP "art"
DIR_SEP "%s" DIR_SEP "%s" DIR_SEP "art%s",
p_parent->p_libvlc->psz_homedir,
p_playlist->p_libvlc->psz_homedir,
psz_artist, psz_album, psz_type );
snprintf( psz_dir, MAX_PATH, "%s" DIR_SEP CONFIG_DIR,
p_parent->p_libvlc->psz_homedir );
p_playlist->p_libvlc->psz_homedir );
utf8_mkdir( psz_dir );
snprintf( psz_dir, MAX_PATH, "%s" DIR_SEP CONFIG_DIR DIR_SEP "art",
p_parent->p_libvlc->psz_homedir );
p_playlist->p_libvlc->psz_homedir );
utf8_mkdir( psz_dir );
snprintf( psz_dir, MAX_PATH, "%s" DIR_SEP CONFIG_DIR DIR_SEP
"art" DIR_SEP "%s",
p_parent->p_libvlc->psz_homedir, psz_artist );
p_playlist->p_libvlc->psz_homedir, psz_artist );
utf8_mkdir( psz_dir );
snprintf( psz_dir, MAX_PATH, "%s" DIR_SEP CONFIG_DIR DIR_SEP
"art" DIR_SEP "%s" DIR_SEP "%s",
p_parent->p_libvlc->psz_homedir,
p_playlist->p_libvlc->psz_homedir,
psz_artist, psz_album );
utf8_mkdir( psz_dir );
/* Todo: check for stuff that needs a downloader module */
p_stream = stream_UrlNew( p_parent, p_item->p_meta->psz_arturl );
p_stream = stream_UrlNew( p_playlist, p_item->p_meta->psz_arturl );
if( p_stream )
{
......@@ -203,7 +211,7 @@ int input_DownloadAndCacheArt( vlc_object_t *p_parent, input_item_t *p_item )
free( p_buffer );
fclose( p_file );
stream_Delete( p_stream );
msg_Dbg( p_parent, "Album art saved to %s\n", psz_filename );
msg_Dbg( p_playlist, "Album art saved to %s\n", psz_filename );
free( p_item->p_meta->psz_arturl );
p_item->p_meta->psz_arturl = strdup( psz_filename );
i_status = VLC_SUCCESS;
......@@ -211,7 +219,7 @@ int input_DownloadAndCacheArt( vlc_object_t *p_parent, input_item_t *p_item )
return i_status;
}
uint32_t input_GetMetaEngineFlags( vlc_meta_t *p_meta )
uint32_t input_CurrentMetaFlags( vlc_meta_t *p_meta )
{
uint32_t i_meta = 0;
......
......@@ -447,6 +447,7 @@ void playlist_PreparseLoop( playlist_preparse_t *p_obj )
{
playlist_t *p_playlist = (playlist_t *)p_obj->p_parent;
int i_activity;
uint32_t i_m, i_o;
vlc_mutex_lock( &p_obj->object_lock );
......@@ -459,7 +460,6 @@ void playlist_PreparseLoop( playlist_preparse_t *p_obj )
if( p_current )
{
vlc_bool_t b_preparsed = VLC_FALSE;
preparse_item_t p;
if( strncmp( p_current->psz_uri, "http:", 5 ) &&
strncmp( p_current->psz_uri, "rtsp:", 5 ) &&
strncmp( p_current->psz_uri, "udp:", 4 ) &&
......@@ -484,17 +484,16 @@ void playlist_PreparseLoop( playlist_preparse_t *p_obj )
var_SetInteger( p_playlist, "item-change", p_current->i_id );
}
PL_LOCK;
/* We haven't retrieved enough meta, add to secondary queue
/* If we haven't retrieved enough meta, add to secondary queue
* which will run the "meta fetchers"
* TODO: - use i_mandatory stuff here instead of hardcoded T/A
* - don't do this for things we won't get meta for, like
* videos
* -> done in input_MetaFetch atm
* TODO:
* don't do this for things we won't get meta for, like
* videos
*/
/*if( !(p_current->p_meta->psz_title && *p_current->p_meta->psz_title
&& p_current->p_meta->psz_artist &&
*p_current->p_meta->psz_artist) )
{*/
if( !input_MetaSatisfied( p_playlist, p_current, &i_m, &i_o,
VLC_TRUE ) )
{
preparse_item_t p;
p.p_item = p_current;
p.b_fetch_art = VLC_FALSE;
vlc_mutex_lock( &p_playlist->p_secondary_preparse->object_lock);
......@@ -504,9 +503,9 @@ void playlist_PreparseLoop( playlist_preparse_t *p_obj )
p );
vlc_mutex_unlock(
&p_playlist->p_secondary_preparse->object_lock);
/*}
}
else
vlc_gc_decref( p_current );*/
vlc_gc_decref( p_current );
PL_UNLOCK;
}
else
......@@ -537,9 +536,12 @@ void playlist_SecondaryPreparseLoop( playlist_secondary_preparse_t *p_obj )
vlc_mutex_unlock( &p_obj->object_lock );
if( p_item )
{
input_MetaFetch( p_playlist, p_item );
p_item->p_meta->i_status |= ITEM_META_FETCHED;
if( b_fetch_art == VLC_TRUE )
if( !b_fetch_art )
{
input_MetaFetch( p_playlist, p_item );
p_item->p_meta->i_status |= ITEM_META_FETCHED;
}
else
{
input_ArtFetch( p_playlist, p_item );
p_item->p_meta->i_status |= ITEM_ART_FETCHED;
......@@ -547,8 +549,6 @@ void playlist_SecondaryPreparseLoop( playlist_secondary_preparse_t *p_obj )
var_SetInteger( p_playlist, "item-change", p_item->i_id );
vlc_gc_decref( p_item );
}
else
PL_UNLOCK;
return;
}
vlc_mutex_unlock( &p_obj->object_lock );
......
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