Commit f18236ee authored by Wieland Hoffmann's avatar Wieland Hoffmann Committed by Jean-Baptiste Kempf

musicbrainz.lua: Use get_releaseid even if the album title is known

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: default avatarJean-Baptiste Kempf <jb@videolan.org>
parent c50c4367
...@@ -33,15 +33,15 @@ function try_query(query) ...@@ -33,15 +33,15 @@ function try_query(query)
return nil return nil
end end
-- Return the mbid for first release -- Return the mbid for the first release returned by the MusicBrainz search server for query
function try_release(query) function get_releaseid(query)
local s = vlc.stream( query ) local s = vlc.stream( query )
if not s then return nil end if not s then return nil end
local page = s:read( 65653 ) local page = s:read( 65653 )
-- FIXME: multiple results may be available and the first one is not -- 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 -- 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 if releaseid then
return releaseid return releaseid
end end
...@@ -56,19 +56,22 @@ function fetch_art() ...@@ -56,19 +56,22 @@ function fetch_art()
or meta["Listing Type"] == "tv" or meta["Listing Type"] == "tv"
then return nil end then return nil end
local releaseid = nil
if meta["artist"] and meta["album"] then if meta["artist"] and meta["album"] then
query = "artist:\"" .. meta["artist"] .. "\" AND release:\"" .. meta["album"] .. "\"" query = "artist:\"" .. meta["artist"] .. "\" AND release:\"" .. meta["album"] .. "\""
relquery = "http://mb.videolan.org/ws/2/release/?query=" .. vlc.strings.encode_uri_component( query ) relquery = "http://mb.videolan.org/ws/2/release/?query=" .. vlc.strings.encode_uri_component( query )
return try_query( relquery ) releaseid = get_releaseid( relquery )
elseif meta["artist"] and meta["title"] then end
if not releaseid and meta["artist"] and meta["title"] then
query = "artist:\"" .. meta["artist"] .. "\" AND recording:\"" .. meta["title"] .. "\"" query = "artist:\"" .. meta["artist"] .. "\" AND recording:\"" .. meta["title"] .. "\""
recquery = "http://mb.videolan.org/ws/2/recording/?query=" .. vlc.strings.encode_uri_component( query ) recquery = "http://mb.videolan.org/ws/2/recording/?query=" .. vlc.strings.encode_uri_component( query )
releaseid = try_release( recquery ) releaseid = get_releaseid( recquery )
if releaseid then end
relquery = "http://mb.videolan.org/ws/2/release/" .. releaseid if releaseid then
return try_query( relquery ) relquery = "http://mb.videolan.org/ws/2/release/" .. releaseid
else return try_query( relquery )
return nil else
end return nil
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment