From cbb8f534b064f144820435148e516978de08cb30 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 11 May 2021 22:21:46 +0200 Subject: ytdl_hook: expose some JSON fields as tags Shows uploader, channel, description fields. This works only if the media media is constructed as EDL (for youtube it usually does this), and if the all_formats option is not set to true (does anyone even use it?). The former usually happens because youtube serves audio and video separately, though it will not for live HLS/DASH. The latter uses delayed media opening, which breaks the global_tags mechanism (see previous commit). --- player/lua/ytdl_hook.lua | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/player/lua/ytdl_hook.lua b/player/lua/ytdl_hook.lua index 586d4ea874..2c728455b8 100644 --- a/player/lua/ytdl_hook.lua +++ b/player/lua/ytdl_hook.lua @@ -38,6 +38,16 @@ function iif(cond, if_true, if_false) return if_false end +-- youtube-dl JSON name to mpv tag name +local tag_list = { + ["uploader"] = "uploader", + ["channel_url"] = "channel_url", + -- these titles tend to be a bit too long, so hide them on the terminal + -- (default --display-tags does not include this name) + ["description"] = "ytdl_description", + -- "title" is handled by force-media-title +} + local safe_protos = Set { "http", "https", "ftp", "ftps", "rtmp", "rtmps", "rtmpe", "rtmpt", "rtmpts", "rtmpte", @@ -341,6 +351,20 @@ local function as_integer(v, def) return def end +local function tags_to_edl(json) + local tags = {} + for json_name, mp_name in pairs(tag_list) do + local v = json[json_name] + if v then + tags[#tags + 1] = mp_name .. "=" .. edl_escape(tostring(v)) + end + end + if #tags == 0 then + return nil + end + return "!global_tags," .. table.concat(tags, ",") +end + -- Convert a format list from youtube-dl to an EDL URL, or plain URL. -- json: full json blob by youtube-dl -- formats: format list by youtube-dl @@ -475,6 +499,11 @@ local function formats_to_edl(json, formats, use_all_formats) if #streams == 1 and single_url then res.url = single_url elseif #streams > 0 then + local tags = tags_to_edl(json) + if tags then + -- not a stream; just for the sake of concatenating the EDL string + streams[#streams + 1] = tags + end res.url = "edl://" .. table.concat(streams, ";") else return nil -- cgit v1.2.3