210 Commits

Author SHA1 Message Date
Julius Bairaktaris fffe7a23a8 ytdl_hook: map vp09 codec strings to vp9
yt-dlp reports VP9 in HLS formats with the RFC 6381 codec string, such
as vp09.00.40.08, which matches no codec_map entry. Such tracks get
codec=null in the EDL, and selecting one first initializes an unrelated
decoder. Map vp09.* to vp9.

Signed-off-by: Julius Bairaktaris <julius@bairaktaris.de>
2026-10-18 03:29:03 +02:00
Kacper Michajłow b43bb95d4c ytdl_hook: default cookies without a Domain to the host of origin
yt-dlp builds the cookies field of each format for the url of that
format and leaves out the Domain attribute when the cookie has an empty
domain in its jar. Cookies imported from a browser can have one, and
the jar then matches them against every url.

Store every cookie the same way and default its domain to the host of
the url the cookies were built for, which makes it a host-only cookie.
The port and userinfo are stripped, since neither libcurl nor lavf
matches a domain that includes them. A cookie that still has no domain
because the url has no http host is dropped.

This includes some cleanup of leftover implementation details of old
lavf cookie option merge, removed in 6017d1fd1c.

Fixes: #18506
2026-10-16 20:05:44 +02:00
Kacper Michajłow a98d3ede9f ytdl_hook: pass a default format again
This is a revert of a6f3236c3a with bestvideo* added. Dropping the
default format was meant to follow yt-dlp's `bv*+ba/b`, but yt-dlp only
selects that when it finds ffmpeg to merge the tracks. Otherwise it
falls back to `best`, a muxed format, which is most of the time is not
optimal selection.
2026-09-13 15:37:23 +02:00
Kacper Michajłow 70894ae039 ytdl_hook: defer loading until the formats become available
yt-dlp can provide time at which formats become available
`available_at`. Sleep until the requested time.

Fixes: #18192
2026-06-27 01:10:41 +02:00
Kacper Michajłow 2d5dfb343a ytdl_hook: use native http-proxy option instead of lavf option
Fixes: #18042
2026-06-18 05:27:17 +02:00
Kacper Michajłow db73857997 ytdl_hook.lua: map ass/srt subtitles 2026-05-21 21:47:45 +02:00
Kacper Michajłow 0ae2214a7a ytdl_hook.lua: use the new curl-max-request-size option if needed
This is for stream_curl.
2026-05-16 18:20:42 +02:00
Kacper Michajłow 6017d1fd1c ytdl_hook.lua: write cookies via cookies-file instead of stream-lavf-o
stream-lavf-o[cookies] only feeds the lavf stream backend. Instead of
side-loading it, use core `--cookies-file` option.
2026-05-16 18:20:42 +02:00
Kacper Michajłow 4d944b2fad ytdl_hook.lua: remove track selection hack
This breaks HLS bitrate selection, as it uses track metadata in place of
HLS bitrate, which are most of the time different things.
2026-05-07 18:59:08 +02:00
Guido Cella 0a0c63d3e9 ytdl_hook.lua: convert metadata values to string
Fixes https://github.com/mpv-player/mpv/pull/17805#issuecomment-4340090625
2026-04-29 11:32:19 +02:00
Guido Cella 98a6960a3d ytdl_hook.lua: remove outdated comment 2026-04-23 22:06:47 +02:00
Guido Cella b3c46456c5 ytdl_hook.lua: set metadata with use_manifests=yes
With use_manifests=yes EDL is not used so metadata never gets set
through the tags mechanism. Thankfully the metadata property was
recently made writable so use that instead.

The existing metadata variable is inlined to fix linting.

Fixes https://github.com/mpv-player/mpv/pull/17761#issuecomment-4306070651
2026-04-23 22:06:47 +02:00
Guido Cella 6b524c4f0e ytdl_hook.lua: default to all_formats=yes
93fe7a5526 fixed the only problem with all_formats=yes, so make it the
default to allow changing tracks of ytdl_hook URLs at runtime without
re-invoking yt-dlp.

