Skip to content

Commit

Permalink
ytdl_hook.lua: support playlist_title
Browse files Browse the repository at this point in the history
Adds support for capturing the playlist_title from playlists and making
it available to subsequent instances of run_ytdl_hook()

This enables the inclusion of ytdl_playlist_title in the metadata
property for single videos which resulted from a playlist entry.

This may also be resolved with yt-dlp/yt-dlp#11234
  • Loading branch information
Earnestly authored and Earnestly committed Oct 25, 2024
1 parent 187fffd commit 52a75ef
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions player/lua/ytdl_hook.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ end)

local chapter_list = {}
local playlist_cookies = {}
local playlist_metadata = {}

local function Set (t)
local set = {}
Expand Down Expand Up @@ -1079,6 +1080,13 @@ local function run_ytdl_hook(url)
return
end

-- capture the playlist metadata and associate it with all entries in
-- the playlist
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
Expand Down Expand Up @@ -1193,6 +1201,12 @@ local function run_ytdl_hook(url)
end

else -- probably a video
-- restore playlist metadata if any belong to the current url
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')
Expand Down

0 comments on commit 52a75ef

Please sign in to comment.