From e398a81bd261feaada934e7b402b5fed57646593 Mon Sep 17 00:00:00 2001 From: Antoine Cellerier Date: Sun, 24 Sep 2006 20:51:56 +0000 Subject: [PATCH] Some more meta changes (mostly cleanup and check the i_mandatory flags) --- include/vlc_input.h | 3 + include/vlc_meta.h | 2 + include/vlc_symbols.h | 6 ++ modules/meta_engine/Modules.am | 1 - modules/meta_engine/dummy.c | 121 ------------------------------ modules/meta_engine/folder.c | 9 ++- modules/meta_engine/musicbrainz.c | 9 ++- src/input/meta.c | 111 ++++++++++++++++++--------- src/input/subtitles.c | 15 +--- 9 files changed, 104 insertions(+), 173 deletions(-) delete mode 100644 modules/meta_engine/dummy.c diff --git a/include/vlc_input.h b/include/vlc_input.h index bf67e6e9f1..64fc5b9a5c 100644 --- a/include/vlc_input.h +++ b/include/vlc_input.h @@ -538,4 +538,7 @@ 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 diff --git a/include/vlc_meta.h b/include/vlc_meta.h index 7f97fcbebe..fd50877d92 100644 --- a/include/vlc_meta.h +++ b/include/vlc_meta.h @@ -225,4 +225,6 @@ struct meta_engine_t input_item_t *p_item; }; +VLC_EXPORT( uint32_t, input_GetMetaEngineFlags, ( vlc_meta_t *p_meta ) ); + #endif diff --git a/include/vlc_symbols.h b/include/vlc_symbols.h index a228d85d1c..42306c59df 100644 --- a/include/vlc_symbols.h +++ b/include/vlc_symbols.h @@ -544,6 +544,8 @@ struct module_symbols_t 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); }; # if defined (__PLUGIN__) # define aout_FiltersCreatePipeline (p_symbols)->aout_FiltersCreatePipeline_inner @@ -1018,6 +1020,8 @@ struct module_symbols_t # 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 # elif defined (HAVE_DYNAMIC_PLUGINS) && !defined (__BUILTIN__) /****************************************************************** * STORE_SYMBOLS: store VLC APIs into p_symbols for plugin access. @@ -1495,6 +1499,8 @@ struct module_symbols_t ((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)->net_ConvertIPv4_deprecated = NULL; \ (p_symbols)->vlc_input_item_GetInfo_deprecated = NULL; \ (p_symbols)->vlc_input_item_AddInfo_deprecated = NULL; \ diff --git a/modules/meta_engine/Modules.am b/modules/meta_engine/Modules.am index 09011735f7..a7fabc8eb3 100644 --- a/modules/meta_engine/Modules.am +++ b/modules/meta_engine/Modules.am @@ -1,5 +1,4 @@ SOURCES_musicbrainz = musicbrainz.c -SOURCES_dummy = dummy.c SOURCES_folder = folder.c SOURCES_taglib = taglib.cpp SOURCES_id3tag = id3tag.c id3genres.h $(NULL) diff --git a/modules/meta_engine/dummy.c b/modules/meta_engine/dummy.c deleted file mode 100644 index a2ee329822..0000000000 --- a/modules/meta_engine/dummy.c +++ /dev/null @@ -1,121 +0,0 @@ -/***************************************************************************** - * dummy.c - ***************************************************************************** - * Copyright (C) 2006 the VideoLAN team - * $Id$ - * - * Authors: Antoine Cellerier - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. - *****************************************************************************/ - -/***************************************************************************** - * Preamble - *****************************************************************************/ -#define _GNU_SOURCE -#include /* malloc(), free() */ - -#include -#include -#include -#include -#include - -#ifdef HAVE_SYS_STAT_H -# include -#endif - - -/***************************************************************************** - * Local prototypes - *****************************************************************************/ -static int FindMeta( vlc_object_t * ); - -/***************************************************************************** - * Module descriptor - *****************************************************************************/ - -vlc_module_begin(); -/* set_category( CAT_INTERFACE ); - set_subcategory( SUBCAT_INTERFACE_CONTROL );*/ - set_shortname( N_( "Dummy" ) ); - set_description( _("Dummy meta data") ); - - set_capability( "meta engine", 0 ); - set_callbacks( FindMeta, NULL ); -vlc_module_end(); - -/***************************************************************************** - *****************************************************************************/ -static int FindMeta( vlc_object_t *p_this ) -{ - meta_engine_t *p_me = (meta_engine_t *)p_this; - input_item_t *p_item = p_me->p_item; - - if( !p_item->p_meta ) return VLC_EGENERIC; - - uint32_t i_meta = 0; -#define CHECK( a, b ) \ - if( p_item->p_meta->psz_ ## a && *p_item->p_meta->psz_ ## a ) \ - i_meta |= VLC_META_ENGINE_ ## b; - - CHECK( title, TITLE ) - CHECK( author, AUTHOR ) - CHECK( artist, ARTIST ) - CHECK( genre, GENRE ) - CHECK( copyright, COPYRIGHT ) - CHECK( album, COLLECTION ) - CHECK( tracknum, SEQ_NUM ) - CHECK( description, DESCRIPTION ) - CHECK( rating, RATING ) - CHECK( date, DATE ) - CHECK( url, URL ) - CHECK( language, LANGUAGE ) - CHECK( arturl, ART_URL ) - - if( !( i_meta & VLC_META_ENGINE_ART_URL ) - && ( p_me->i_mandatory & VLC_META_ENGINE_ART_URL ) ) - { - if( i_meta & VLC_META_ENGINE_COLLECTION - && i_meta & VLC_META_ENGINE_ARTIST ) - { - char *psz_filename; - struct stat a; - asprintf( &psz_filename, - "file://%s" DIR_SEP CONFIG_DIR DIR_SEP "art" - DIR_SEP "%s" DIR_SEP "%s" DIR_SEP "art.jpg", /* ahem ... we can have other filetype too... */ - p_me->p_libvlc->psz_homedir, - p_item->p_meta->psz_artist, - p_item->p_meta->psz_album ); - if( utf8_stat( psz_filename+7, &a ) != -1 ) - { - vlc_meta_SetArtURL( p_item->p_meta, psz_filename ); - i_meta |= VLC_META_ENGINE_ART_URL; - } - free( psz_filename ); - } - } - - /* Add checks for musicbrainz meta */ - - if( ( p_me->i_mandatory & i_meta ) == p_me->i_mandatory ) - { - return VLC_SUCCESS; - } - else - { - return VLC_EGENERIC; - } -} diff --git a/modules/meta_engine/folder.c b/modules/meta_engine/folder.c index ea7aee3088..00f3288959 100644 --- a/modules/meta_engine/folder.c +++ b/modules/meta_engine/folder.c @@ -67,6 +67,7 @@ static int FindMeta( vlc_object_t *p_this ) meta_engine_t *p_me = (meta_engine_t *)p_this; input_item_t *p_item = p_me->p_item; vlc_bool_t b_have_art = VLC_FALSE; + uint32_t i_meta; if( !p_item->p_meta ) return VLC_EGENERIC; @@ -123,5 +124,11 @@ static int FindMeta( vlc_object_t *p_this ) free( psz_dir ); } - return VLC_SUCCESS; + i_meta = input_GetMetaEngineFlags( p_item->p_meta ); + p_me->i_mandatory &= ~i_meta; + p_me->i_optional &= ~i_meta; + if( p_me->i_mandatory ) + return VLC_EGENERIC; + else + return VLC_SUCCESS; } diff --git a/modules/meta_engine/musicbrainz.c b/modules/meta_engine/musicbrainz.c index 74fac78345..58230ef7e5 100644 --- a/modules/meta_engine/musicbrainz.c +++ b/modules/meta_engine/musicbrainz.c @@ -67,6 +67,7 @@ static int FindMeta( vlc_object_t *p_this ) char psz_data[256]; char i_album_count, i; char *ppsz_args[4]; + uint32_t i_meta; if( !p_item->p_meta ) return VLC_EGENERIC; psz_artist = p_item->p_meta->psz_artist; @@ -132,5 +133,11 @@ static int FindMeta( vlc_object_t *p_this ) mb_Delete( p_mb ); - return VLC_SUCCESS; + i_meta = input_GetMetaEngineFlags( p_item->p_meta ); + p_me->i_mandatory &= ~i_meta; + p_me->i_optional &= ~i_meta; + if( p_me->i_mandatory ) + return VLC_EGENERIC; + else + return VLC_SUCCESS; } diff --git a/src/input/meta.c b/src/input/meta.c index 33cca2e7b4..564f212b8e 100644 --- a/src/input/meta.c +++ b/src/input/meta.c @@ -32,35 +32,48 @@ # include #endif +int input_FindArt( vlc_object_t *p_parent, input_item_t *p_item ); + int __input_MetaFetch( vlc_object_t *p_parent, input_item_t *p_item ) { struct meta_engine_t *p_me; + uint32_t i_mandatory = 0, i_optional = 0, i_meta; + int i_policy; - /* FIXME: don't launch any module if we already have all the needed - * info. Easiest way to do this would be to add a dummy module. - * I'll do that later */ + if( !p_item->p_meta ) return VLC_EGENERIC; - p_me = vlc_object_create( p_parent, VLC_OBJECT_META_ENGINE ); - p_me->i_flags |= OBJECT_FLAGS_NOINTERACT; - p_me->i_mandatory = VLC_META_ENGINE_TITLE - | VLC_META_ENGINE_ARTIST; - p_me->i_optional = 0; -/* - if( var_CreateGetInteger( p_parent, "album-art" ) != ALBUM_ART_NEVER ) + i_policy = var_CreateGetInteger( p_parent, "album-art" ); + + i_mandatory = VLC_META_ENGINE_TITLE + | VLC_META_ENGINE_ARTIST; + if( i_policy == ALBUM_ART_ALL ) { - p_me->i_mandatory |= VLC_META_ENGINE_ART_URL; + i_mandatory |= VLC_META_ENGINE_ART_URL; } else { - p_me->i_optional |= VLC_META_ENGINE_ART_URL; + i_optional |= VLC_META_ENGINE_ART_URL; } -*/ + + input_FindArt( p_parent, p_item ); + + i_meta = input_GetMetaEngineFlags( p_item->p_meta ); + i_mandatory &= ~i_meta; + i_optional &= ~i_meta; + + if( !i_mandatory ) return VLC_SUCCESS; + + p_me = vlc_object_create( p_parent, 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 ); if( !p_me->p_module ) { - msg_Err( p_parent, "no suitable meta engine module" ); + msg_Err( p_parent, "no suitable meta fetcher module" ); vlc_object_detach( p_me ); vlc_object_destroy( p_me ); return VLC_EGENERIC; @@ -68,6 +81,7 @@ int __input_MetaFetch( vlc_object_t *p_parent, input_item_t *p_item ) module_Unneed( p_me, p_me->p_module ); + vlc_object_detach( p_me ); vlc_object_destroy( p_me ); return VLC_SUCCESS; @@ -82,36 +96,34 @@ int input_FindArt( vlc_object_t *p_parent, input_item_t *p_item ) char *psz_album; char *psz_type; char psz_filename[MAX_PATH]; - int i_ret; + int i; struct stat a; + const char ppsz_type[] = { ".jpg", ".png", ".gif", ".bmp", "" }; if( !p_item->p_meta ) return VLC_EGENERIC; psz_artist = p_item->p_meta->psz_artist; psz_album = p_item->p_meta->psz_album; - //FIXME !!!!! - psz_type = strdup( "jpg" ); - - 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, - psz_artist, psz_album, psz_type ); - - /* Check if file exists */ - i_ret = utf8_stat( psz_filename+7, &a ); - if( i_ret == 0 ) - { - msg_Dbg( p_parent, "album art %s already exists in cache" - , psz_filename ); - return VLC_SUCCESS; - } - else + for( i = 0; i < 5; i++ ) { - /* Use a art finder module to find the URL */ - return VLC_EGENERIC; + 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, + psz_artist, psz_album, psz_type ); + + /* Check if file exists */ + if( utf8_stat( psz_filename+7, &a ) == 0 ) + { + msg_Dbg( p_parent, "album art %s already exists in cache" + , psz_filename ); + return VLC_SUCCESS; + } } + + /* Use a art finder module to find the URL */ + return VLC_EGENERIC; } /** @@ -121,8 +133,6 @@ int input_FindArt( vlc_object_t *p_parent, input_item_t *p_item ) int input_DownloadAndCacheArt( vlc_object_t *p_parent, input_item_t *p_item ) { int i_status = VLC_EGENERIC; - int i_ret; - struct stat a; stream_t *p_stream; char psz_filename[MAX_PATH], psz_dir[MAX_PATH]; char *psz_artist; @@ -136,6 +146,8 @@ int input_DownloadAndCacheArt( vlc_object_t *p_parent, input_item_t *p_item ) || !*p_item->p_meta->psz_arturl ) return VLC_EGENERIC; + psz_type = strrchr( p_item->p_meta->psz_arturl, '.' ); + /* Todo: get a helper to do this */ snprintf( psz_filename, MAX_PATH, "file://%s" DIR_SEP CONFIG_DIR DIR_SEP "art" @@ -181,3 +193,28 @@ 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 i_meta = 0; + +#define CHECK( a, b ) \ + if( p_meta->psz_ ## a && *p_meta->psz_ ## a ) \ + i_meta |= VLC_META_ENGINE_ ## b; + + CHECK( title, TITLE ) + CHECK( author, AUTHOR ) + CHECK( artist, ARTIST ) + CHECK( genre, GENRE ) + CHECK( copyright, COPYRIGHT ) + CHECK( album, COLLECTION ) + CHECK( tracknum, SEQ_NUM ) + CHECK( description, DESCRIPTION ) + CHECK( rating, RATING ) + CHECK( date, DATE ) + CHECK( url, URL ) + CHECK( language, LANGUAGE ) + CHECK( arturl, ART_URL ) + + return i_meta; +} diff --git a/src/input/subtitles.c b/src/input/subtitles.c index 3efc30729b..9ce393d3ff 100644 --- a/src/input/subtitles.c +++ b/src/input/subtitles.c @@ -46,15 +46,6 @@ #include -/** - * What's between a directory and a filename? - */ -#if defined( WIN32 ) - #define DIRECTORY_SEPARATOR '\\' -#else - #define DIRECTORY_SEPARATOR '/' -#endif - /** * We are not going to autodetect more subtitle files than this. */ @@ -231,7 +222,7 @@ static char **paths_to_list( char *psz_dir, char *psz_path ) psz_subdir[0] == '.' ? psz_dir : "", psz_subdir, psz_subdir[strlen(psz_subdir) - 1] == - DIRECTORY_SEPARATOR ? '\0' : DIRECTORY_SEPARATOR ); + DIR_SEP ? '\0' : DIR_SEP ); subdirs[i] = psz_temp; i++; } @@ -286,7 +277,7 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path, } /* extract filename & dirname from psz_fname */ - tmp = strrchr( psz_fname, DIRECTORY_SEPARATOR ); + tmp = strrchr( psz_fname, DIR_SEP ); if( tmp ) { int dirlen = 0; @@ -313,7 +304,7 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path, } dirlen = strlen( f_dir ); f_dir = (char *)realloc(f_dir, dirlen +2 ); - f_dir[dirlen] = DIRECTORY_SEPARATOR; + f_dir[dirlen] = DIR_SEP; f_dir[dirlen+1] = '\0'; f_fname = FromLocaleDup( psz_fname ); } -- 2.39.2