0
0
mirror of https://github.com/mpv-player/mpv.git synced 2024-09-20 12:02:23 +02:00

ytdl_hook: add thumbnail option

Opening speed could be improved with the "async" prefix, but then the
tracks would be out of order.
This commit is contained in:
Christoph Heinrich 2023-10-24 00:51:29 +02:00 committed by Dudemanguy
parent a5b0eceeba
commit 045f4a7315
2 changed files with 13 additions and 12 deletions

View File

@ -943,6 +943,13 @@ Program Behavior
``all_formats`` is set to 'no', and the stream selection as done by ``all_formats`` is set to 'no', and the stream selection as done by
youtube-dl (via ``--ytdl-format``) is used. youtube-dl (via ``--ytdl-format``) is used.
``thumbnails=<all|best|none>``
Add thumbnails as video tracks (default: none).
Thumbnails get downloaded when they are added as tracks, so 'all' can
have a noticable impact on how long it takes to open the video when
there are a lot of thumbnails.
``use_manifests=<yes|no>`` ``use_manifests=<yes|no>``
Make mpv use the master manifest URL for formats like HLS and DASH, Make mpv use the master manifest URL for formats like HLS and DASH,
if available, allowing for video/audio selection in runtime (default: if available, allowing for video/audio selection in runtime (default:

View File

@ -8,6 +8,7 @@ local o = {
use_manifests = false, use_manifests = false,
all_formats = false, all_formats = false,
force_all_formats = true, force_all_formats = true,
thumbnails = "none",
ytdl_path = "", ytdl_path = "",
} }
@ -616,7 +617,7 @@ local function formats_to_edl(json, formats, use_all_formats)
return res return res
end end
local function add_single_video(json, thumbnail, allthumbs) local function add_single_video(json)
local streamurl = "" local streamurl = ""
local format_info = "" local format_info = ""
local max_bitrate = 0 local max_bitrate = 0
@ -755,13 +756,13 @@ local function add_single_video(json, thumbnail, allthumbs)
end end
-- add thumbnails -- add thumbnails
if (thumbnail == true) and not (json.thumbnails == nil) then if (o.thumbnails == 'all' or o.thumbnails == 'best') and not (json.thumbnails == nil) then
local thumb = nil local thumb = nil
local thumb_height = -1 local thumb_height = -1
for _, thumb_info in ipairs(json.thumbnails) do for _, thumb_info in ipairs(json.thumbnails) do
if not (thumb_info.url == nil) then if not (thumb_info.url == nil) then
if (allthumbs == true) then if (o.thumbnails == 'all') then
msg.verbose("adding thumbnail") msg.verbose("adding thumbnail")
mp.commandv("video-add", thumb_info.url, "auto") mp.commandv("video-add", thumb_info.url, "auto")
thumb_height = 0 thumb_height = 0
@ -885,8 +886,6 @@ function run_ytdl_hook(url)
local format = mp.get_property("options/ytdl-format") local format = mp.get_property("options/ytdl-format")
local raw_options = mp.get_property_native("options/ytdl-raw-options") local raw_options = mp.get_property_native("options/ytdl-raw-options")
local allsubs = true local allsubs = true
local thumbnail = false
local allthumbs = false
local proxy = nil local proxy = nil
local use_playlist = false local use_playlist = false
@ -918,11 +917,6 @@ function run_ytdl_hook(url)
end end
if (param == "sub-lang" or param == "sub-langs" or param == "srt-lang") and (arg ~= "") then if (param == "sub-lang" or param == "sub-langs" or param == "srt-lang") and (arg ~= "") then
allsubs = false 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 elseif (param == "proxy") and (arg ~= "") then
proxy = arg proxy = arg
elseif (param == "yes-playlist") then elseif (param == "yes-playlist") then
@ -1094,7 +1088,7 @@ function run_ytdl_hook(url)
elseif self_redirecting_url and #json.entries == 1 then elseif self_redirecting_url and #json.entries == 1 then
msg.verbose("Playlist with single entry detected.") msg.verbose("Playlist with single entry detected.")
add_single_video(json.entries[1], thumbnail, allthumbs) add_single_video(json.entries[1])
else else
local playlist_index = parse_yt_playlist(url, json) local playlist_index = parse_yt_playlist(url, json)
local playlist = {"#EXTM3U"} local playlist = {"#EXTM3U"}
@ -1148,7 +1142,7 @@ function run_ytdl_hook(url)
end end
else -- probably a video else -- probably a video
add_single_video(json, thumbnail, allthumbs) add_single_video(json)
end end
msg.debug('script running time: '..os.clock()-start_time..' seconds') msg.debug('script running time: '..os.clock()-start_time..' seconds')
end end