Commit bd3484b9 authored by Clément Stenac's avatar Clément Stenac

* Split download function in find/download

* Put meta related functions in src/input/meta.c
* Merge vlc_meta_engine.h and vlc_meta.h

Album art stuff is still broken, but I need to go now :)
parent a311268c
......@@ -467,14 +467,16 @@ VLC_EXPORT( input_thread_t *, __input_CreateThread, ( vlc_object_t *, input_item
VLC_EXPORT( input_thread_t *, __input_CreateThread2, ( vlc_object_t *, input_item_t *, char * ) );
#define input_Preparse(a,b) __input_Preparse(VLC_OBJECT(a),b)
VLC_EXPORT( int, __input_Preparse, ( vlc_object_t *, input_item_t * ) );
#define input_SecondaryPreparse(a,b) __input_SecondaryPreparse(VLC_OBJECT(a),b)
VLC_EXPORT( int, __input_SecondaryPreparse, ( vlc_object_t *, input_item_t * ) );
#define input_Read(a,b,c) __input_Read(VLC_OBJECT(a),b, c)
VLC_EXPORT( int, __input_Read, ( vlc_object_t *, input_item_t *, vlc_bool_t ) );
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 * ) );
enum input_query_e
{
/* input variable "position" */
......
......@@ -191,4 +191,38 @@ struct meta_export_t
const char *psz_file;
};
#define VLC_META_ENGINE_TITLE 0x00000001
#define VLC_META_ENGINE_AUTHOR 0x00000002
#define VLC_META_ENGINE_ARTIST 0x00000004
#define VLC_META_ENGINE_GENRE 0x00000008
#define VLC_META_ENGINE_COPYRIGHT 0x00000010
#define VLC_META_ENGINE_COLLECTION 0x00000020
#define VLC_META_ENGINE_SEQ_NUM 0x00000040
#define VLC_META_ENGINE_DESCRIPTION 0x00000080
#define VLC_META_ENGINE_RATING 0x00000100
#define VLC_META_ENGINE_DATE 0x00000200
#define VLC_META_ENGINE_URL 0x00000400
#define VLC_META_ENGINE_LANGUAGE 0x00000800
#define VLC_META_ENGINE_ART_URL 0x00001000
#define VLC_META_ENGINE_MB_ARTIST_ID 0x00002000
#define VLC_META_ENGINE_MB_RELEASE_ID 0x00004000
#define VLC_META_ENGINE_MB_TRACK_ID 0x00008000
#define VLC_META_ENGINE_MB_TRM_ID 0x00010000
typedef struct meta_engine_sys_t meta_engine_sys_t;
struct meta_engine_t
{
VLC_COMMON_MEMBERS
module_t *p_module;
uint32_t i_mandatory; /**< Stuff which we really need to get */
uint32_t i_optional; /**< Stuff which we'd like to have */
input_item_t *p_item;
};
#endif
/*****************************************************************************
* vlc_meta_engine.h: meta engine module.
*****************************************************************************
* Copyright (C) 2006 the VideoLAN team
* $Id$
*
* Authors: Antoine Cellerier <dionoea A videolan D 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.
*****************************************************************************/
#ifndef _VLC_META_ENGINE_H
#define _VLC_META_ENGINE_H
#include "vlc_meta.h"
#define VLC_META_ENGINE_TITLE 0x00000001
#define VLC_META_ENGINE_AUTHOR 0x00000002
#define VLC_META_ENGINE_ARTIST 0x00000004
#define VLC_META_ENGINE_GENRE 0x00000008
#define VLC_META_ENGINE_COPYRIGHT 0x00000010
#define VLC_META_ENGINE_COLLECTION 0x00000020
#define VLC_META_ENGINE_SEQ_NUM 0x00000040
#define VLC_META_ENGINE_DESCRIPTION 0x00000080
#define VLC_META_ENGINE_RATING 0x00000100
#define VLC_META_ENGINE_DATE 0x00000200
#define VLC_META_ENGINE_URL 0x00000400
#define VLC_META_ENGINE_LANGUAGE 0x00000800
#define VLC_META_ENGINE_ART_URL 0x00001000
#define VLC_META_ENGINE_MB_ARTIST_ID 0x00002000
#define VLC_META_ENGINE_MB_RELEASE_ID 0x00004000
#define VLC_META_ENGINE_MB_TRACK_ID 0x00008000
#define VLC_META_ENGINE_MB_TRM_ID 0x00010000
typedef struct meta_engine_sys_t meta_engine_sys_t;
struct meta_engine_t
{
VLC_COMMON_MEMBERS
module_t *p_module;
uint32_t i_mandatory; /**< Stuff which we really need to get */
uint32_t i_optional; /**< Stuff which we'd like to have */
input_item_t *p_item;
};
#endif
......@@ -538,11 +538,12 @@ struct module_symbols_t
void (*aout_EnableFilter_inner) (vlc_object_t *, const char *, vlc_bool_t);
void (*playlist_NodesPairCreate_inner) (playlist_t *, char *, playlist_item_t **, playlist_item_t **, vlc_bool_t);
char * (*aout_VisualChange_inner) (vlc_object_t *, int);
int (*__input_SecondaryPreparse_inner) (vlc_object_t *, input_item_t *);
void *__input_SecondaryPreparse_deprecated;
void (*input_ItemAddOption_inner) (input_item_t *, const char *);
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 *);
};
# if defined (__PLUGIN__)
# define aout_FiltersCreatePipeline (p_symbols)->aout_FiltersCreatePipeline_inner
......@@ -1012,11 +1013,11 @@ struct module_symbols_t
# define aout_EnableFilter (p_symbols)->aout_EnableFilter_inner
# define playlist_NodesPairCreate (p_symbols)->playlist_NodesPairCreate_inner
# define aout_VisualChange (p_symbols)->aout_VisualChange_inner
# define __input_SecondaryPreparse (p_symbols)->__input_SecondaryPreparse_inner
# define input_ItemAddOption (p_symbols)->input_ItemAddOption_inner
# 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
# elif defined (HAVE_DYNAMIC_PLUGINS) && !defined (__BUILTIN__)
/******************************************************************
* STORE_SYMBOLS: store VLC APIs into p_symbols for plugin access.
......@@ -1489,11 +1490,11 @@ struct module_symbols_t
((p_symbols)->aout_EnableFilter_inner) = aout_EnableFilter; \
((p_symbols)->playlist_NodesPairCreate_inner) = playlist_NodesPairCreate; \
((p_symbols)->aout_VisualChange_inner) = aout_VisualChange; \
((p_symbols)->__input_SecondaryPreparse_inner) = __input_SecondaryPreparse; \
((p_symbols)->input_ItemAddOption_inner) = input_ItemAddOption; \
((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)->net_ConvertIPv4_deprecated = NULL; \
(p_symbols)->vlc_input_item_GetInfo_deprecated = NULL; \
(p_symbols)->vlc_input_item_AddInfo_deprecated = NULL; \
......@@ -1546,6 +1547,7 @@ struct module_symbols_t
(p_symbols)->__intf_IntfProgressUpdate_deprecated = NULL; \
(p_symbols)->__intf_IntfProgress_deprecated = NULL; \
(p_symbols)->streaming_ChainToPsz_deprecated = NULL; \
(p_symbols)->__input_SecondaryPreparse_deprecated = NULL; \
# endif /* __PLUGIN__ */
#endif /* __VLC_SYMBOLS_H */
......@@ -275,6 +275,7 @@ SOURCES_libvlc_common = \
input/demux.c \
input/es_out.c \
input/input.c \
input/meta.c \
input/input_internal.h \
input/stream.c \
input/mem_stream.c \
......
......@@ -39,7 +39,6 @@
#include "vlc_playlist.h"
#include "vlc_interface.h"
#include "vlc_interaction.h"
#include "vlc_meta_engine.h"
#include "charset.h"
......@@ -349,47 +348,6 @@ int __input_Preparse( vlc_object_t *p_parent, input_item_t *p_item )
return VLC_SUCCESS;
}
int __input_SecondaryPreparse( vlc_object_t *p_parent, input_item_t *p_item )
{
struct meta_engine_t *p_me;
/* 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 */
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 )
{
p_me->i_mandatory |= VLC_META_ENGINE_ART_URL;
}
else
{
p_me->i_optional |= VLC_META_ENGINE_ART_URL;
}
*/
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" );
vlc_object_detach( p_me );
vlc_object_destroy( p_me );
return VLC_EGENERIC;
}
module_Unneed( p_me, p_me->p_module );
vlc_object_destroy( p_me );
return VLC_SUCCESS;
}
/**
* Request a running input thread to stop and die
*
......@@ -2529,96 +2487,3 @@ vlc_bool_t input_AddSubtitles( input_thread_t *p_input, char *psz_subtitle,
return VLC_TRUE;
}
#ifndef MAX_PATH
# define MAX_PATH 250
#endif
int input_DownloadAndCacheArt( vlc_object_t *p_parent, input_item_t *p_item )
{
char *psz_artist;
char *psz_album;
char *psz_type;
char *psz_filename;
int i_status = VLC_EGENERIC;
int i_ret;
struct stat a;
if( !p_item->p_meta
|| !p_item->p_meta->psz_arturl
|| !*p_item->p_meta->psz_arturl )
{
return VLC_EGENERIC;
}
if( !strncmp( p_item->p_meta->psz_arturl, "file", 4 ) )
{
return VLC_SUCCESS;
}
psz_artist = p_item->p_meta->psz_artist;
psz_album = p_item->p_meta->psz_album;
psz_type = strrchr( p_item->p_meta->psz_arturl, '.' );
psz_filename = (char *)malloc( MAX_PATH );
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 );
msg_Dbg( p_parent, "Saving album art to %s", psz_filename );
/* 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", psz_filename );
}
else
{
//if( i_ret == -1 && errno == ENOTDIR )
{
/* GRUIKKKKKKKKKK (make sure that all the directories exist) */
char *psz_dir = malloc( MAX_PATH );
snprintf( psz_dir, MAX_PATH, "%s" DIR_SEP CONFIG_DIR,
p_parent->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 );
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 );
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,
psz_artist, psz_album );
utf8_mkdir( psz_dir );
free( psz_dir );
}
stream_t *p_stream = stream_UrlNew( p_parent,
p_item->p_meta->psz_arturl );
if( p_stream )
{
void *p_buffer = malloc( 1<<16 );
long int l_read;
FILE *p_file = utf8_fopen( psz_filename+7, "w" );
while( ( l_read = stream_Read( p_stream, p_buffer, 1<<16 ) ) )
{
fwrite( p_buffer, l_read, 1, p_file );
}
free( p_buffer );
fclose( p_file );
stream_Delete( p_stream );
msg_Dbg( p_parent, "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;
}
}
free( psz_filename );
return i_status;
}
/*****************************************************************************
* meta.c : Metadata handling
*****************************************************************************
* Copyright (C) 1998-2004 the VideoLAN team
* $Id$
*
* Authors: Antoine Cellerier <dionoea@videolan.org>
* Clément Stenac <zorglub@videolan.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.
*****************************************************************************/
#include <vlc/vlc.h>
#include <vlc/input.h>
#include <vlc_meta.h>
#include "vlc_playlist.h"
#include "charset.h"
#ifdef HAVE_SYS_STAT_H
# include <sys/stat.h>
#endif
int __input_MetaFetch( vlc_object_t *p_parent, input_item_t *p_item )
{
struct meta_engine_t *p_me;
/* 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 */
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 )
{
p_me->i_mandatory |= VLC_META_ENGINE_ART_URL;
}
else
{
p_me->i_optional |= VLC_META_ENGINE_ART_URL;
}
*/
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" );
vlc_object_detach( p_me );
vlc_object_destroy( p_me );
return VLC_EGENERIC;
}
module_Unneed( p_me, p_me->p_module );
vlc_object_destroy( p_me );
return VLC_SUCCESS;
}
#ifndef MAX_PATH
# define MAX_PATH 250
#endif
int input_FindArt( vlc_object_t *p_parent, input_item_t *p_item )
{
char *psz_artist;
char *psz_album;
char *psz_type;
char psz_filename[MAX_PATH];
int i_ret;
struct stat a;
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
{
/* Use a art finder module to find the URL */
return VLC_EGENERIC;
}
}
/**
* 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 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;
char *psz_album;
char *psz_type;
psz_artist = p_item->p_meta->psz_artist;
psz_album = p_item->p_meta->psz_album;
/* You dummy ! How am I supposed to download NULL ? */
if( !p_item->p_meta || !p_item->p_meta->psz_arturl
|| !*p_item->p_meta->psz_arturl )
return VLC_EGENERIC;
/* Todo: get a helper to do this */
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 );
snprintf( psz_dir, MAX_PATH, "%s" DIR_SEP CONFIG_DIR,
p_parent->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 );
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 );
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,
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 );
if( p_stream )
{
void *p_buffer = malloc( 1<<16 );
long int l_read;
FILE *p_file = utf8_fopen( psz_filename+7, "w" );
while( ( l_read = stream_Read( p_stream, p_buffer, 1<<16 ) ) )
{
fwrite( p_buffer, l_read, 1, p_file );
}
free( p_buffer );
fclose( p_file );
stream_Delete( p_stream );
msg_Dbg( p_parent, "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;
}
return i_status;
}
......@@ -56,7 +56,7 @@
#include "vlc_tls.h"
#include "vlc_xml.h"
#include "vlc_osd.h"
#include "vlc_meta_engine.h"
#include "vlc_meta.h"
/*****************************************************************************
* Local prototypes
......
......@@ -532,7 +532,7 @@ void playlist_SecondaryPreparseLoop( playlist_preparse_t *p_obj )
vlc_mutex_unlock( &p_obj->object_lock );
if( p_current )
{
input_SecondaryPreparse( p_playlist, p_current );
input_MetaFetch( p_playlist, p_current );
p_current->p_meta->i_status |= ITEM_META_FETCHED;
var_SetInteger( p_playlist, "item-change", p_current->i_id );
vlc_gc_decref( p_current );
......
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