Closes #16872.
2026-04-21 22:50:12 +02:00
Guido Cella 021b5ccf23 ytdl_hook.lua: set the title in metadata
93fe7a5526 made global_tags work with all_formats=yes, so do like
suggested in 8ea7aa5471 and set the title via tags.

This makes available in ${metadata/title}, even if you set
--force-media-title separately.

--force-media-title is also set when self_redirecting_url is true, but
tags seem not to be set in this case and I don't know where to find such
videos to test. It was originally added to close #5313, but the URL
linked there no longer loads.
2026-04-17 19:56:06 +02:00
Guido Cella f4dcd295cf demux_edl: support global_tags with delay_open
The delay_open mechanism used by
--script-opt=ytdl_hook-all_formats=yes breaks setting metadata with
global_tags because tl->track_layout is NULL. See adcf51dccd cbb8f534b0
8ea7aa5471.

Fix this by applying tags to the EDL timeline in this case.

Tags must still be applied to tl->track_layout when available for them
to work with local EDL files.
2026-04-17 19:24:47 +02:00
Kacper Michajłow 1068d4adb1 ytdl_hook.lua: tag variants with program_id 2026-04-17 18:30:43 +02:00
nanahi 7ace42f505 ytdl_hook.lua: use _name key for mp.command_native 2026-04-06 18:33:20 +02:00
Nicolas F f28cea85c1 ytdl_hook.lua: use the new request_size AVOption when needed
Some sites throttle requests, but throttling can be avoided with many
small range requests. yt-dlp implements a "http_chunk_size" key in its
-J output to inform us of the ideal size.

https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21703 has just been merged,
which allows use the http_chunk_size to greatly speed up how fast
YouTube videos get loaded into the cache by mpv.

Should the FFmpeg that mpv is built against lack the request_size
AVOption, then this will silently not do anything new, so no version
checks are needed.

Specifying multiple_requests=1 like suggested in
https://github.com/mpv-player/mpv/issues/8655#issuecomment-3872689494
does not seem necessary.

Fixes #8655.
Supersedes #15612.

Co-authored-by: Nicolas F <ovdev@fratti.ch>
2026-02-27 20:18:55 +01:00
Hubert Głuchowski 557e592511 ytdl_hook: recognize srv3 subtitle format if subrandr is present
This allows YouTube videos played directly from a URL to make use of
subrandr's SRV3 support if it is allowed by an overriden `sub-format`.
2025-12-23 07:01:29 +01:00
Guido Cella a58e9e596b Revert "ytdl_hook: add chapters by parsing video's description"
This reverts commit e9c43258b8.

yt-dlp implemented its own parsing to extract chapters from the
descriptions of videos without chapter markers in the player over 3
years ago in https://github.com/yt-dlp/yt-dlp/commit/0fe51254 (the PR is
even inspired by mpv). Actually it was present even earlier in
youtube-dl but was removed for unknown reasons in
https://github.com/ytdl-org/youtube-dl/commit/67299f23d8b1894120e875edf97440de87e22308.
So we can remove our parsing code, as it is dead code that never runs if
yt-dlp's JSON already contains chapters.

And it seems that such videos without chapter markers are rare or
non-existing by now anyway - we can't find any.
https://www.youtube.com/watch?v=1v_4dL8l8pQ is linked from the yt-dlp PR
with the above commit, but now yt-dlp returns the Key moments as
chapters, so it can't be used for testing.

Our parsing was actually worse than yt-dlp's, because #16085 added an
option to disable it to fix the misdetection reported in #16081, but
yt-dlp correctly returns no chapter for that video
(https://www.youtube.com/watch?v=1v_4dL8l8pQ). So this code branch was
only running for misdetections, and by removing it that option is not
needed.
2025-12-19 18:06:14 +01:00
Guido Cella acd3378c9b Revert "ytdl_hook: add option to extract chapters"
This reverts commit df1e71a7cc.

The next commit will make this unused since chapters will only be taken
from yt-dlp's JSON.
2025-12-19 18:06:14 +01:00
NotMithical 6269f4ffce ytdl_hook.lua: add support for VP9 profile 2 2025-09-02 21:42:14 +02:00
sfan5 80d2a6a7ed ytdl_hook.lua: don't crash if playlist entries don't have an usable URL
see #16717
2025-08-23 15:02:46 +02:00
sfan5 a6f3236c3a ytdl_hook.lua: don't pass any format to youtube-dl by default
yt-dlp changed its default format from `bv+ba/b` to `bv*+ba/b`, which we want to follow
since it fixes the behavior with some streaming sites.

The note that "sometimes youtube-dl returns a format that mpv cannot use" was added in
43c13e5ea2 but it's not clear what it refers to.

fixes #16388
2025-07-28 11:22:13 +02:00
sfan5 2168e3d82c ytdl_hook.lua: get rid of outdated youtube-dl hint
It has never worked for yt-dlp anyway and the relevant error messages
already tell people to update.
2025-07-28 11:22:13 +02:00
Kacper Michajłow 47bc7b2a07 ytdl_hook.lua: add support for HEVC 2025-06-10 17:52:25 +02:00
yumcookiez df1e71a7cc ytdl_hook: add option to extract chapters 2025-04-17 00:37:13 +02:00
Christoph Heinrich 958fee6895 ytdl_hook.lua: fix duplicated chapters
Sometimes when opening a YouTube video with chapters, the chapter-list
ended up having all the chapters twice, despite the json from yt-dlp only
containing them once. That must mean that sometimes add_single_video()
runs twice before the chapter_list table gets cleared in the
on_preloaded hook.

This can be avoided by replacing chapter_list with a new table before
adding entries to it.
2025-03-23 22:52:12 +01:00
Kacper Michajłow 6479dd13ce ytdl_hook.lua: fix boolean comparision
Make sure the `early` variable is boolean. The issue was that if url have
`ytdl://`, find() would return position `1`. This makes `early` also `1`.
And now we try to compare `early == load_fail`, which for `1 == true` is
false, while we expect it to be true. Make sure we compare booleans.

Fixes unnecessary hook processing when using ytdl:// protocol.
2025-03-05 11:13:35 +01:00
Guido Cella ca211b5b88 ytdl_hook.lua: fix start and end conditions
Fixes #13358, fixes fcc67cc6c1.
2025-01-10 14:06:16 +01:00
Kacper Michajłow 59d1dc43b9 various: fix typos 2025-01-04 15:59:49 +02:00
yk 96fad6a0fc ytdl_hook: pass empty proxy value
an empty value to a commandline option usually means that parameter does
not expect anything, but in case of `--proxy`, yt-dlp use an empty value to
disable proxy setting, the empty value need to be passed to `--proxy`
2024-12-17 22:26:46 +02:00
Earnestly 9f6cca624f ytdl_hook.lua: track playlist metadata
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
2024-10-26 19:59:26 +02:00
Crend King c8860fd816 ytdl_hook.lua: always specify --write-srt
Currently by default mpv sets --all-subs when calling yt-dlp for JSON
info. --all-subs is an option that simply expands to --sub-langs all
--write-subs. --write-subs is special that without it yt-dlp will no
longer extract any subtitle info.

mpv's yt-dlp hook has a logic that if user specify any sub-langs in
--ytdl-raw-options, it no longer uses --all-subs. Unfortunately, this
means unaware users will not get any subtitle any more until they study
the mpv internal code and add their own --write-subs.

This PR always specifies --write-srt, an alias of --write-subs, in the
hook, so users don't have to. The alias is used to maintain
compatibility with youtube-dl.

Fixes issue #14818
2024-10-10 18:28:41 +02:00
Guido Cella 6ed3781a3d ytdl_hook.lua: add include script-opt of URLs to try with ytdl first
By the default mpv tries opening URLs with ffmpeg first, and users who
don't configure try_ytdl_first get a slower startup for youtube URLs, on
top of yt-dlp already being slow.

Fix this by adding a script-opt of URL pattern to try with ytdl first.
Youtube and twitch are included by default.

Compared to the alternative of trying ytdl first by default and
excluding URLs with a media extension, this only works for the sites
explicitly included in the new option's value, but doesn't have false
positives on media URLs without an extension.
2024-10-09 01:08:31 +02:00
Guido Cella 92403a068c ytdl_hook.lua: lower case URLs for exclude matching 2024-10-09 01:08:31 +02:00
Maxim Biro ff47926d6a ytdl_hook: make path and json available to other scripts
It's useful for user scripts to be able to use the same ytdl binary that
ytdl_hook uses without having to replicate ytdl_hook's process of
searching for the ytdl binary.

Some user scripts might also find it useful to be able to access ytdl's
json output that the ytdl_hook already receives, sparing user scripts
from having to make a duplicate ytdl binary invocation to get the json
output.

Providing just the json output is not enough though, as ytdl doesn't communicate
errors though it -- if an error occurs, ytdl provides no json output and instead
prints to stderr. So without stderr, there is no way for user scripts to figure
out why ytdl has failed: no such username / video id, the channel is not live
yet, etc. Because of that, the entire result of the subprocess call is provided
to the user scripts, containing stdout (json), stderr, ytdl's exit code, etc.
2024-09-21 17:53:01 +02:00
llyyr 140196f297 ytdl_hook: fix typo (chapters -> chapter)
Fixes: ec966fb866
2024-09-19 13:55:58 +00:00
llyyr ec966fb866 ytdl_hook: add some more yt-dlp tags
These might be useful
2024-09-14 14:07:54 +02:00
Kacper Michajłow 0aebcbcc19 player/{command,scripting}: log subprocess execution
Useful for debugging purposes and sanity checks.

Remove unused function while at it.
2024-07-12 22:40:02 +02:00
Kacper Michajłow c0f5d2391b ytdl_hook.lua: fix hook triggering while it shouldn't
Fixes: acbd537dac
Fixes: #14522
2024-07-12 11:11:54 +02:00
Kacper Michajłow acbd537dac ytdl_hook.lua: allow changing try_ytdl_first during runtime
Check value in hook instead of hooking conditionally.
2024-07-07 02:32:48 +02:00
bashonly e78e2c73cf ytdl_hook: strip quotes from cookie values 2024-07-04 19:10:37 +00:00
Guido Cella 62868beffe ytdl_hook.lua: fix lint warnings 2024-06-02 22:26:00 +02:00
Kacper Michajłow e5e17c80ba ytdl_hook.lua: fix some lint warnings 2024-05-12 20:06:39 +02:00
Christoph Heinrich bcbd821fa9 ytdl_hook: fix mixed thumbnail.preference availability 2023-11-06 14:59:05 +00:00
Dudemanguy fcc67cc6c1 lua: remove a ton of unneeded parentheses
For whatever reason, some of the lua code (particularly the osc and
ytdl_hook) is full of a bunch of stuff like if (foo), if not (foo ==
nil), etc. The parenthesis aren't needed in lua and actually just look
weird since nobody actually writes lua like this. You can see most of
the other conditionals are written normally. So cleanup the style to
match when the parenthesis clearly aren't doing anything. Not directly
related, but also add some spaces on a few math operations while we're
at it.
2023-11-02 16:03:20 +00:00
Christoph Heinrich 612faed856 ytdl_hook: reverse thumbnail order
ytdl lists thumbnails in ascending order according to height/preference.
all_formats=yes adds formats from best to worst, so the same should also
be done for thumbnails.
2023-10-30 16:46:17 +00:00
Christoph Heinrich 21609953cc ytdl_hook: support the preference field of thumbnails
yt-dlp has a preference field for it's thumbnails, and not all of it's
listed thumbnails have fields with their dimensions.
Therefore prefere the preference field when available and fall back to
height if it's not.
2023-10-30 16:46:17 +00:00
Christoph Heinrich 045f4a7315 ytdl_hook: add thumbnail option
Opening speed could be improved with the "async" prefix, but then the
tracks would be out of order.
2023-10-30 16:46:17 +00:00