[vlc-devel] [PATCH 1/3] musicbrainz.lua: Use get_releaseid even if the album title is known

Wieland Hoffmann themineo at gmail.com
Sun Jan 12 23:04:07 CET 2014


This renames `try_release` to `get_releaseid` and uses it to find the
MusicBrainz Identifier. That MBID is later used in the query passed to
try_query.

Not using the ASIN returned from the search server in the get_releaseid
call means one additional request is performed in the case that both the
artist and the album name are already known.
---
 share/lua/meta/art/00_musicbrainz.lua | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/share/lua/meta/art/00_musicbrainz.lua b/share/lua/meta/art/00_musicbrainz.lua
index 2e224f4..1e11cbd 100644
--- a/share/lua/meta/art/00_musicbrainz.lua
+++ b/share/lua/meta/art/00_musicbrainz.lua
@@ -33,15 +33,15 @@ function try_query(query)
     return nil
 end
 
--- Return the mbid for first release
-function try_release(query)
+-- Return the mbid for the first release returned by the MusicBrainz search server for query
+function get_releaseid(query)
     local s = vlc.stream( query )
     if not s then return nil end
     local page = s:read( 65653 )
 
     -- FIXME: multiple results may be available and the first one is not
     -- guaranteed to have asin, so if it doesnt, we wouldnt get any art
-    _, _, releaseid = string.find( page, "<release id=\"([%x%-]-)\">" )
+    _, _, releaseid = string.find( page, "<release id=\"([%x%-]-)\"" )
     if releaseid then
         return releaseid
     end
@@ -56,19 +56,22 @@ function fetch_art()
     or meta["Listing Type"] == "tv"
     then return nil end
 
+    local releaseid = nil
+
     if meta["artist"] and meta["album"] then
         query = "artist:\"" .. meta["artist"] .. "\" AND release:\"" .. meta["album"] .. "\""
         relquery = "http://mb.videolan.org/ws/2/release/?query=" .. vlc.strings.encode_uri_component( query )
-        return try_query( relquery )
-    elseif meta["artist"] and meta["title"] then
+        releaseid = get_releaseid( relquery )
+    end
+    if not releaseid and meta["artist"] and meta["title"] then
         query = "artist:\"" .. meta["artist"] .. "\" AND recording:\"" .. meta["title"] .. "\""
         recquery = "http://mb.videolan.org/ws/2/recording/?query=" .. vlc.strings.encode_uri_component( query )
-        releaseid = try_release( recquery )
-        if releaseid then
-            relquery = "http://mb.videolan.org/ws/2/release/" .. releaseid
-            return try_query( relquery )
-        else
-            return nil
-        end
+        releaseid = get_releaseid( recquery )
+    end
+    if releaseid then
+        relquery = "http://mb.videolan.org/ws/2/release/" .. releaseid
+        return try_query( relquery )
+    else
+        return nil
     end
 end
-- 
1.8.5.2




More information about the vlc-devel mailing list