From 9f6cca624f8e58dc8716975372ff1c8a4ac98d0e Mon Sep 17 00:00:00 2001 From: Earnestly Date: Tue, 15 Oct 2024 09:52:43 +0100 Subject: [PATCH] ytdl_hook.lua: track playlist metadata Add support for tracking playlist_title and playlist_id metadata corresponding to a given playlist url and the entries associated with it. This allows the inclusion of ytdl_playlist_title and ytdl_playlist_id in the metadata property for single videos which have a corresponding playlist-path property. This commit also resolves yt-dlp/yt-dlp#11234 --- player/lua/ytdl_hook.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/player/lua/ytdl_hook.lua b/player/lua/ytdl_hook.lua index 7e31177ef7443..77ad5394af78a 100644 --- a/player/lua/ytdl_hook.lua +++ b/player/lua/ytdl_hook.lua @@ -27,6 +27,7 @@ end) local chapter_list = {} local playlist_cookies = {} +local playlist_metadata = {} local function Set (t) local set = {} @@ -1079,6 +1080,11 @@ local function run_ytdl_hook(url) return end + playlist_metadata[url] = { + playlist_title = json["title"], + playlist_id = json["id"] + } + local self_redirecting_url = json.entries[1]["_type"] ~= "url_transparent" and json.entries[1]["webpage_url"] and @@ -1193,6 +1199,12 @@ local function run_ytdl_hook(url) end else -- probably a video + -- add playlist metadata if any belongs to the current video + local metadata = playlist_metadata[mp.get_property("playlist-path")] or {} + for key, value in pairs(metadata) do + json[key] = value + end + add_single_video(json) end msg.debug('script running time: '..os.clock()-start_time..' seconds')