Last active
February 18, 2021 19:05
-
-
Save SonoSooS/573d3f031bd61a650a65d5238b80164c to your computer and use it in GitHub Desktop.
Bandcamp VLC plugin
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
--[[-- | |
bandcamp.lua - Bandcamp album/track player plugin | |
Copyright (C) 2016-2018 Sono (https://github.com/MarcuzD) | |
This program is free software: you can redistribute it and/or modify | |
it under the terms of the GNU General Public License as | |
published by the Free Software Foundation, either version 3, or | |
(at your option) any later version. | |
This program is distributed in the hope that it will be useful, but | |
WITHOUT ANY WARRANTY; without even the implied warranty of | |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
General Lesser Public License for more details. | |
You should have received a copy of the GNU General Public License | |
along with this program. If not, see <http://www.gnu.org/licenses/>. | |
Note: this script requires JSON.lua to be downloaded from http://regex.info/code/JSON.lua as VLC/lua/modules/JSON.lua | |
An example album link: https://gilvasunner.bandcamp.com/album/cd-grand-beta | |
An example track link: https://aavepyora.bandcamp.com/track/valo-voima-ja-vapaus | |
My GitHub page: https://github.com/MarcuzD | |
My Youtube channel: https://youtube.com/user/mCucc | |
--]]-- | |
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, "([^%.]%.bandcamp%.com/album/[^/]+)$") | |
or string.match( vlc.path, "([^%.]%.bandcamp%.com/track/[^/]+)$")) | |
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 line = vlc.readline() | |
while true do | |
if not line then break end | |
line = line:match("content=\"(https://bandcamp.com/EmbeddedPlayer/[^\"]+)") | |
if line then break end | |
line = vlc.readline() | |
end | |
if line == nil then error("No EmbeddedPlayer!") end | |
local s, ejj = vlc.stream(line) | |
if s == nil then error(ejj) end | |
line = s:readline() | |
while true do | |
if not line then break end | |
line = line:match("var playerdata = (.*);$") | |
if line then break end | |
line = s:readline() | |
end | |
if not line then error("No playerdata!") end | |
local strr = tf(line) | |
buf = {} | |
for k,v in pairs(strr.main.tracks) do | |
buf[#buf + 1 ] = | |
{ | |
path = v.file["mp3-128"], | |
name = v.title, | |
arturl = (strr.main.album_art_lg and strr.main.album_art_lg or strr.main.album_art), | |
title = v.title, | |
artist = v.artist, | |
url = v.title_link | |
} | |
end | |
return buf | |
end |
I can't believe people are still using this outdated garbage!
I'll install VLC and try to troubleshoot it. Will report back a few days later how it went (I have a job, so my time is limited).
It took me so long to debug this issue!
@zloster I uploaded the updated plugin to a repo instead of this gist https://github.com/SonoSooS/aaa_vlc/blob/master/playlist/bandcamp.lua
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've noticed a problem with handling a track names with
/
in them. If an album contains such a track there will be a failure to load the playlist in the VLC.Example:
1. The Code Noir / Amina 07:30
. This album fails to load in the VLC playlist.