<commit_before>--[[
 Gets an artwork from amazon

 $Id$
 Copyright © 2007-2010 the VideoLAN team

 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
--]]

function try_query(query)
    local l = vlc.object.libvlc()
    local t = vlc.var.get( l, "musicbrainz-previousdate" )
    if t ~= nil then
        if t + 2000000. > vlc.misc.mdate() then
            vlc.msg.warn( "We must wait 2 second between requests unless we want to be blacklisted from the musicbrainz server." )
            vlc.misc.mwait( t + 2000000. )
        end
        vlc.var.set( l, "musicbrainz-previousdate", vlc.misc.mdate() )
    else
        vlc.var.create( l, "musicbrainz-previousdate", vlc.misc.mdate() )
    end
    l = nil
    vlc.msg.dbg( query )
    local s = vlc.stream( query )
    if not s then return nil end
    local page = s:read( 65653 )

    -- FIXME: multiple results may be available
    asin = string.find( page, "<asin>(%w+)</asin>" )
    if asin then
        vlc.msg.dbg( asin )
        return "http://images.amazon.com/images/P/"..asin..".01._SCLZZZZZZZ_.jpg"
    else
        return nil
    end
end

-- Return the artwork
function fetch_art()
    local meta = vlc.item:metas()
    if not (meta["artist"] and meta["album"]) then
        return nil
    end

    local query1 = "http://mb.videolan.org/ws/1/release/?type=xml&artist="..vlc.strings.encode_uri_component(meta["artist"]).."&title=\""..vlc.strings.encode_uri_component(meta["album"].."\"")
    return try_query(query1)
end<commit_msg>Musicbrainz art fetcher: use version 2 API.<commit_after>--[[
 Gets an artwork from amazon

 $Id$
 Copyright © 2007-2010 the VideoLAN team

 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
--]]

function try_query(query)
    local l = vlc.object.libvlc()
    local t = vlc.var.get( l, "musicbrainz-previousdate" )
    if t ~= nil then
        if t + 2000000. > vlc.misc.mdate() then
            vlc.msg.warn( "We must wait 2 second between requests unless we want to be blacklisted from the musicbrainz server." )
            vlc.misc.mwait( t + 2000000. )
        end
        vlc.var.set( l, "musicbrainz-previousdate", vlc.misc.mdate() )
    else
        vlc.var.create( l, "musicbrainz-previousdate", vlc.misc.mdate() )
    end
    l = nil
    vlc.msg.dbg( query )
    local s = vlc.stream( query )
    if not s then return nil end
    local page = s:read( 65653 )

    -- FIXME: multiple results may be available
    asin = string.find( page, "<asin>(%w+)</asin>" )
    if asin then
        vlc.msg.dbg( asin )
        return "http://images.amazon.com/images/P/"..asin..".01._SCLZZZZZZZ_.jpg"
    else
        return nil
    end
end

-- Return the artwork
function fetch_art()
    local meta = vlc.item:metas()
    if not (meta["artist"] and meta["album"]) then
        return nil
    end

    local query1 = "http://mb.videolan.org/ws/2/release/?query=artist:"..vlc.strings.encode_uri_component(meta["artist"]).."%20AND%20release:\""..vlc.strings.encode_uri_component(meta["album"].."\"")
    return try_query(query1)
end
{'fraction_non_alphanumeric': 0.10560595487322633, 'fraction_numerical': 0.02209816236334031, 'mean_word_length': 2.952205882352941, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 1}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1869398', 'n_tokens_mistral': 1408, 'n_tokens_neox': 1302, 'n_words': 487}