-
Notifications
You must be signed in to change notification settings - Fork 2
/
soundcloud.lua_TEMP
94 lines (76 loc) · 2.8 KB
/
soundcloud.lua_TEMP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
--[[
$Id$
Copyright © 2012, 2015 the VideoLAN team
Modified: TRC4 <[email protected]>
--]]
-- Probe function.
function probe()
local path = vlc.path
path = path:gsub("^www%.", "")
return ( vlc.access == "http" or vlc.access == "https" )
and string.match( path, "^soundcloud%.com/.+/.+" )
end
function fix_quotes( value )
if string.match( value, "^\"" ) then
return "" -- field was really empty string
end
-- TODO: handle escaped backslashes and others
return string.gsub( value, "\\\"", "\"" )
end
-- Parse function.
function parse()
while true do
line = vlc.readline()
if not line then break end
-- Parameters for API call
if not track then
track = string.match( line, "soundcloud:tracks:(%d+)" )
end
-- For private tracks
if not secret then
secret = string.match( line, "[\"']secret_token[\"'] *: *[\"'](.-)[\"']" )
end
-- Metadata
if not name then
name = string.match( line, "[\"']title[\"'] *: *\"(.-[^\\])\"" )
if name then
name = fix_quotes( name )
end
end
if not description then
description = string.match( line, "[\"']artwork_url[\"'] *:.-[\"']description[\"'] *: *\"(.-[^\\])\"" )
if description then
description = fix_quotes( description )
end
end
if not artist then
artist = string.match( line, "[\"']username[\"'] *: *\"(.-[^\\])\"" )
if artist then
artist = fix_quotes( artist )
end
end
if not arturl then
arturl = string.match( line, "[\"']artwork_url[\"'] *: *[\"'](.-)[\"']" )
end
end
if track then
-- THIS IS MY API, PLEASE CHANGE WITH YOURS CLIENT ID
local client_id = "22e8f71d7ca75e156d6b2f0e0a5172b3"
local app_version = "1505226596"
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 "" ) )
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
vlc.msg.err( "Couldn't extract Soundcloud Audio URL, Please Check for Updates to this Script" )
return { }
end
return { { path = path, name = name, description = description, artist = artist, arturl = arturl } }
end