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 62826a9
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions player/lua/ytdl_hook.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ end)
local chapter_list = {}
local playlist_cookies = {}

local playlist = {
metadata = {},
path = {}
}

local function Set (t)
local set = {}
for _, v in pairs(t) do set[v] = true end
Expand Down Expand Up @@ -1079,6 +1084,12 @@ local function run_ytdl_hook(url)
return
end

-- capture the playlist metadata and associate it with all entries in
-- the playlist
playlist.metadata["playlist_title"] = json["title"]
playlist.metadata["playlist_id"] = json["id"]
playlist.path[json.original_url] = playlist.metadata

local self_redirecting_url =
json.entries[1]["_type"] ~= "url_transparent" and
json.entries[1]["webpage_url"] and
Expand Down Expand Up @@ -1193,6 +1204,15 @@ local function run_ytdl_hook(url)
end

else -- probably a video
-- restore playlist metadata if any belong to the current url
local metadata = playlist.path[mp.get_property("playlist-path")] or {}

for key, value in pairs(metadata) do
if value then
json[key] = value
end
end

add_single_video(json)
end
msg.debug('script running time: '..os.clock()-start_time..' seconds')
Expand Down

0 comments on commit 62826a9

Please sign in to comment.