--[[ * Copyright (C) 2014 Grilo Project * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation; version 2.1 of * the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * --]] --------------------------- -- Source initialization -- --------------------------- source = { id = "grl-gamefaqs", name = "gamefaqs", description = "GameFAQs.com", supported_keys = { "description", "thumbnail", "rating" }, resolve_keys = { required = { "title" }, }, tags = { 'video-games' } } ------------------ -- Source utils -- ------------------ GUARDIANA_DEFAULT_QUERY = "http://www.gamefaqs.com/search/index.html?game=%s" --------------------------------- -- Handlers of Grilo functions -- --------------------------------- function grl_source_resolve() local url, req local title req = grl.get_media_keys() if not req or not req.title then grl.callback() return end title = string.gsub(req.title, " ", "+") url = string.format(GUARDIANA_DEFAULT_QUERY, title) if req.video_games_system_type then url = url .. "&platform=54" -- FIXME that's Genesis end print ("Fetching search page " .. url) grl.fetch(url, "fetch_results_cb") end --------------- -- Utilities -- --------------- function fetch_results_cb(results) if results then local item = results:match('(.-)') local link = item:match('href="(.-)"') local url = "http://www.gamefaqs.com" .. link print (url) grl.fetch(url, "fetch_page_cb") -- grl.callback() end end function fetch_page_cb(page) local media = {} media.description = page:match('
(.-)
') media.thumbnail = page:match('class="boxshot" src="(.-)"') -- FIXME match doesn't work media.rating = page:match('
(%d+) /.-') grl.callback(media, 0) end