2 Gets an artwork from the Cover Art Archive or Amazon
5 Copyright © 2007-2010 the VideoLAN team
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 return { scope
="network" }
26 function try_query(mbid
)
27 local relquery
= "http://mb.videolan.org/ws/2/release/" .. mbid
28 local s
= vlc
.stream( relquery
)
29 if not s
then return nil end
30 local page
= s
:read( 65653 )
32 found
, _
= string.find( page
, "<artwork>true</artwork>" )
34 front
, _
= string.find( page
, "<front>true</front>" )
36 return "http://coverartarchive.org/release/"..mbid
.."/front-500"
40 -- FIXME: multiple results may be available
41 _
, _
, asin = string.find( page
, "<asin>(%w+)</asin>" )
43 return "http://images.amazon.com/images/P/"..asin..".01._SCLZZZZZZZ_.jpg"
45 vlc
.msg
.dbg("Neither coverartarchive.org nor amazon have cover art for this release")
49 -- Return the mbid for the first release returned by the MusicBrainz search server for query
50 function get_releaseid(query
)
51 local s
= vlc
.stream( query
)
52 if not s
then return nil end
53 local page
= s
:read( 65653 )
55 -- FIXME: multiple results may be available and the first one is not
56 -- guaranteed to have asin, so if it doesnt, we wouldnt get any art
57 _
, _
, releaseid
= string.find( page
, "<release id=\"([%x%-]-)\"" )
66 local meta
= vlc
.item
:metas()
68 if meta
["Listing Type"] == "radio"
69 or meta
["Listing Type"] == "tv"
74 if meta
["MB_ALBUMID"] then
75 releaseid
= meta
["MB_ALBUMID"]
78 if not releaseid
and meta
["artist"] and meta
["album"] then
79 query
= "artist:\"" .. meta
["artist"] .. "\" AND release:\"" .. meta
["album"] .. "\""
80 relquery
= "http://mb.videolan.org/ws/2/release/?query=" .. vlc
.strings
.encode_uri_component( query
)
81 releaseid
= get_releaseid( relquery
)
83 if not releaseid
and meta
["artist"] and meta
["title"] then
84 query
= "artist:\"" .. meta
["artist"] .. "\" AND recording:\"" .. meta
["title"] .. "\""
85 recquery
= "http://mb.videolan.org/ws/2/recording/?query=" .. vlc
.strings
.encode_uri_component( query
)
86 releaseid
= get_releaseid( recquery
)
89 return try_query( releaseid
)