Skip to content

Instantly share code, notes, and snippets.

@vrutkovs
Last active August 29, 2015 14:02
Show Gist options
  • Save vrutkovs/6a495297c8628e8f2bdf to your computer and use it in GitHub Desktop.
Save vrutkovs/6a495297c8628e8f2bdf to your computer and use it in GitHub Desktop.
iplayer.fm
--[[
* Copyright (C) 2014 Vadim Rutkovsky
*
* Contact: Vadim Rutkovsky <vrutkovs@redhat.com>
*
* 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
*
--]]
MAIN_URL = 'http://iplayer.fm/q/%s'
---------------------------
-- Source initialization --
---------------------------
source = {
id = "grl-iplayer-fm-lua",
name = "iplayer.fm",
description = "A source for browsing music from iplayer.fm",
supported_keys = { "id", "thumbnail", "title", "url", "mime-type" },
supported_media = 'audio',
supported_media = 'search',
tags = { 'music'}
}
------------------
-- Source utils --
------------------
function grl_source_search(text)
local search_url = string.format(MAIN_URL, text)
grl.fetch(search_url, "iplayer_fetch_cb")
end
------------------------
-- Callback functions --
------------------------
-- return all the media found
function iplayer_fetch_cb(results)
if not results then
grl.callback()
end
-- get track list
local request_limit_counter = 0
local fetch_urls = {}
for li in results:gmatch('<li class="track" (.-)</h4>') do
media = {}
media['type'] = 'audio'
media.id = li:match('id="(.-)"')
media.url = li:match('mp3="(.-)"')
media.title = li:match('<span>(.-)</span>')
media.artist = li:match('<b>(.-)</b>')
grl.callback(media, -1)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment