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)
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
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