Commit d4b92298 authored by Pierre Ynard's avatar Pierre Ynard

soundcloud.lua: support for private tracks

parent 58ad6be8
...@@ -42,30 +42,17 @@ function parse() ...@@ -42,30 +42,17 @@ function parse()
line = vlc.readline() line = vlc.readline()
if not line then break end if not line then break end
if not path then -- Parameters for API call
local track = string.match( line, "soundcloud:tracks:(%d+)" ) if not track then
if track then track = string.match( line, "soundcloud:tracks:(%d+)" )
-- API magic end
local client_id = "02gUJC0hH2ct1EGOcYXQIzRFU91c72Ea"
-- app_version is not required by the API but we send it -- For private tracks
-- anyway to remain unconspicuous if not secret then
local app_version = "a089efd" secret = string.match( line, "[\"']secret_token[\"'] *: *[\"'](.-)[\"']" )
local api = vlc.stream( "https://api.soundcloud.com/i1/tracks/"..track.."/streams?client_id="..client_id.."&app_version="..app_version )
if not api then
break
end
local streams = api:readline() -- data is on one line only
-- For now only quality available is 128 kbps (http_mp3_128_url)
path = string.match( streams, "[\"']http_mp3_%d+_url[\"'] *: *[\"'](.-)[\"']" )
if path then
-- FIXME: do this properly
path = string.gsub( path, "\\u0026", "&" )
end
end
end end
-- Metadata
if not name then if not name then
name = string.match( line, "[\"']title[\"'] *: *\"(.-[^\\])\"" ) name = string.match( line, "[\"']title[\"'] *: *\"(.-[^\\])\"" )
if name then if name then
...@@ -92,6 +79,26 @@ function parse() ...@@ -92,6 +79,26 @@ function parse()
end end
end end
if track then
-- API magic
local client_id = "02gUJC0hH2ct1EGOcYXQIzRFU91c72Ea"
-- app_version is not required by the API but we send it anyway
-- to remain unconspicuous
local app_version = "a089efd"
local api = vlc.stream( "https://api.soundcloud.com/i1/tracks/"..track.."/streams?client_id="..client_id.."&app_version="..app_version..( secret and "&secret_token="..secret or "" ) )
if api then
local streams = api:readline() -- data is on one line only
-- For now only quality available is 128 kbps (http_mp3_128_url)
path = string.match( streams, "[\"']http_mp3_%d+_url[\"'] *: *[\"'](.-)[\"']" )
if path then
-- FIXME: do this properly
path = string.gsub( path, "\\u0026", "&" )
end
end
end
if not path then if not path then
vlc.msg.err( "Couldn't extract soundcloud audio URL, please check for updates to this script" ) vlc.msg.err( "Couldn't extract soundcloud audio URL, please check for updates to this script" )
return { } return { }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment