[vlc-devel] commit: Reimplement MB module in Lua. (Antoine Cellerier )

git version control git at videolan.org
Wed Sep 10 02:46:08 CEST 2008


vlc | branch: 0.9-bugfix | Antoine Cellerier <dionoea at videolan.org> | Wed Sep 10 02:32:17 2008 +0200| [f025d7355522ff165774ddd2fe0a4c656d62f691] | committer: Antoine Cellerier 

Reimplement MB module in Lua.

Remove C musicbrainz modules, use the new XML musicbrainz API.
This removes VLC's dependency on libmusicbrainz. Consider backporting
this commit and the previous one to 0.9-bugfix to get musicbrainz
support on windows.
(cherry picked from commit 950caf17359c35cd4b4fd31638e5f3b7cca14a5c)

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=f025d7355522ff165774ddd2fe0a4c656d62f691
---

 configure.ac                                       |   14 --
 modules/meta_engine/Modules.am                     |    1 -
 modules/meta_engine/musicbrainz.c                  |  172 --------------------
 share/Makefile.am                                  |    3 +-
 share/lua/meta/01_musicbrainz.lua                  |   54 ++++++
 .../meta/{googleimage.lua => 10_googleimage.lua}   |    0 
 6 files changed, 56 insertions(+), 188 deletions(-)

diff --git a/configure.ac b/configure.ac
index 6bf7b6d..81de61b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1754,20 +1754,6 @@ AS_IF([test "${enable_audioscrobbler}" != "no"], [
   ])
 
 dnl
-dnl Musicbrainz plugin
-dnl
-AC_ARG_ENABLE(musicbrainz,
-  [  --enable-musicbrainz    MusicBrainz support (default disabled) ])
-  AS_IF([test "${enable_musicbrainz}" = "yes"],[
-      PKG_CHECK_MODULES(MUSICBRAINZ, libmusicbrainz,
-    [ VLC_ADD_PLUGIN([musicbrainz])
-      VLC_ADD_LIBS([musicbrainz],[$MUSICBRAINZ_LIBS])
-      VLC_ADD_CFLAGS([musicbrainz],[$MUSICBRAINZ_CFLAGS])  ],
-       [AC_MSG_WARN(MusicBrainz library not found)])
-   ])
-
-
-dnl
 dnl Taglibplugin
 dnl
 AC_ARG_ENABLE(taglib,
diff --git a/modules/meta_engine/Modules.am b/modules/meta_engine/Modules.am
index e8d8c89..c3d21e5 100644
--- a/modules/meta_engine/Modules.am
+++ b/modules/meta_engine/Modules.am
@@ -1,4 +1,3 @@
 SOURCES_folder = folder.c
 SOURCES_id3tag = id3tag.c id3genres.h $(NULL)
-SOURCES_musicbrainz = musicbrainz.c
 SOURCES_taglib = taglib.cpp
diff --git a/modules/meta_engine/musicbrainz.c b/modules/meta_engine/musicbrainz.c
deleted file mode 100644
index 33077a4..0000000
--- a/modules/meta_engine/musicbrainz.c
+++ /dev/null
@@ -1,172 +0,0 @@
-/*****************************************************************************
- * musicbrainz.c
- *****************************************************************************
- * Copyright (C) 2006 the VideoLAN team
- * $Id$
- *
- * Authors: Antoine Cellerier <dionoea -at- videolan -dot- org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
- *****************************************************************************/
-
-/*****************************************************************************
- * Preamble
- *****************************************************************************/
-
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include <vlc_common.h>
-#include <vlc_plugin.h>
-#include <vlc_interface.h>
-#include <vlc_input.h>
-#include <vlc_playlist.h>
-#include <vlc_meta.h>
-
-#include "musicbrainz/mb_c.h"
-
-#include <assert.h>
-
-/*****************************************************************************
- * Local prototypes
- *****************************************************************************/
-static int FindArt( vlc_object_t * );
-
-/*****************************************************************************
- * Module descriptor
- *****************************************************************************/
-
-vlc_module_begin();
-    set_shortname( N_( "MusicBrainz" ) );
-    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 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;
-
-    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;
-    ppsz_args[2] = NULL;
-    if( !mb_QueryWithArgs( p_mb,
-        "<mq:FindAlbum>\n" \
-        "   <mq:depth>@DEPTH@</mq:depth>\n" \
-        "   <mq:maxItems>@MAX_ITEMS@</mq:maxItems>\n" \
-        "   <mq:albumName>@1@</mq:albumName>\n" \
-        "   <mq:artistName>@2@</mq:artistName>\n" \
-        "</mq:FindAlbum>\n", ppsz_args ) )
-    {
-        mb_GetQueryError( p_mb, psz_buf, 256 );
-        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 )
-    {
-        mb_Delete( p_mb );
-        return VLC_EGENERIC;
-    }
-
-    /** \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++ )
-    {
-        mb_Select( p_mb, MBS_Rewind );
-        mb_Select1( p_mb, MBS_SelectAlbum, i );
-
-        mb_GetResultData( p_mb, MBE_AlbumGetAlbumId, psz_data, 256 );
-        mb_GetIDFromURL( p_mb, psz_data, psz_buf, 256 );
-        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_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 );
-
-    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 );
-}
diff --git a/share/Makefile.am b/share/Makefile.am
index 0cd4c0d..1a9296a 100644
--- a/share/Makefile.am
+++ b/share/Makefile.am
@@ -281,7 +281,8 @@ DIST_osdmenu_minimal = \
 DIST_lua= \
 	lua/README.txt \
 	lua/meta/README.txt \
-	lua/meta/googleimage.lua \
+	lua/meta/01_musicbrainz.lua \
+	lua/meta/10_googleimage.lua \
 	lua/playlist/README.txt \
 	lua/playlist/appletrailers.lua \
 	lua/playlist/break.lua \
diff --git a/share/lua/meta/01_musicbrainz.lua b/share/lua/meta/01_musicbrainz.lua
new file mode 100644
index 0000000..030f420
--- /dev/null
+++ b/share/lua/meta/01_musicbrainz.lua
@@ -0,0 +1,54 @@
+--[[
+ Gets an artwork from amazon
+
+ $Id$
+ Copyright © 2007 the VideoLAN team
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+--]]
+
+-- Return the artwork
+function fetch_art()
+    local query
+    if vlc.artist and vlc.album then
+        query = "http://musicbrainz.org/ws/1/release/?type=xml&artist="..vlc.strings.encode_uri_component(vlc.artist).."&title="..vlc.strings.encode_uri_component(vlc.album)
+    else
+        return nil
+    end
+
+    local l = vlc.object.libvlc()
+    local t = vlc.var.get( l, "musicbrainz-previousdate" )
+    if t ~= nil then
+        if t + 10000000. > vlc.misc.mdate() then
+            vlc.msg.warn( "We must wait 1 second between requests unless we want to be blacklisted from the musicbrainz server." )
+            vlc.misc.mwait( t + 1000000. )
+        end
+        vlc.var.set( l, "musicbrainz-previousdate", vlc.misc.mdate() )
+    else
+        vlc.var.create( l, "musicbrainz-previousdate", vlc.misc.mdate() )
+    end
+    l = nil
+    vlc.msg.dbg( query )
+    local s = vlc.stream( query )
+    local page = s:read( 65653 )
+
+    -- FIXME: multiple results may be available
+    asin = string.gsub( page, "^.*<asin>([^<]*)</asin>.*$", "%1" )
+    if asin ~= page then
+        return "http://images.amazon.com/images/P/"..asin..".01._SCLZZZZZZZ_.jpg"
+    else
+        return nil
+    end
+end
diff --git a/share/lua/meta/googleimage.lua b/share/lua/meta/10_googleimage.lua
similarity index 100%
rename from share/lua/meta/googleimage.lua
rename to share/lua/meta/10_googleimage.lua




More information about the vlc-devel mailing list