From b1b03da1378716502ae12671d1ef23e5d11b52b2 Mon Sep 17 00:00:00 2001 From: Ricardo Constantino Date: Sun, 24 Dec 2017 13:13:57 +0000 Subject: ytdl_hook: use table concat for playlist building Faster and more efficient than string concat with large playlists. --- player/lua/ytdl_hook.lua | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'player') diff --git a/player/lua/ytdl_hook.lua b/player/lua/ytdl_hook.lua index c61c38cc99..8aef3e4540 100644 --- a/player/lua/ytdl_hook.lua +++ b/player/lua/ytdl_hook.lua @@ -454,15 +454,14 @@ mp.add_hook("on_load", 10, function () msg.verbose("Playlist with single entry detected.") add_single_video(json.entries[1]) else - - local playlist = "#EXTM3U\n" + local playlist = {"#EXTM3U"} for i, entry in pairs(json.entries) do local site = entry.url local title = entry.title if not (title == nil) then title = string.gsub(title, '%s+', ' ') - playlist = playlist .. "#EXTINF:0," .. title .. "\n" + table.insert(playlist, "#EXTINF:0," .. title) end -- 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 site = "ytdl://" .. site end - playlist = playlist .. site .. "\n" + table.insert(playlist, site) end - mp.set_property("stream-open-filename", "memory://" .. playlist) + mp.set_property("stream-open-filename", "memory://" .. table.concat(playlist, "\n")) end else -- probably a video -- cgit v1.2.3