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 *****************************************************************************/
29 #include <vlc_interface.h>
30 #include <vlc_input.h>
31 #include <vlc_playlist.h>
34 #include "musicbrainz/mb_c.h"
36 /*****************************************************************************
38 *****************************************************************************/
39 static int FindArt( vlc_object_t * );
40 static int FindMetaMBId( vlc_object_t *p_this );
42 /*****************************************************************************
44 *****************************************************************************/
47 set_shortname( N_( "MusicBrainz" ) );
48 set_description( _("MusicBrainz meta data") );
50 set_capability( "meta fetcher", 10 );
51 /* This meta fetcher module only retrieves the musicbrainz track id
55 * - Also store the album id
57 set_callbacks( FindMetaMBId, NULL );
59 /* This art finder module fetches the album ID from musicbrainz and
60 * uses it to fetch the amazon ASIN from musicbrainz.
62 * - Add ability to reuse MB album ID if we already have it
64 set_capability( "art finder", 80 );
65 set_callbacks( FindArt, NULL );
68 /*****************************************************************************
69 *****************************************************************************/
71 static int GetData( vlc_object_t *p_obj, input_item_t *p_item,
76 char i_album_count, i;
78 vlc_bool_t b_art_found = VLC_FALSE;
83 psz_artist = input_item_GetArtist( p_item );
84 psz_album = input_item_GetAlbum( p_item );
86 if( !psz_artist || !psz_album )
100 mb_SetDepth( p_mb, 2 );
101 ppsz_args[0] = psz_album;
102 ppsz_args[1] = psz_artist;
104 if( !mb_QueryWithArgs( p_mb,
106 " <mq:depth>@DEPTH@</mq:depth>\n" \
107 " <mq:maxItems>@MAX_ITEMS@</mq:maxItems>\n" \
108 " <mq:albumName>@1@</mq:albumName>\n" \
109 " <mq:artistName>@2@</mq:artistName>\n" \
110 "</mq:FindAlbum>\n", ppsz_args ) )
112 mb_GetQueryError( p_mb, psz_buf, 256 );
113 msg_Err( p_obj, "Query failed: %s", psz_buf );
122 i_album_count = mb_GetResultInt( p_mb, MBE_GetNumAlbums );
123 if( i_album_count < 1 )
129 /** \todo Get the MB Track ID and store it */
130 msg_Dbg( p_obj, "found %d albums.\n", i_album_count );
132 for( i = 1; i <= i_album_count; i++ )
134 mb_Select( p_mb, MBS_Rewind );
135 mb_Select1( p_mb, MBS_SelectAlbum, i );
137 mb_GetResultData( p_mb, MBE_AlbumGetAlbumId, psz_data, 256 );
138 mb_GetIDFromURL( p_mb, psz_data, psz_buf, 256 );
139 msg_Dbg( p_obj, "album Id: %s", psz_buf );
145 if( mb_GetResultData( p_mb, MBE_AlbumGetAmazonAsin, psz_buf, 256 ) )
147 msg_Dbg( p_obj, "Amazon ASIN: %s", psz_buf );
148 snprintf( psz_data, 255,
149 "http://images.amazon.com/images/P/%s.01._SCLZZZZZZZ_.jpg",
151 msg_Dbg( p_obj, "Album art URL: %s", psz_data );
152 input_item_SetArtURL( p_item, psz_data );
153 b_art_found = VLC_TRUE;
165 return b_art_found ? VLC_SUCCESS : VLC_EGENERIC;
168 static int FindMetaMBId( vlc_object_t *p_this )
170 meta_engine_t *p_me = (meta_engine_t *)p_this;
171 input_item_t *p_item = p_me->p_item;
172 int i_ret = GetData( VLC_OBJECT(p_me), p_item,
173 p_me->i_mandatory & VLC_META_ENGINE_ART_URL );
177 uint32_t i_meta = input_CurrentMetaFlags( input_item_GetMetaObject( p_item ) );
178 p_me->i_mandatory &= ~i_meta;
179 p_me->i_optional &= ~i_meta;
180 return p_me->i_mandatory ? VLC_EGENERIC : VLC_SUCCESS;
185 static int FindArt( vlc_object_t *p_this )
187 playlist_t *p_playlist = (playlist_t *)p_this;
188 input_item_t *p_item = (input_item_t *)(p_playlist->p_private);
191 return GetData( VLC_OBJECT(p_playlist), p_item, VLC_TRUE );