X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fmeta_engine%2Fmusicbrainz.c;h=33077a4fd3a349f107b8ed5d8f92d1460bef28bd;hb=62dd14548820fb0966e6b90d586183f74a427e4b;hp=7c296489065a3f3b39c5fa0ebc439dcc027f1d72;hpb=408a016e922da04d9f5067f96fbaf17ffce36878;p=vlc diff --git a/modules/meta_engine/musicbrainz.c b/modules/meta_engine/musicbrainz.c index 7c29648906..33077a4fd3 100644 --- a/modules/meta_engine/musicbrainz.c +++ b/modules/meta_engine/musicbrainz.c @@ -24,63 +24,76 @@ /***************************************************************************** * Preamble *****************************************************************************/ -#include /* malloc(), free() */ -#include -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include +#include +#include +#include #include -#include #include "musicbrainz/mb_c.h" +#include + /***************************************************************************** * Local prototypes *****************************************************************************/ -static int FindMeta( vlc_object_t * ); +static int FindArt( vlc_object_t * ); /***************************************************************************** * Module descriptor *****************************************************************************/ vlc_module_begin(); -/* set_category( CAT_INTERFACE ); - set_subcategory( SUBCAT_INTERFACE_CONTROL );*/ set_shortname( N_( "MusicBrainz" ) ); - set_description( _("MusicBrainz meta data") ); - - set_capability( "meta fetcher", 80 ); - set_callbacks( FindMeta, NULL ); + set_description( N_("MusicBrainz meta data") ); + + /* This art finder module fetches the album ID from musicbrainz and + * uses it to fetch the amazon ASIN from musicbrainz. + * TODO: + * - Add ability to reuse MB album ID if we already have it + */ + set_capability( "art finder", 80 ); + set_callbacks( FindArt, 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; - - char *psz_title = NULL; - char *psz_artist = NULL; - char *psz_album = NULL; +static int GetData( vlc_object_t *p_obj, input_item_t *p_item, + bool b_art ) +{ char psz_buf[256]; char psz_data[256]; char i_album_count, i; char *ppsz_args[4]; + bool b_art_found = false; + + char *psz_artist; + char *psz_album; - if( !p_item->p_meta ) return VLC_EGENERIC; - psz_artist = p_item->p_meta->psz_artist; - psz_album = p_item->p_meta->psz_album; - psz_title = p_item->psz_name; + psz_artist = input_item_GetArtist( p_item ); + psz_album = input_item_GetAlbum( p_item ); if( !psz_artist || !psz_album ) + { + free( psz_artist ); + free( psz_album ); return VLC_EGENERIC; + } + musicbrainz_t p_mb; p_mb = mb_New(); #ifdef WIN32 mb_WSAInit( p_mb ); #endif + mb_SetDepth( p_mb, 2 ); ppsz_args[0] = psz_album; ppsz_args[1] = psz_artist; @@ -94,20 +107,24 @@ static int FindMeta( vlc_object_t *p_this ) "\n", ppsz_args ) ) { mb_GetQueryError( p_mb, psz_buf, 256 ); - msg_Err( p_me, "Query failed: %s\n", psz_buf ); + msg_Err( p_obj, "Query failed: %s", psz_buf ); mb_Delete( p_mb ); + free( psz_artist ); + free( psz_album ); return VLC_EGENERIC; } + free( psz_artist ); + free( psz_album ); i_album_count = mb_GetResultInt( p_mb, MBE_GetNumAlbums ); if( i_album_count < 1 ) { - msg_Err( p_me, "No albums found.\n" ); mb_Delete( p_mb ); return VLC_EGENERIC; } - msg_Dbg( p_me, "Found %d albums.\n", i_album_count ); + /** \todo Get the MB Track ID and store it */ + msg_Dbg( p_obj, "found %d albums.\n", i_album_count ); for( i = 1; i <= i_album_count; i++ ) { @@ -116,21 +133,40 @@ static int FindMeta( vlc_object_t *p_this ) mb_GetResultData( p_mb, MBE_AlbumGetAlbumId, psz_data, 256 ); mb_GetIDFromURL( p_mb, psz_data, psz_buf, 256 ); - msg_Dbg( p_me, "Album Id: %s", psz_buf ); + msg_Dbg( p_obj, "album Id: %s", psz_buf ); + + + if( !b_art ) + break; if( mb_GetResultData( p_mb, MBE_AlbumGetAmazonAsin, psz_buf, 256 ) ) { - msg_Dbg( p_me, "Amazon ASIN: %s", psz_buf ); - sprintf( psz_data, "http://images.amazon.com/images/P/%s.01._SCLZZZZZZZ_.jpg", psz_buf ); - vlc_meta_SetArtURL( p_item->p_meta, psz_data ); + msg_Dbg( p_obj, "Amazon ASIN: %s", psz_buf ); + snprintf( psz_data, 255, + "http://images.amazon.com/images/P/%s.01._SCLZZZZZZZ_.jpg", + psz_buf ); + msg_Dbg( p_obj, "Album art URL: %s", psz_data ); + input_item_SetArtURL( p_item, psz_data ); + b_art_found = true; break; } } #ifdef WIN32 mb_WSAInit( p_mb ); #endif - mb_Delete( p_mb ); - return VLC_SUCCESS; + if( !b_art ) + return VLC_SUCCESS; + else + return b_art_found ? VLC_SUCCESS : VLC_EGENERIC; +} + +static int FindArt( vlc_object_t *p_this ) +{ + playlist_t *p_playlist = (playlist_t *)p_this; + input_item_t *p_item = (input_item_t *)(p_playlist->p_private); + assert( p_item ); + + return GetData( VLC_OBJECT(p_playlist), p_item, true ); }