Skip to content

Instantly share code, notes, and snippets.

@seraku24
Created May 16, 2018 09:56
Show Gist options
  • Star 47 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save seraku24/db42e0e418b2252f2136d2d7f1656be5 to your computer and use it in GitHub Desktop.
Save seraku24/db42e0e418b2252f2136d2d7f1656be5 to your computer and use it in GitHub Desktop.
VLC 3.x compatibility patch for 149909-playlist_youtube.lua
--[[
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.
--]]
-- 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 playlist_parsed, playlistData, line, s, item
local p = {}
local id_ref = {}
local index = 1
local playlistID = get_url_param( vlc.path, "list" )
local videoID = get_url_param( vlc.path, "v" )
local playlistURL = "http://www.youtube.com/list_ajax?action_get_list=1&style=xml&list="..playlistID
while true do
playlistData = ""
line = ""
s = nil
s = vlc.stream(playlistURL.."&index="..index)
while line do
playlistData = playlistData..line
line = s:readline()
end
playlist_parsed = nil
playlist_parsed = parse_xml(playlistData).root.video
for i, video in ipairs(playlist_parsed) do
vlc.msg.err(i.." "..video.encrypted_id.CDATA)
if id_ref[video.encrypted_id.CDATA]
and id_ref[video.encrypted_id.CDATA] == i
then
return p
else
id_ref[video.encrypted_id.CDATA] = i
end
item = nil
item = {}
if video.encrypted_id
and video.encrypted_id.CDATA then
item.path = "http://www.youtube.com/watch?v="..video.encrypted_id.CDATA
end
if video.title
and video.title.CDATA then
item.title = video.title.CDATA
end
if video.artist
and video.artist.CDATA then
item.artist = video.artist.CDATA
end
if video.thumbnail
and video.thumbnail.CDATA then
item.arturl = video.thumbnail.CDATA
end
if video.description
and video.description.CDATA then
item.description = video.description.CDATA
end
--~ item.rating = video.rating
table.insert (p, item)
end
if #playlist_parsed == 100 then
index = index +100
else
return p
end
end
end
end
function parse_xml(data)
local tree = {}
local stack = {}
local tmp = {}
local tmpTag = ""
local level = 0
table.insert(stack, tree)
for op, tag, attr, empty, val in string.gmatch(
data,
"<(%p?)([^%s>/]+)([^>]-)(%/?)>[%s\r\n\t]*([^<]*)[%s\r\n\t]*") do
if op=="?" then
--~ DOCTYPE
elseif op=="/" then
if level>0 then
level = level - 1
table.remove(stack)
end
else
level = level + 1
if op=="!" then
stack[level]['CDATA'] = vlc.strings.resolve_xml_special_chars(
string.gsub(tag..attr, "%[CDATA%[(.+)%]%]", "%1"))
attr = ""
level = level - 1
elseif type(stack[level][tag]) == "nil" then
stack[level][tag] = {}
table.insert(stack, stack[level][tag])
else
if type(stack[level][tag][1]) == "nil" then
tmp = nil
tmp = stack[level][tag]
stack[level][tag] = nil
stack[level][tag] = {}
table.insert(stack[level][tag], tmp)
end
tmp = nil
tmp = {}
table.insert(stack[level][tag], tmp)
table.insert(stack, tmp)
end
if val~="" then
stack[level][tag]['CDATA'] = {}
stack[level][tag]['CDATA'] = vlc.strings.resolve_xml_special_chars(val)
end
if attr ~= "" then
stack[level][tag]['ATTR'] = {}
string.gsub(attr,
"(%w+)=([\"'])(.-)%2",
function (name, _, value)
stack[level][tag]['ATTR'][name] = value
end)
end
if empty ~= "" then
level = level - 1
table.remove(stack)
end
end
end
return tree
end
@greasythemattis
Copy link

It's not loading the entire playlist for me

@maholloway
Copy link

This worked for me as well, not sure it loads entire playlist yet though...

@DJGoo
Copy link

DJGoo commented Mar 26, 2019

This worked for me as well, not sure it loads entire playlist yet though...

It doesn't, I was trying to load the Yogscast TTT playlist and it stopped at 200 and wouldn't load more

@francisco5em
Copy link

i want to add a warning, i haven't tested the limits of the scripts but i can say that it only works if the playlist is public only.

Copy link

ghost commented May 16, 2020

oh! this worked for me! thanks a lot.
tried on manjaro linux
VLC 3.0.5

@cosmindrimba
Copy link

VLC 3.0.9 - I can see the individual songs in the playlist once I open the YT playlist link, but it just skips over all of them.

@xerus6
Copy link

xerus6 commented May 31, 2020

God it's so nice I love it, thanks bro ( June 2020 )

@mfaizsyahmi
Copy link

Broken as of 11 February 2021. It appears that the /list_ajax request to YouTube returns a 404.

@Druxtt
Copy link

Druxtt commented Feb 14, 2021

Broken as of 11 February 2021. It appears that the /list_ajax request to YouTube returns a 404.

yep, broken for me also :(

@xerus6
Copy link

xerus6 commented Feb 15, 2021

Rip you guys..

@czoins
Copy link

czoins commented Feb 18, 2021

There's a modified fork using youtube-dl instead, read the README or check the discussion:
https://gist.github.com/Seneral/bd64281ae30a6010e97d956ecd63238e

@bastibeckr
Copy link

Hi, i created an updated version, it works for me, feel free to improve it.

https://gist.github.com/bastibeckr/16f57b6bdecf27b772d6433b2090bf61

@pkutaj
Copy link

pkutaj commented Mar 19, 2021

Hi, i created an updated version, it works for me, feel free to improve it.

https://gist.github.com/bastibeckr/16f57b6bdecf27b772d6433b2090bf61

Thanks! Currently limited to 15 tracks, though.

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