Skip to content

Commit

Permalink
ytdl_hook.lua: track playlist metadata
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Earnestly authored and kasper93 committed Oct 26, 2024
1 parent 9af491f commit 9f6cca6
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 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,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
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit 9f6cca6

Please sign in to comment.