Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save NeuroCPP/fea44ac91c91e2923e8d43c6e9e96654 to your computer and use it in GitHub Desktop.
Save NeuroCPP/fea44ac91c91e2923e8d43c6e9e96654 to your computer and use it in GitHub Desktop.
Modified VLC YouTube playlist parsing script. The original script was not working anymore because youtube removed the list_ajax interface. Unfortunately the new interface requires at least http GET method with proper headers and they are not supported by vlc. So this version makes use of an external program (youtube-dl). Disclaimer: this version…
--[[
Youtube playlist importer for VLC media player 1.1 and 2.0
Copyright 2012 Guillaume Le Maout
Authors: Guillaume Le Maout
Contact: http://addons.videolan.org/messages/?action=newmessage&username=exebetche
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 2 of the License, 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 Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
--]]
--[[
MODified by Kai Gillmann, 19.01.2013, kaigillmann@googlemail.com:
VLC HAS already a youtube importer, but not for playlists. IMO this mentioned one is
better than this one, because it opens the video in the best possible video resolution.
So i decided to remove all parts of the code which is not responsible for list handling.
Now this lua script parses the list, as wanted, but for each video opened, the vlc default
Youtube script is used, so the videos will be displayed properly.
--]]
--[[
Youtube playlist importer for VLC media player 1.1 and 2.0
Copyright 2012 Guillaume Le Maout
Authors: Guillaume Le Maout
Contact: http://addons.videolan.org/messages/?action=newmessage&username=exebetche
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 2 of the License, 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 Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
--]]
--[[
MODified by Kai Gillmann, 19.01.2013, kaigillmann@googlemail.com:
VLC HAS already a youtube importer, but not for playlists. IMO this mentioned one is
better than this one, because it opens the video in the best possible video resolution.
So i decided to remove all parts of the code which is not responsible for list handling.
Now this lua script parses the list, as wanted, but for each video opened, the vlc default
Youtube script is used, so the videos will be displayed properly.
--]]
--[[
Patched by Aaron Hill (https://github.com/seraku24), 2018-05-16:
The original script was failing in VLC 3.x due to an overzealous probe function.
This patch makes the probe function more restrictive to avoid false positives.
--]]
--[[
Patched by Matteo Federico Zazzetta (https://github.com/p3g4asus), 2020-02-17:
The original script was not working anymore because youtube removed the list_ajax interface.
Unfortunately the new interface requires at least http GET method with proper headers and
they are not supported by vlc. So this version makes use of an external program (youtube-dl).
Disclaimer: this version works only under Windows. It can be easily ported but I have no way to test
it on other OS at the moment.
Installation (under Windows): place this file in the lua playlist vlc folder together with JSON.lua
(http://regex.info/code/JSON.lua) and youtube-dl.exe (https://youtube-dl.org/latest)
--]]
-- Probe function.
function probe()
if vlc.access ~= "http" and vlc.access ~= "https" then
return false
end
return string.match(vlc.path:match("([^/]+)"),"%w+.youtube.com") and (
not string.match(vlc.path, "list_ajax") and string.match(vlc.path, "[?&]list="))
end
local function isdef(p,...)
if not p then
return false
else
local tb = p
for i,v in ipairs(arg) do
if tb[v]==nil then
return false
else
tb = tb[v]
end
end
return true
end
end
function Log(lm)
vlc.msg.info("[youtube_pl.lua] " .. tostring(lm))
end
function get_url_param( url, name )
local _, _, res = string.find( url, "[&?]"..name.."=([^&]*)" )
return res
end
function try_yt_dl(lst)
local info = debug.getinfo(1,'S');
local kk,jj,ll = string.match(string.sub(info.source,2), "(.-)([^\\/]-%.?([^%.\\/]*))$")
Log("Trying ytdl "..kk)
local link = vlc.access.."://www.youtube.com/playlist?list="..lst
local JSON = (loadfile (kk.."JSON.lua"))()
local bat_dir3 = "cmd /k \"\""..kk.."youtube-dl.exe\" -j --flat-playlist \""..link.."\"\""
local f = assert(io.popen (bat_dir3, 'r'))
local p = {}
Log("Exec "..bat_dir3)
-- local bat_dir2 = "> \""..kk.."youtube-dl.txt\" \""..kk.."youtube-dl.exe\" -j --flat-playlist \""..link.."\""
-- Log("Exec "..bat_dir2)
-- os.execute(bat_dir2)
-- local outfile = kk.."youtube-dl.txt"
-- Log("Open "..outfile)
local p = {}
for json in f:lines() do
Log(json)
local rv, pall = pcall(function () return JSON:decode(json) end)
if rv and isdef(pall,"id") then
local item = {}
item.path = "https://www.youtube.com/watch?v="..pall.id
if isdef(pall,"title") then
item.title = pall.title
end
if isdef(pall,"duration") then
item.duration = math.floor(tonumber(pall.duration))
end
table.insert (p, item)
end
end
f:close()
return p
end
-- Parse function.
function parse()
if string.match( vlc.path, "list=" ) then
local lst = get_url_param(vlc.path, "list")
return try_yt_dl(lst)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment