Skip to content

Instantly share code, notes, and snippets.

@mfaizsyahmi
Last active June 29, 2021 20:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mfaizsyahmi/3c5a350f5e47a8b962b1b6f662fd280b to your computer and use it in GitHub Desktop.
Save mfaizsyahmi/3c5a350f5e47a8b962b1b6f662fd280b to your computer and use it in GitHub Desktop.
VLC YouTube Playlist parser using youtube-dl
--[[
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.
--]]
--[[
Mfaizsyahmi 2021-06-01:
Rewrote parse() to use youtube-dl
--]]
-- Helper function to get a parameter's value in a URL
function get_url_param( url, name )
local _, _, res = string.find( url, "[&?]"..name.."=([^&]*)" )
return res
end
-- 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
-- Parse function.
function parse()
if string.match( vlc.path, "list=" ) then
local handle = io.popen("youtube-dl -j --flat-playlist " .. vlc.path)
local items = {}
for item_json in handle:lines() do
_, _, id = string.find(item_json, '"id": "([%w_\-]+)"')
_, _, title = string.find(item_json, '"title": "([^"]+)"')
table.insert(items, {path = "https://youtu.be/" .. id; name = title})
end
return items
end
end
@mfaizsyahmi
Copy link
Author

Because all of the parsers out there are in various states of brokenness, I resorted to use an external program, the one I know to work: youtube-dl. Obviously, you need to have youtube-dl installed.

The console window running youtube-dl will flash for a few seconds. Lua standard library has no control over this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment