2 -- Copyright (C) 2012-2013 Toni Gundogdu <legatvs@gmail.com>
4 -- This file is part of libquvi-scripts <http://quvi.sourceforge.net/>.
6 -- This program is free software: you can redistribute it and/or
7 -- modify it under the terms of the GNU Affero General Public
8 -- License as published by the Free Software Foundation, either
9 -- version 3 of the License, or (at your option) any later version.
11 -- This program 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
14 -- GNU Affero General Public License for more details.
16 -- You should have received a copy of the GNU Affero General
17 -- Public License along with this program. If not, see
18 -- <http://www.gnu.org/licenses/>.
21 local Soundcloud
= {} -- Utility functions unique to this script
23 -- Identify the playlist script.
26 domains
= table.concat({'soundcloud.com'}, ','),
27 can_parse_url
= Soundcloud
.can_parse_url(qargs
)
31 -- Parse playlist properties.
34 qargs
.id
, s
= qargs
.input_url
:match('/([%w-_]+)/sets/([%w-_]+)/')
35 if qargs
.id
and s
then
36 qargs
.id
= qargs
.id
.."_".. s
39 local p
= quvi
.http
.fetch(qargs
.input_url
).data
41 qargs
.thumb_url
= p
:match('.+content="(.-)"%s+property="og:image"') or ''
42 qargs
.title
= p
:match('.+content="(.-)"%s+property="og:title"') or ''
44 local m
= 'class="info">.-href="(.-)"'
45 .. '.-class="set%-track%-title".->(.-)<'
46 .. '.-class="time">(.-)<'
50 for u
,t
,d
in p
:gmatch(m
) do
51 local m
,s
= d
:match('(%d+)%.(%d+)')
53 duration_ms
= ((tonumber(m
or '0')*60) + tonumber(s
or '0')) *1000,
54 url
= "http://soundcloud.com" ..u
,
57 table.insert(qargs
.media
, r
)
67 function Soundcloud
.can_parse_url(qargs
)
68 local U
= require
'socket.url'
69 local t
= U
.parse(qargs
.input_url
)
70 if t
and t
.scheme
and t
.scheme
:lower():match('^https?$')
71 and t
.host
and t
.host
:lower():match('soundcloud%.com$')
72 and t
.path
and t
.path
:lower():match('^/.-/sets/[%w-_]+/$')
80 -- vim: set ts=2 sw=2 tw=72 expandtab: