Commit e398a81b authored by Antoine Cellerier's avatar Antoine Cellerier

Some more meta changes (mostly cleanup and check the i_mandatory flags)

parent 6d6d53e1
......@@ -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
......@@ -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
......@@ -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; \
......
SOURCES_musicbrainz = musicbrainz.c
SOURCES_dummy = dummy.c
SOURCES_folder = folder.c
SOURCES_taglib = taglib.cpp
SOURCES_id3tag = id3tag.c id3genres.h $(NULL)
/*****************************************************************************
* dummy.c
*****************************************************************************
* Copyright (C) 2006 the VideoLAN team
* $Id$
*
* Authors: Antoine Cellerier <dionoea -at- videolan -dot- org>
*
* 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 <stdlib.h> /* malloc(), free() */
#include <vlc/vlc.h>
#include <vlc/intf.h>
#include <vlc_meta.h>
#include <vlc_meta.h>
#include <charset.h>
#ifdef HAVE_SYS_STAT_H
# include <sys/stat.h>
#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;
}
}
......@@ -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;
}
......@@ -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;
}
......@@ -32,35 +32,48 @@
# include <sys/stat.h>
#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;
}
......@@ -46,15 +46,6 @@
#include <ctype.h>
/**
* 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 );
}
......
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