Created
July 13, 2017 05:24
-
-
Save samkatakouzinos/502ec9d5ad29181aaaee5094ef5bf5ef to your computer and use it in GitHub Desktop.
SoundCloud set playlist plugin for VLC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[-- | |
SonundCloud set (playlist) parser | |
Made by MarcusD | |
This is a VLC playlist plugin to be able to play SoundCloud sets | |
Note: if it's not working, download http://regex.info/code/JSON.lua as VLC/lua/modules/JSON.lua | |
An example set link: https://soundcloud.com/pe-mahhieux/sets/savant | |
My GitHub page: https://github.com/MarcuzD | |
My Youtube channel: https://youtube.com/user/mCucc | |
The MIT License (MIT) | |
Copyright (c) 2016 Horváth Márk "MarcusD" Dániel | |
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
--]]-- | |
-- SoundCloud ClientID | |
--local cid = "b45b1aa10f1ac2941910a7f0d10f8e28" | |
local cid = "02gUJC0hH2ct1EGOcYXQIzRFU91c72Ea" | |
--local appversion = "f3cc0b3" | |
local json = require("JSON"):new() | |
function json.assert(wat, msg) | |
if wat then | |
print(msg) | |
else | |
vlc.msg.err(msg) | |
end | |
end | |
-- Probe function. | |
function probe() | |
return ( vlc.access == "https" or vlc.access == "http" ) | |
and string.match( vlc.path, "(soundcloud%.com/[^/]+/sets/[^?/]+)" ) | |
end | |
local function tf(s) | |
local t = {} | |
local ejj | |
t.main, _, ejj = json:decode(s, 1, nil) | |
if not t.main then local _, charnum = ejj:match("column (%d)+") charnum = tonumber(charnum) vlc.msg.err("================[NO PARSER]================") vlc.msg.err(ejj) vlc.msg.err("================[JSON DUMP]================") vlc.msg.err(s:sub(charnum - 10, charnum + 10)) vlc.msg.err("================[JSON DUMP]================") error(ejj) end | |
return t | |
end | |
-- Parse function. | |
function parse() | |
local s, ejj = vlc.stream("https://soundcloud.com/oembed?format=json&url=https://" .. vlc.path) | |
if s == nil then error(ejj) end | |
local line = s:readline() | |
if line == nil then error("No oembed line") end | |
line = string.match(line, "api.soundcloud.com%%2Fplaylists%%2F(%d+)") | |
if line == nil then error("No track regex'd") end | |
s, ejj = vlc.stream("https://api.soundcloud.com/playlists/" .. line .. "?client_id=" .. cid) | |
if s == nil then error(ejj) end | |
local buf = {} | |
local cnt = 0 | |
line = s:read(1) | |
repeat | |
--print(line) | |
if line then buf[#buf + 1] = line cnt = 0 end | |
line = s:read(1) | |
if not line then cnt = cnt + 1 end | |
until cnt == 4 | |
if not buf[1] then error("================[NO DATA]==============") end | |
line = table.concat(buf) | |
strr = tf(line) | |
buf = {} | |
for k,v in pairs(strr.main.tracks) do | |
buf[#buf + 1 ] = | |
{ | |
path = (v.stream_url .. "?client_id=" .. cid), | |
name = v.title, | |
arturl = (v.artwork_url and v.artwork_url or v.user.artwork_url), | |
title = v.title, | |
artist = (v.user.username .. " (" .. v.user.permalink.. ")"), | |
genre = v.genre, | |
copyright = v.license, | |
description = v.description, | |
date = v.created_at, | |
url = vlc.access .. "://" .. v.permalink_url, | |
meta = | |
{ | |
["tag list"] = v.tag_list, | |
["creation time"] = v.created_at | |
} | |
} | |
end | |
return buf | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for keeping this up somewhere, does it still work? Tried my own client id