X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Finput%2Fmeta.c;h=3420e7cef8c4a73c3fdebeb8d95b611d734fcc1c;hb=e3f0531d93abd49f902a324241e31200de05b45d;hp=dbf97ba7e7a5ee877cea297a8e54d0784dcf5d44;hpb=8172a7de5eca345a5c6cee49e1952b2c6538ced1;p=vlc diff --git a/src/input/meta.c b/src/input/meta.c index dbf97ba7e7..3420e7cef8 100644 --- a/src/input/meta.c +++ b/src/input/meta.c @@ -22,7 +22,11 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include #include #include #include @@ -31,83 +35,44 @@ #include #include "../playlist/playlist_internal.h" #include +#include /* PATH_MAX */ +#include #ifdef HAVE_SYS_STAT_H # include #endif -static const char * meta_type_to_string[VLC_META_TYPE_COUNT] = -{ - [vlc_meta_Title] = N_("Title"), - [vlc_meta_Artist] = N_("Artist"), - [vlc_meta_Genre] = N_("Genre"), - [vlc_meta_Copyright] = N_("Copyright"), - [vlc_meta_Album] = N_("Album"), - [vlc_meta_TrackNumber] = N_("Track number"), - [vlc_meta_Description] = N_("Description"), - [vlc_meta_Rating] = N_("Rating"), - [vlc_meta_Date] = N_("Date"), - [vlc_meta_Setting] = N_("Setting"), - [vlc_meta_URL] = N_("URL"), - [vlc_meta_Language] = N_("Language"), - [vlc_meta_NowPlaying] = N_("Now Playing"), - [vlc_meta_Publisher] = N_("Publisher"), - [vlc_meta_EncodedBy] = N_("Encoded by"), - [vlc_meta_ArtworkURL] = N_("Artwork URL"), - [vlc_meta_TrackID] = N_("Track ID"), -}; +#include "../libvlc.h" const char * input_MetaTypeToLocalizedString( vlc_meta_type_t meta_type ) { - return _(meta_type_to_string[meta_type]); -} - -#define input_FindArtInCache(a,b) __input_FindArtInCache(VLC_OBJECT(a),b) -static int __input_FindArtInCache( vlc_object_t *, 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 ) -{ - (void)p_playlist; - *pi_mandatory = VLC_META_ENGINE_TITLE | VLC_META_ENGINE_ARTIST; - - 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, i_optional; - - input_MetaSatisfied( p_playlist, p_item, &i_mandatory, &i_optional ); - // Meta shouldn't magically appear - assert( i_mandatory ); - - /* FIXME: object creation is overkill, use p_private */ - p_me = vlc_object_create( p_playlist, VLC_OBJECT_META_ENGINE ); - p_me->i_flags |= OBJECT_FLAGS_NOINTERACT; - p_me->i_flags |= OBJECT_FLAGS_QUIET; - 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 ); - if( !p_me->p_module ) + switch( meta_type ) { - vlc_object_destroy( p_me ); - return VLC_EGENERIC; + case vlc_meta_Title: return _("Title"); + case vlc_meta_Artist: return _("Artist"); + case vlc_meta_Genre: return _("Genre"); + case vlc_meta_Copyright: return _("Copyright"); + case vlc_meta_Album: return _("Album"); + case vlc_meta_TrackNumber: return _("Track number"); + case vlc_meta_Description: return _("Description"); + case vlc_meta_Rating: return _("Rating"); + case vlc_meta_Date: return _("Date"); + case vlc_meta_Setting: return _("Setting"); + case vlc_meta_URL: return _("URL"); + case vlc_meta_Language: return _("Language"); + case vlc_meta_NowPlaying: return _("Now Playing"); + case vlc_meta_Publisher: return _("Publisher"); + case vlc_meta_EncodedBy: return _("Encoded by"); + case vlc_meta_ArtworkURL: return _("Artwork URL"); + case vlc_meta_TrackID: return _("Track ID"); + + default: abort(); } - module_Unneed( p_me, p_me->p_module ); - vlc_object_destroy( p_me ); - - input_item_SetMetaFetched( p_item, VLC_TRUE ); +}; - return VLC_SUCCESS; -} +#define input_FindArtInCache(a,b) __input_FindArtInCache(VLC_OBJECT(a),b) +static int __input_FindArtInCache( vlc_object_t *, input_item_t *p_item ); /* Return codes: * 0 : Art is in cache or is a local file @@ -134,7 +99,7 @@ int input_ArtFind( playlist_t *p_playlist, input_item_t *p_item ) /* If we already checked this album in this session, skip */ if( psz_artist && psz_album ) { - FOREACH_ARRAY( playlist_album_t album, p_playlist->p_fetcher->albums ) + FOREACH_ARRAY( playlist_album_t album, pl_priv(p_playlist)->p_fetcher->albums ) if( !strcmp( album.psz_artist, psz_artist ) && !strcmp( album.psz_album, psz_album ) ) { @@ -164,12 +129,20 @@ int input_ArtFind( playlist_t *p_playlist, input_item_t *p_item ) input_FindArtInCache( p_playlist, p_item ); char *psz_arturl = input_item_GetArtURL( p_item ); - if( !EMPTY_STR( psz_arturl ) ) + if( psz_arturl ) { + /* We already have an URL */ + if( !strncmp( psz_arturl, "file://", strlen( "file://" ) ) ) + { + free( psz_arturl ); + return 0; /* Art is in cache, no need to go further */ + } + free( psz_arturl ); - return 0; /* Art is in cache, no need to go further */ + + /* Art need to be put in cache */ + return 1; } - free( psz_arturl ); PL_LOCK; p_playlist->p_private = p_item; @@ -191,7 +164,7 @@ int input_ArtFind( playlist_t *p_playlist, input_item_t *p_item ) } free( psz_title ); - p_module = module_Need( p_playlist, "art finder", 0, VLC_FALSE ); + p_module = module_Need( p_playlist, "art finder", 0, false ); if( p_module ) i_ret = 1; @@ -205,8 +178,8 @@ int input_ArtFind( playlist_t *p_playlist, input_item_t *p_item ) a.psz_artist = psz_artist; a.psz_album = psz_album; a.psz_arturl = input_item_GetArtURL( p_item ); - a.b_found = (i_ret == VLC_EGENERIC ? VLC_FALSE : VLC_TRUE ); - ARRAY_APPEND( p_playlist->p_fetcher->albums, a ); + a.b_found = (i_ret == VLC_EGENERIC ? false : true ); + ARRAY_APPEND( pl_priv(p_playlist)->p_fetcher->albums, a ); } else { @@ -266,15 +239,16 @@ static void __ArtCacheGetDirPath( vlc_object_t *p_obj, const char *psz_title, const char *psz_artist, const char *psz_album ) { + (void)p_obj; + char *psz_cachedir = config_GetCacheDir(); + if( !EMPTY_STR(psz_artist) && !EMPTY_STR(psz_album) ) { char * psz_album_sanitized = ArtCacheGetSanitizedFileName( psz_album ); char * psz_artist_sanitized = ArtCacheGetSanitizedFileName( psz_artist ); - snprintf( psz_dir, PATH_MAX, "%s" DIR_SEP "art" DIR_SEP "artistalbum" DIR_SEP "%s" DIR_SEP "%s", - p_obj->p_libvlc->psz_cachedir, - psz_artist_sanitized, psz_album_sanitized ); + psz_cachedir, psz_artist_sanitized, psz_album_sanitized ); free( psz_album_sanitized ); free( psz_artist_sanitized ); } @@ -283,10 +257,10 @@ static void __ArtCacheGetDirPath( vlc_object_t *p_obj, char * psz_title_sanitized = ArtCacheGetSanitizedFileName( psz_title ); snprintf( psz_dir, PATH_MAX, "%s" DIR_SEP "art" DIR_SEP "title" DIR_SEP "%s", - p_obj->p_libvlc->psz_cachedir, - psz_title_sanitized ); + psz_cachedir, psz_title_sanitized ); free( psz_title_sanitized ); } + free( psz_cachedir ); } @@ -415,7 +389,7 @@ int input_DownloadAndCacheArt( playlist_t *p_playlist, input_item_t *p_item ) } psz_type = strrchr( psz_arturl, '.' ); - if( strlen( psz_type ) > 5 ) + if( psz_type && strlen( psz_type ) > 5 ) psz_type = NULL; /* remove extension if it's > to 4 characters */ /* Warning: psz_title, psz_artist, psz_album may change in ArtCache*() */ @@ -473,10 +447,10 @@ int input_DownloadAndCacheArt( playlist_t *p_playlist, input_item_t *p_item ) void input_ExtractAttachmentAndCacheArt( input_thread_t *p_input ) { input_item_t *p_item = p_input->p->input.p_item; - char *psz_arturl; - char *psz_artist = NULL; - char *psz_album = NULL; - char *psz_title = NULL; + const char *psz_arturl; + const char *psz_artist = NULL; + const char *psz_album = NULL; + const char *psz_title = NULL; char *psz_type = NULL; char psz_filename[PATH_MAX+1]; FILE *f; @@ -487,14 +461,13 @@ void input_ExtractAttachmentAndCacheArt( input_thread_t *p_input ) /* TODO-fenrir merge input_ArtFind with download and make it set the flags FETCH * and then set it here to to be faster */ - psz_arturl = input_item_GetArtURL( p_item ); + psz_arturl = vlc_meta_Get( p_item->p_meta, vlc_meta_ArtworkURL ); + if( !psz_arturl || strncmp( psz_arturl, "attachment://", strlen("attachment://") ) ) { - free( psz_arturl ); msg_Err( p_input, "internal input error with input_ExtractAttachmentAndCacheArt" ); return; } - input_item_SetArtURL( p_item, NULL ); if( input_item_IsArtFetched( p_item ) ) { @@ -502,7 +475,6 @@ void input_ExtractAttachmentAndCacheArt( input_thread_t *p_input ) * condition */ msg_Warn( p_input, "internal input error with input_ExtractAttachmentAndCacheArt" ); input_FindArtInCache( p_input, p_item ); - free( psz_arturl ); return; } @@ -519,28 +491,34 @@ void input_ExtractAttachmentAndCacheArt( input_thread_t *p_input ) if( !p_attachment || p_attachment->i_data <= 0 ) { msg_Warn( p_input, "internal input error with input_ExtractAttachmentAndCacheArt" ); - goto end; + return; } - psz_artist = input_item_GetArtist( p_item ); - psz_album = input_item_GetAlbum( p_item ); - psz_title = input_item_GetTitle( p_item ); + psz_artist = vlc_meta_Get( p_item->p_meta, vlc_meta_Artist ); + psz_album = vlc_meta_Get( p_item->p_meta, vlc_meta_Album ); + psz_title = vlc_meta_Get( p_item->p_meta, vlc_meta_Title ); + if( !strcmp( p_attachment->psz_mime, "image/jpeg" ) ) + psz_type = strdup( ".jpg" ); + else if( !strcmp( p_attachment->psz_mime, "image/png" ) ) + psz_type = strdup( ".png" ); + if( !psz_title ) - psz_title = input_item_GetName( p_item ); + psz_title = p_item->psz_name; if( (!psz_artist || !psz_album ) && !psz_title ) - goto end; - - /* */ - psz_type = strrchr( psz_arturl, '.' ); + return; ArtCacheGetDirPath( p_input, psz_filename, psz_title, psz_artist, psz_album ); ArtCacheCreateDir( psz_filename ); ArtCacheGetFilePath( p_input, psz_filename, psz_title, psz_artist, psz_album, psz_type ); + free( psz_type ); /* Check if we already dumped it */ if( !utf8_stat( psz_filename+7, &s ) ) - goto end; + { + vlc_meta_Set( p_item->p_meta, vlc_meta_ArtworkURL, psz_filename ); + return; + } f = utf8_fopen( psz_filename+7, "w" ); if( f ) @@ -548,45 +526,10 @@ void input_ExtractAttachmentAndCacheArt( input_thread_t *p_input ) if( fwrite( p_attachment->p_data, p_attachment->i_data, 1, f ) != 1 ) msg_Err( p_input, "%s: %m", psz_filename ); else + { msg_Dbg( p_input, "album art saved to %s\n", psz_filename ); + vlc_meta_Set( p_item->p_meta, vlc_meta_ArtworkURL, psz_filename ); + } fclose( f ); } - -end: - if( psz_artist ) free( psz_artist ); - if( psz_album ) free( psz_album ); - if( psz_title ) free( psz_title ); - if( psz_arturl ) free( psz_arturl ); -} - - -uint32_t input_CurrentMetaFlags( vlc_meta_t *p_meta ) -{ - uint32_t i_meta = 0; - - if( !p_meta ) - return 0; - -#define CHECK( a, b ) \ - if( !EMPTY_STR( vlc_meta_Get( p_meta, vlc_meta_ ## a ) ) ) \ - i_meta |= VLC_META_ENGINE_ ## b; - - CHECK( Title, TITLE ) - CHECK( Artist, ARTIST ) - CHECK( Album, COLLECTION ) -#if 0 - /* As this is not used at the moment, don't uselessly check for it. - * Re-enable this when it is used */ - CHECK( Genre, GENRE ) - CHECK( Copyright, COPYRIGHT ) - CHECK( Tracknum, SEQ_NUM ) - CHECK( Description, DESCRIPTION ) - CHECK( Rating, RATING ) - CHECK( Date, DATE ) - CHECK( URL, URL ) - CHECK( Language, LANGUAGE ) -#endif - CHECK( ArtworkURL, ART_URL ) - - return i_meta; }