ytdl_hook: use table concat for playlist building

Faster and more efficient than string concat with large playlists.
This commit is contained in:
Ricardo Constantino 2017-12-24 13:13:57 +00:00 committed by Kevin Mitchell
parent 1623430b20
commit b1b03da137
1 changed files with 4 additions and 5 deletions

View File

@ -454,15 +454,14 @@ mp.add_hook("on_load", 10, function ()
msg.verbose("Playlist with single entry detected.") msg.verbose("Playlist with single entry detected.")
add_single_video(json.entries[1]) add_single_video(json.entries[1])
else else
local playlist = {"#EXTM3U"}
local playlist = "#EXTM3U\n"
for i, entry in pairs(json.entries) do for i, entry in pairs(json.entries) do
local site = entry.url local site = entry.url
local title = entry.title local title = entry.title
if not (title == nil) then if not (title == nil) then
title = string.gsub(title, '%s+', ' ') title = string.gsub(title, '%s+', ' ')
playlist = playlist .. "#EXTINF:0," .. title .. "\n" table.insert(playlist, "#EXTINF:0," .. title)
end end
-- some extractors will still return the full info for -- some extractors will still return the full info for
@ -478,11 +477,11 @@ mp.add_hook("on_load", 10, function ()
if not (site:find("https?://") == 1) then if not (site:find("https?://") == 1) then
site = "ytdl://" .. site site = "ytdl://" .. site
end end
playlist = playlist .. site .. "\n" table.insert(playlist, site)
end end
mp.set_property("stream-open-filename", "memory://" .. playlist) mp.set_property("stream-open-filename", "memory://" .. table.concat(playlist, "\n"))
end end
else -- probably a video else -- probably a video