1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2006 the VideoLAN team
7 * Authors: Antoine Cellerier <dionoea -at- videolan -dot- org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <stdlib.h> /* malloc(), free() */
33 #include "musicbrainz/mb_c.h"
35 /*****************************************************************************
37 *****************************************************************************/
38 static int FindMeta( vlc_object_t * );
40 /*****************************************************************************
42 *****************************************************************************/
45 /* set_category( CAT_INTERFACE );
46 set_subcategory( SUBCAT_INTERFACE_CONTROL );*/
47 set_shortname( N_( "MusicBrainz" ) );
48 set_description( _("MusicBrainz meta data") );
50 set_capability( "meta fetcher", 80 );
51 set_callbacks( FindMeta, NULL );
54 /*****************************************************************************
55 *****************************************************************************/
56 static int FindMeta( vlc_object_t *p_this )
58 meta_engine_t *p_me = (meta_engine_t *)p_this;
59 input_item_t *p_item = p_me->p_item;
61 char *psz_title = NULL;
62 char *psz_artist = NULL;
63 char *psz_album = NULL;
67 char i_album_count, i;
71 if( !p_item->p_meta ) return VLC_EGENERIC;
72 psz_artist = p_item->p_meta->psz_artist;
73 psz_album = p_item->p_meta->psz_album;
74 psz_title = p_item->psz_name;
76 if( !psz_artist || !psz_album )
84 mb_SetDepth( p_mb, 2 );
85 ppsz_args[0] = psz_album;
86 ppsz_args[1] = psz_artist;
88 if( !mb_QueryWithArgs( p_mb,
90 " <mq:depth>@DEPTH@</mq:depth>\n" \
91 " <mq:maxItems>@MAX_ITEMS@</mq:maxItems>\n" \
92 " <mq:albumName>@1@</mq:albumName>\n" \
93 " <mq:artistName>@2@</mq:artistName>\n" \
94 "</mq:FindAlbum>\n", ppsz_args ) )
96 mb_GetQueryError( p_mb, psz_buf, 256 );
97 msg_Err( p_me, "Query failed: %s\n", psz_buf );
102 i_album_count = mb_GetResultInt( p_mb, MBE_GetNumAlbums );
103 if( i_album_count < 1 )
105 msg_Err( p_me, "No albums found.\n" );
110 msg_Dbg( p_me, "Found %d albums.\n", i_album_count );
112 for( i = 1; i <= i_album_count; i++ )
114 mb_Select( p_mb, MBS_Rewind );
115 mb_Select1( p_mb, MBS_SelectAlbum, i );
117 mb_GetResultData( p_mb, MBE_AlbumGetAlbumId, psz_data, 256 );
118 mb_GetIDFromURL( p_mb, psz_data, psz_buf, 256 );
119 msg_Dbg( p_me, "Album Id: %s", psz_buf );
121 if( mb_GetResultData( p_mb, MBE_AlbumGetAmazonAsin, psz_buf, 256 ) )
123 msg_Dbg( p_me, "Amazon ASIN: %s", psz_buf );
124 sprintf( psz_data, "http://images.amazon.com/images/P/%s.01._SCLZZZZZZZ_.jpg", psz_buf );
125 vlc_meta_SetArtURL( p_item->p_meta, psz_data );
135 i_meta = input_CurrentMetaFlags( p_item->p_meta );
136 p_me->i_mandatory &= ~i_meta;
137 p_me->i_optional &= ~i_meta;
138 if( p_me->i_mandatory )