share/Makefile.am: Reorganize blocks, comments
[libquvi-scripts.git] / share / lua / playlist / soundcloud.lua
blob69d540ffbc140e6224ab97b3364689280989ef84
1 -- libquvi-scripts
2 -- Copyright (C) 2012 Toni Gundogdu <legatvs@gmail.com>
3 --
4 -- This file is part of libquvi-scripts <http://quvi.sourceforge.net/>.
5 --
6 -- This library is free software; you can redistribute it and/or
7 -- modify it under the terms of the GNU Lesser General Public
8 -- License as published by the Free Software Foundation; either
9 -- version 2.1 of the License, or (at your option) any later version.
11 -- This library is distributed in the hope that it will be useful,
12 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
13 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 -- Lesser General Public License for more details.
16 -- You should have received a copy of the GNU Lesser General Public
17 -- License along with this library; if not, write to the Free Software
18 -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 -- 02110-1301 USA
22 -- Identify the playlist script.
23 function ident(qargs)
24 local A = require 'quvi/accepts'
25 local r = {
26 accepts = A.accepts(qargs.input_url,
27 {"soundcloud%.com"}, {'/sets/[%w-_]+/'})
29 return r
30 end
32 -- Parse playlist properties.
33 function parse(qargs)
35 qargs.id, s = qargs.input_url:match('/([%w-_]+)/sets/([%w-_]+)/')
36 if qargs.id and s then
37 qargs.id = qargs.id .."_".. s
38 end
40 local C = require 'quvi/const'
41 local o = { [C.qfo_type] = C.qft_playlist }
42 local p = quvi.fetch(qargs.input_url, o)
44 qargs.thumb_url = p:match('.+content="(.-)"%s+property="og:image"') or ''
45 qargs.title = p:match('.+content="(.-)"%s+property="og:title"') or ''
47 local m = 'class="info">.-href="(.-)"'
48 .. '.-class="set%-track%-title">(.-)<'
49 .. '.-class="time">(.-)<'
51 qargs.media = {}
53 for u,t,d in p:gmatch(m) do
54 local m,s = d:match('(%d+)%.(%d+)')
55 local r = {
56 duration_ms = ((tonumber(m or '0')*60) + tonumber(s or '0')) *1000,
57 url = "http://soundcloud" ..u,
58 title = t
60 table.insert(qargs.media, r)
61 end
63 return qargs
64 end
66 -- vim: set ts=2 sw=2 tw=72 expandtab: