-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsoundcloud.lua
106 lines (102 loc) · 2.71 KB
/
soundcloud.lua
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
95
96
97
98
99
100
101
102
103
104
105
106
--[[
$Id$
Copyright © 2007-2022 the VideoLAN team
Soundcloud Playlist importer for VLC media player 1.x 2.x 3.x
Tested on VLC Player 3.0.16
To play videos need to paste soundcloud.lua in C:\Program Files (x86)\VideoLAN\VLC\lua\playlist
Modified: TRC4 <trc4@usa.com>
Example URL: https://soundcloud.com/sxtbox/trc4-deejay-dance-with-the
--]]
-- 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 ""
end
return string.gsub(value, "\\\"", "\"")
end
function extract_magic(url)
local s = vlc.stream(url)
if not s then
return nil
end
local line = s:read(4194304)
if not line then
return nil
end
local client_id = string.match(line, "[{,]client_id:\"(%w+)\"[},]")
if client_id then
vlc.msg.dbg("Soundcloud Found API Magic")
return client_id
end
return nil
end
-- Parse function
function parse()
while true do
local line = vlc.readline()
if not line then
break
end
if not stream then
stream = string.match(line, "\"url\":\"([^\"]-/stream/progressive[^\"]-)\"")
end
if not client_id then
local script = string.match(line, "<script( .-)>")
if script then
local src = string.match(script, " src=\"(.-)\"")
if src then
client_id = extract_magic(src)
end
end
end
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 stream then
if client_id then
stream = stream .. (string.match(stream, "?") and "&" or "?") .. "client_id=" .. client_id
end
local api = vlc.stream(stream)
if api then
local streams = api:readline()
path = string.match(streams, "\"url\":\"(.-)\"")
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