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"
36 /*****************************************************************************
37 * intf_sys_t: description and status of log interface
38 *****************************************************************************/
43 /*****************************************************************************
45 *****************************************************************************/
46 static int Open ( vlc_object_t * );
47 static void Close ( vlc_object_t * );
49 static int ItemChange( vlc_object_t *, const char *,
50 vlc_value_t, vlc_value_t, void * );
52 /*****************************************************************************
54 *****************************************************************************/
57 set_category( CAT_INTERFACE );
58 set_subcategory( SUBCAT_INTERFACE_CONTROL );
59 set_shortname( N_( "MusicBrainz" ) );
60 set_description( _("MusicBrainz meta data") );
62 set_capability( "interface", 0 );
63 set_callbacks( Open, Close );
66 /*****************************************************************************
67 * Open: initialize and create stuff
68 *****************************************************************************/
69 static int Open( vlc_object_t *p_this )
71 intf_thread_t *p_intf = (intf_thread_t *)p_this;
72 playlist_t *p_playlist;
74 MALLOC_ERR( p_intf->p_sys, intf_sys_t );
76 p_playlist = pl_Yield( p_intf );
77 var_AddCallback( p_playlist, "item-change", ItemChange, p_intf );
78 var_AddCallback( p_playlist, "playlist-current", ItemChange, p_intf );
84 /*****************************************************************************
85 * Close: destroy interface stuff
86 *****************************************************************************/
87 static void Close( vlc_object_t *p_this )
89 intf_thread_t *p_intf = (intf_thread_t *)p_this;
90 playlist_t *p_playlist = pl_Yield( p_this );
92 var_DelCallback( p_playlist, "item-change", ItemChange, p_intf );
93 var_DelCallback( p_playlist, "playlist-current", ItemChange, p_intf );
96 /* Destroy structure */
97 free( p_intf->p_sys );
100 /*****************************************************************************
101 * ItemChange: Playlist item change callback
102 *****************************************************************************/
103 static int ItemChange( vlc_object_t *p_this, const char *psz_var,
104 vlc_value_t oldval, vlc_value_t newval, void *param )
106 intf_thread_t *p_intf = (intf_thread_t *)param;
107 char *psz_title = NULL;
108 char *psz_artist = NULL;
109 char *psz_album = NULL;
110 input_thread_t *p_input;
111 playlist_t *p_playlist = pl_Yield( p_this );
113 p_input = p_playlist->p_input;
114 pl_Release( p_this );
116 if( !p_input ) return VLC_SUCCESS;
117 vlc_object_yield( p_input );
119 if( p_input->b_dead || !p_input->input.p_item->psz_name )
121 /* Not playing anything ... */
122 vlc_object_release( p_input );
126 /* Playing something ... */
127 psz_artist = p_input->input.p_item->p_meta->psz_artist;
128 psz_album = p_input->input.p_item->p_meta->psz_album;
129 psz_title = p_input->input.p_item->psz_name;
131 if( psz_artist && psz_album /* && psz_title */ )
136 char i_album_count, i;
139 fprintf( stdout,"
\e[33;1m--> %s %s %s
\e[0m\n", psz_artist, psz_album, psz_title );
144 mb_SetDepth( p_mb, 2 );
145 ppsz_args[0] = psz_album;
146 ppsz_args[1] = psz_artist;
148 if( !mb_QueryWithArgs( p_mb,
150 " <mq:depth>@DEPTH@</mq:depth>\n" \
151 " <mq:maxItems>@MAX_ITEMS@</mq:maxItems>\n" \
152 " <mq:albumName>@1@</mq:albumName>\n" \
153 " <mq:artistName>@2@</mq:artistName>\n" \
154 "</mq:FindAlbum>\n", ppsz_args ) )
156 mb_GetQueryError( p_mb, psz_buf, 256 );
157 msg_Err( p_intf, "Query failed: %s\n", psz_buf );
159 vlc_object_release( p_input );
163 i_album_count = mb_GetResultInt( p_mb, MBE_GetNumAlbums );
164 if( i_album_count < 1 )
166 msg_Err( p_intf, "No albums found.\n" );
168 vlc_object_release( p_input );
172 msg_Dbg( p_intf, "Found %d albums.\n", i_album_count );
174 for( i = 1; i <= i_album_count; i++ )
176 mb_Select( p_mb, MBS_Rewind );
177 mb_Select1( p_mb, MBS_SelectAlbum, i );
179 mb_GetResultData( p_mb, MBE_AlbumGetAlbumId, psz_data, 256 );
180 mb_GetIDFromURL( p_mb, psz_data, psz_buf, 256 );
181 msg_Dbg( p_intf, "Album Id: %s", psz_buf );
183 if( mb_GetResultData( p_mb, MBE_AlbumGetAmazonAsin, psz_buf, 256 ) )
185 msg_Dbg( p_intf, "Amazon ASIN: %s", psz_buf );
186 msg_Dbg( p_intf, "Album art url: " "http://images.amazon.com/images/P/%s.01._AA240_SCLZZZZZZZ_.jpg", psz_buf );
198 vlc_object_release( p_input );