]> git.sesse.net Git - vlc/commitdiff
Some more meta changes (mostly cleanup and check the i_mandatory flags)
authorAntoine Cellerier <dionoea@videolan.org>
Sun, 24 Sep 2006 20:51:56 +0000 (20:51 +0000)
committerAntoine Cellerier <dionoea@videolan.org>
Sun, 24 Sep 2006 20:51:56 +0000 (20:51 +0000)
include/vlc_input.h
include/vlc_meta.h
include/vlc_symbols.h
modules/meta_engine/Modules.am
modules/meta_engine/dummy.c [deleted file]
modules/meta_engine/folder.c
modules/meta_engine/musicbrainz.c
src/input/meta.c
src/input/subtitles.c

index bf67e6e9f11fa5dd85fc5653cc73c0429d608d85..64fc5b9a5c04b3f6eb2c8911d1718c12d9cee25f 100644 (file)
@@ -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
index 7f97fcbebec88bad1e0b7a2afdc92258c0d01d99..fd50877d923cf30357e4e3375afb11914889258e 100644 (file)
@@ -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
index a228d85d1c44f4ae83f5fb2d241e5319893d109b..42306c59dfd4049a44863e08e5389e09a66bba55 100644 (file)
@@ -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; \
index 09011735f7fe2a7f99b39ec4a126051599070062..a7fabc8eb3741c8db3de2d5071d6955cfca4bbe3 100644 (file)
@@ -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 (file)
index a2ee329..0000000
+++ /dev/null
@@ -1,121 +0,0 @@
-/*****************************************************************************
- * 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;
-     }
-}
index ea7aee30881b39c9d5aedc9d034ab1b1c90520bd..00f3288959c4e14a8cd7ba870cd566705a7cb8ae 100644 (file)
@@ -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;
 }
index 74fac783455b3e8df4fe6159ac9f63c95220b859..58230ef7e580cb1bd597dae56da6c68db92964cf 100644 (file)
@@ -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;
 }
index 33cca2e7b4b44cfeb35b8a9840ee8eca2e05c16d..564f212b8e86af6dc99cd313bdcfadb15137ed8f 100644 (file)
 #   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;
+}
index 3efc30729b4fdc4fd15db4d0da64de9df461b5d5..9ce393d3ff1d933c8a288b333bf0aacf60735de8 100644 (file)
 
 #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 );
     }