]> git.sesse.net Git - vlc/commitdiff
musicbrainz.lua: Use get_releaseid even if the album title is known
authorWieland Hoffmann <themineo@gmail.com>
Sun, 12 Jan 2014 22:04:07 +0000 (23:04 +0100)
committerJean-Baptiste Kempf <jb@videolan.org>
Mon, 13 Jan 2014 22:17:59 +0000 (23:17 +0100)
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.

Signed-off-by: Jean-Baptiste Kempf <jb@videolan.org>
share/lua/meta/art/00_musicbrainz.lua

index 2e224f43a145fc4c37ae99ce90f69be5a07d791b..1e11cbd760c9688436cc139c8b2da1dc5b2f64ec 100644 (file)
@@ -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