Perhaps it could become a part of Sampler (PG).
Code: Select all
-- VLC Extension that searches for playlist items (location) in several xspf playlists
-- and then combines them in 1 playlist so the items take turns: {a1, b1, a2, b2, b3}
-- or {a1, b1, a2, b2, a1, b3}.
--[[
tab={
{"a1","a2"},
{"b1","b2","b3"},
}
--]]
-- TO DO: proper parsing of playlist files; parsing of folders;
function descriptor()
return {
title = "Mix playlists",
capabilities = {},
}
end
function activate()
Create_dialog()
end
function deactivate()
end
function meta_changed()
end
function close()
vlc.deactivate()
end
---------------------------
function Create_dialog()
d = vlc.dialog(descriptor().title)
l_mix = d:add_label("Enqueue xspf playlist files in VLC playlist,<br /> then press [Read playlist] button,<br /> then [Clear playlist]<br /> and then [Mix].",1,1,3,2)
cb_supplement = d:add_check_box("supplement", false, 3,2,1,1)
d:add_button("Read playlist", click_Read, 1,3,1,1)
d:add_button("Clear playlist", click_Clear, 2,3,1,1)
d:add_button("Mix", click_Mix, 3,3,1,1)
end
function click_Read()
tab={}
local playlist = vlc.playlist.get("playlist",false)
for k, item in pairs(playlist.children) do
if string.match(item.path, "%.xspf$") then
local s = vlc.stream(item.path)
--if s==nil then return false end
local playlist_tab = {}
while true do
line = s:readline()
if not line then
break
else
for location in string.gmatch(line, "<location>(.-)</location>") do
table.insert(playlist_tab, vlc.strings.resolve_xml_special_chars(location))
end
end
end
vlc.msg.info(#playlist_tab)
table.insert(tab, playlist_tab)
end
end
local message=""
for i,v in ipairs(tab) do
message=message.."Playlist "..i..": "..#v.." items<br />"
end
if message=="" then message="No items found." end
l_mix:set_text(message)
end
function click_Clear()
vlc.playlist.clear()
end
function click_Mix()
local tabmix={}
local x=0
local a=0
for i,v in ipairs(tab) do
if #v>a then a=#v end
end
while true do
x=x+1
local y=0
for i,v in ipairs(tab) do
if v[x]~=nil then
y=y+1
table.insert(tabmix, v[x])
elseif cb_supplement:get_checked() then
table.insert(tabmix, v[(x-1) % #v + 1])
end
end
if x==a or y==0 then break end
end
--l_mix:set_text(table.concat(tabmix,", "))
for i,v in ipairs(tabmix) do
vlc.playlist.enqueue({{path=v}})
end
end
vlc.strings.resolve_xml_special_chars