diff options
author | Eva <evauwu@riseup.net> | 2020-06-21 03:30:59 +0200 |
---|---|---|
committer | Dudemanguy <random342@airmail.cc> | 2023-10-30 16:46:17 +0000 |
commit | a5b0eceeba2051d593e0fee46c17c86c4d71a0af (patch) | |
tree | 1299d9a1e20db244e50cbb73c4040ebdf45305e5 /player/lua/ytdl_hook.lua | |
parent | 040622f6b7a98204cf84d81066e64a5b39867c87 (diff) | |
download | mpv-a5b0eceeba2051d593e0fee46c17c86c4d71a0af.tar.bz2 mpv-a5b0eceeba2051d593e0fee46c17c86c4d71a0af.tar.xz |
ytdl_hook: support thumbnails
Similar to "write-sub=", adding "write-thumbnail=" to raw-options will add the highest resolution thumbnail as a video track.
Closes #7041
Diffstat (limited to 'player/lua/ytdl_hook.lua')
-rw-r--r-- | player/lua/ytdl_hook.lua | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/player/lua/ytdl_hook.lua b/player/lua/ytdl_hook.lua index f3e4fda6ad..25bc970d66 100644 --- a/player/lua/ytdl_hook.lua +++ b/player/lua/ytdl_hook.lua @@ -616,7 +616,7 @@ local function formats_to_edl(json, formats, use_all_formats) return res end -local function add_single_video(json) +local function add_single_video(json, thumbnail, allthumbs) local streamurl = "" local format_info = "" local max_bitrate = 0 @@ -754,6 +754,32 @@ local function add_single_video(json) end end + -- add thumbnails + if (thumbnail == true) and not (json.thumbnails == nil) then + local thumb = nil + local thumb_height = -1 + + for _, thumb_info in ipairs(json.thumbnails) do + if not (thumb_info.url == nil) then + if (allthumbs == true) then + msg.verbose("adding thumbnail") + mp.commandv("video-add", thumb_info.url, "auto") + thumb_height = 0 + elseif ((thumb_info.height or 0) > thumb_height) then + thumb = thumb_info.url + thumb_height = thumb_info.height or 0 + end + end + end + + if not (thumb == nil) then + msg.verbose("adding thumbnail") + mp.commandv("video-add", thumb, "auto") + elseif (thumb_height == -1) then + msg.verbose("No thumbnail url") + end + end + -- add chapters if json.chapters then msg.debug("Adding pre-parsed chapters") @@ -859,6 +885,8 @@ function run_ytdl_hook(url) local format = mp.get_property("options/ytdl-format") local raw_options = mp.get_property_native("options/ytdl-raw-options") local allsubs = true + local thumbnail = false + local allthumbs = false local proxy = nil local use_playlist = false @@ -890,6 +918,11 @@ function run_ytdl_hook(url) end if (param == "sub-lang" or param == "sub-langs" or param == "srt-lang") and (arg ~= "") then allsubs = false + elseif (param == "write-thumbnail") then + thumbnail = true + elseif (param == "write-all-thumbnails") then + thumbnail = true + allthumbs = true elseif (param == "proxy") and (arg ~= "") then proxy = arg elseif (param == "yes-playlist") then @@ -1061,7 +1094,7 @@ function run_ytdl_hook(url) elseif self_redirecting_url and #json.entries == 1 then msg.verbose("Playlist with single entry detected.") - add_single_video(json.entries[1]) + add_single_video(json.entries[1], thumbnail, allthumbs) else local playlist_index = parse_yt_playlist(url, json) local playlist = {"#EXTM3U"} @@ -1115,7 +1148,7 @@ function run_ytdl_hook(url) end else -- probably a video - add_single_video(json) + add_single_video(json, thumbnail, allthumbs) end msg.debug('script running time: '..os.clock()-start_time..' seconds') end |