Professional Documents
Culture Documents
Youtube playlist importer for VLC media player 1.1 and 2.0
Copyright 2012 Guillaume Le Maout
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.
--]]
-- Probe function.
function probe()
if vlc.access ~= "http" and vlc.access ~= "https" then
return false
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
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
function parse_xml(data)
local tree = {}
local stack = {}
local tmp = {}
local tmpTag = ""
local level = 0
table.insert(stack, tree)
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