summaryrefslogtreecommitdiffstats
path: root/player
diff options
context:
space:
mode:
authorYour Name <you@example.com>2021-05-11 22:21:46 +0200
committerYour Name <you@example.com>2021-05-11 22:21:46 +0200
commitcbb8f534b064f144820435148e516978de08cb30 (patch)
tree12eb62285ca56922db51a3828d9b326a8ec0dd40 /player
parentadcf51dccdddc806c7da7172f4e162e69f392370 (diff)
downloadmpv-cbb8f534b064f144820435148e516978de08cb30.tar.bz2
mpv-cbb8f534b064f144820435148e516978de08cb30.tar.xz
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).
Diffstat (limited to 'player')
-rw-r--r--player/lua/ytdl_hook.lua29
1 files changed, 29 insertions, 0 deletions
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