4 Copyright © 2012, 2015 the VideoLAN team
6 Authors: Cheng Sun <chengsun9atgmail.com>
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
26 return ( vlc.access == "http" or vlc.access == "https" )
27 and string.match( vlc.path, "soundcloud%.com/.+/.+" )
30 function fix_quotes( value )
31 if string.match( value, "^\"" ) then
32 return "" -- field was really empty string
35 -- TODO: handle escaped backslashes and others
36 return string.gsub( value, "\\\"", "\"" )
43 if not line then break end
45 -- Parameters for API call
47 track = string.match( line, "soundcloud:tracks:(%d+)" )
52 secret = string.match( line, "[\"']secret_token[\"'] *: *[\"'](.-)[\"']" )
57 name = string.match( line, "[\"']title[\"'] *: *\"(.-[^\\])\"" )
59 name = fix_quotes( name )
63 if not description then
64 description = string.match( line, "[\"']artwork_url[\"'] *:.-[\"']description[\"'] *: *\"(.-[^\\])\"" )
66 description = fix_quotes( description )
71 artist = string.match( line, "[\"']username[\"'] *: *\"(.-[^\\])\"" )
73 artist = fix_quotes( artist )
78 arturl = string.match( line, "[\"']artwork_url[\"'] *: *[\"'](.-)[\"']" )
84 local client_id = "02gUJC0hH2ct1EGOcYXQIzRFU91c72Ea"
85 -- app_version is not required by the API but we send it anyway
86 -- to remain unconspicuous
87 local app_version = "a089efd"
89 local api = vlc.stream( vlc.access.."://api.soundcloud.com/i1/tracks/"..track.."/streams?client_id="..client_id.."&app_version="..app_version..( secret and "&secret_token="..secret or "" ) )
92 local streams = api:readline() -- data is on one line only
93 -- For now only quality available is 128 kbps (http_mp3_128_url)
94 path = string.match( streams, "[\"']http_mp3_%d+_url[\"'] *: *[\"'](.-)[\"']" )
96 -- FIXME: do this properly
97 path = string.gsub( path, "\\u0026", "&" )
103 vlc.msg.err( "Couldn't extract soundcloud audio URL, please check for updates to this script" )
107 return { { path = path, name = name, description = description, artist = artist, arturl = arturl } }