0
0
mirror of https://github.com/mpv-player/mpv.git synced 2024-09-20 20:03:10 +02:00
Commit Graph

108 Commits

Author SHA1 Message Date
wm4
43c13e5ea2 ytdl_hook: add a way to not pass --format to the command line
Might be helpful for... whatever.
2020-02-19 16:31:04 +01:00
wm4
29e15e6248 ytdl_hook.lua: delay load subtitles
Uses the infrastructure added in the previous commits. This is
admittedly a bit weird (constructing EDL URLs and such). But on the
other hand, adding this as "first class" mechanism directly to the
sub-add command or so would increase weirdness and unexpected behavior
in other places, or at least that's what I think.

To reduce confusion, this goes through the effort of mapping the webvtt
codec, so it's shown "properly" in the codec list. Without this it would
show "null", but still work. In particular, any non-webvtt codecs should
still work if libavcodec supports it.

Not sure if I should remove the --all-subs hack from the code. But I
guess it does no harm.
2020-02-15 18:30:42 +01:00
wm4
a935109235 ytdl_hook: --vid=no should not ignore --ytdl-format in config file
Do this only if ytdl-format was not set at all.

Fixes: #6636
2019-10-24 13:52:09 +02:00
Nicolas F
06765e6ac9 ytdl_hook: check youtube-dl version if it breaks
Some failures by youtube-dl prompt the user to submit a bug report.
If such a failure occurs, we can compare youtube-dl's version to the
current calendar date to see how old it is. We don't make this check
on every youtube-dl failure, as failing to extract an URL is quite
common, and waiting for a second blocking python interpreter startup
for every such case would be a bit unpleasant.

Here the assumption is made that any youtube-dl version older than
3 months is probably severely out of date. Users will be warned about
this.

We also output the trimmed stderr of youtube-dl with msg.error, as this
appeared to have been the behaviour of utils.subprocess without stderr
capturing. Since this uses mp.command_native now, we'll have to do this
ourselves where appropriate.
2019-10-13 19:08:46 +02:00
Niklas Haas
e8f32a92f8 player: update for --video-aspect deprecation
We had some dangling references to this option.
2019-10-04 22:41:31 +02:00
wm4
a09396ee60 demux_edl, cue, mkv: clean up timeline stuff slightly
Remove the singly linked list hack, replace it with a slightly more
proper data structure. This probably gets rid of a few minor bugs along
the way, caused by the awkward nonsensical sharing/duplication of some
fields.

Another change (because I'm touching everything related to timeline
anyway) is that I'm removing the special semantics for parts[num_parts].
This is now strictly out of bounds, and instead of using the start time
of the next/beyond-last part, there is an end time field now.

Unfortunately, this also requires touching the code for cue and mkv
ordered chapters. From some superficial testing, they still seem to
mostly work.

One observable change is that the "no_chapters" header is per-stream
now, which is arguably more correct, and getting the old behavior would
require adding code to handle it as special-case, so just adjust
ytdl_hook.lua to the new behavior.
2019-09-19 20:37:04 +02:00
wm4
6efcde06e3 ytdl_hook: use no_clip for separate audio streams
I noticed that some ytdl streams have a start time other than 0. There's
currently no mechanism inside of the EDL stuff that determines this
start time correctly, so it can happen that if the start time is high,
demux_timeline.c tries to clip off the entire video and audio, resulting
in failure of playback.

As a counter measure, use the no_clip header, which entirely disables
clipping against time ranges in demux_timeline.c. (It's basically a
hack.)
2019-09-19 20:37:04 +02:00
wm4
d23336089c ytdl_hook: fix pseudo-DASH if no init fragment is present
Init fragments are not a necessity for DASH, but this code assumed so.
Maybe the check was to prevent worse. But using normal EDL here leads to
very shitty behavior where it tries to open hundreds or thousands of
fragments, each with its own demuxer and HTTP connection. (This behavior
is fine for normal uses of EDLs, but completely unacceptable when
emulating fragmented streaming protocols. I'm not sure why the normal
EDL code is needed here, but I think someone claimed some obscure sites
just need it.)

This happens in the same situation as the one described in the previous
commit.
2019-09-19 20:37:04 +02:00
wm4
80d2016075 ytdl_hook: audio can use fragmented DASH too
Otherwise we'd just use the base URL as media URL, which would fail with
a 404 error.

Not sure if there's a deeper reason why the audio path was explicitly
different from the video one. But this actually works now for a video
that returned fragmented DASH audio with the default format selection.
(This affects streams on that well known site of a big evil Silicon
Valley company. Typically happens after live stream gets converted to a
normal video, though after some time passes, this fragmented version is
deleted, and replaced by a non-fragmented one. I've observed this
several times and this seems to be the "normal" behavior.)
2019-09-19 20:37:04 +02:00
wm4
27a09b42ed ytdl_hook: disable EDL-generated useless chapters when merging streams
(Yes, a bit odd how this header is needed only for the first stream.)
2019-09-19 20:37:04 +02:00
wm4
f485e34fc9 ytdl_hook: merge separate audio tracks via EDL
This merges separate audio and video tracks into one virtual stream,
which helps the mpv caching layer. See previous EDL commit for details.

It's apparently active for most of evil Silicon Valley giant's streaming
videos.

Initial tests seem to work fine, except it happens pretty often that
playback goes into buffering immediately even when seeking within a
cached range, because there is not enough forward cache data yet to
fully restart playback. (Or something like this.)

The audio stream title used to be derived from track.format_note; this
commit stops doing so. It seemed pointless anyway. If really necessary,
it could be restored by adding new EDL headers.

Note that we explicitly don't do this with subtitle tracks. Subtitle
tracks still have a chance with on-demand loading or loading in the
background while video is already playing; merging them with EDL would
prevent this. Currently, subtitles are still added in a "blocking"
manner, but in theory this could be loosened. For example, the Lua API
already provides a way to run processes asynchronously, which could be
used to add subtitles during playback. EDL will probably be never
flexible enough to provide this. Also, subtitles are downloaded at
once, rather than streamed like audio and video.

Still missing: disabling EDL's pointless chapter generation, and
propagating download speed statistics through the EDL wrapper.
2019-09-19 20:37:04 +02:00
wm4
d2ef2f98a8 loadfile, ytdl_hook: don't reject EDL-resolved URLs through playlist
The ytdl wrapper can resolve web links to playlists. This playlist is
passed as big memory:// blob, and will contain further quite normal web
links. When playback of one of these playlist entries starts, ytdl is
called again and will resolve the web link to a media URL again.

This didn't work if playlist entries resolved to EDL URLs. Playback was
rejected with a "potentially unsafe URL from playlist" error. This was
completely weird and unexpected: using the playlist entry directly on
the command line worked fine, and there isn't a reason why it should be
different for a playlist entry (both are resolved by the ytdl wrapper
anyway). Also, if the only EDL URL was added via audio-add or sub-add,
the URL was accessed successfully.

The reason this happened is because the playlist entries were marked as
STREAM_SAFE_ONLY, and edl:// is not marked as "safe". Playlist entries
passed via command line directly are not marked, so resolving them to
EDL worked.

Fix this by making the ytdl hook set load-unsafe-playlists while the
playlist is parsed. (After the playlist is parsed, and before the first
playlist entry is played, file-local options are reset again.) Further,
extend the load-unsafe-playlists option so that the playlist entries are
not marked while the playlist is loaded.

Since playlist entries are already verified, this should change nothing
about the actual security situation.

There are now 2 locations which check load_unsafe_playlists. The old one
is a bit redundant now. In theory, the playlist loading code might not
be the only code which sets these flags, so keeping the old code is
somewhat justified (and in any case it doesn't hurt to keep it).

In general, the security concept sucks (and always did). I can for
example not answer the question whether you can "break" this mechanism
with various combinations of archives, EDL files, playlists files,
compromised sites, and so on. You probably can, and I'm fully aware that
it's probably possible, so don't blame me.
2019-09-19 20:37:04 +02:00
Ricardo Constantino
9dbab9661c ytdl_hook: fix audio not being picked up for some sites 2018-09-26 22:41:04 +02:00
Ricardo Constantino
d8131568c8
ytdl_hook: always load ytdl:// links with ytdl_hook first
Suggested in IRC by sfan5.
2018-08-17 19:28:27 +01:00
Ricardo Constantino
11289d5238 ytdl_hook: try to set video track first if available
Fixes `--ytdl-format="dash-fastly_skyfire-video-363357330+dash-fastly_skyfire_sep-audio-363357330" https://vimeo.com/108650530`

This happened because the video track also had audio available and after
adding it expecting an audio-only track, there were no more tracks with video.
2018-05-03 22:03:48 +03:00
wm4
c647516278 ytdl_hook: don't log error when loading is aborted 2018-04-15 21:07:13 +03:00
Ricardo Constantino
f670c64e59
ytdl_hook: add ytdl:// prefix again for non-youtube playlists
Only youtube playlists return ID-only urls. Other extractors may
return "<extractor>:<ID>" so those still need the ytdl:// prefix.

Reproduced with
http://www.cbc.ca/burdenoftruth/videos/trailers-promos/burden-of-truth-returns
2018-02-11 23:27:37 -08:00
Ricardo Constantino
57228b6581
ytdl_hook: add script opt for using manifest URLs
Disable by default.
This feature was added in 7eb342757, which allowed stream selection
in runtime. Problem with this atm is that FFmpeg will try to demux
every first packet of every track leading to noticeable delay opening
the URL.

This option can be changed to enabled by default or removed when
HLS/DASH demuxers are improved upstream.
2018-02-11 23:27:37 -08:00
Ricardo Constantino
664e8fe66a
ytdl_hook: parse youtube playlist urls to set start index
Still needs `--ytdl-raw-option=yes-playlist=` because this only
works for youtube.

This was requested in a few issues:
https://github.com/mpv-player/mpv/issues/1400
https://github.com/mpv-player/mpv/issues/2592
https://github.com/mpv-player/mpv/issues/3024

For #1400 to be completely implemented would need ytdl_hook to
re-request the same playlist with the last video's ID for the mix to
continue indefinitely which would probably too hackish to work reliably.
2018-02-11 23:27:36 -08:00
Ricardo Constantino
976daf1942
ytdl_hook: exit early, save an indentation level 2018-02-11 23:27:36 -08:00
Ricardo Constantino
bf3549839e
ytdl_hook: various nit
Remove obsolete comment about FFmpeg ignoring non-http proxies
which was repeated in ytdl_hook before the feature was added.

Remove unnecessary conditions for not nil. Lua tables will always
return nil for non-existent keys.
2018-02-11 23:27:36 -08:00
Ricardo Constantino
3e71eb8676
ytdl_hook: whitelist subtitle URLs as well
This was overlooked when doing the whitelisting for video and audio to
fix #5456.
2018-02-11 23:25:56 -08:00
Ricardo Constantino
268431c858
ytdl_hook: use fallback if there's no demuxer-lavf-list prop
This is important if backporting by grabbing the latest version of
the script without backporting the commit that added the property:

828bd2963c
2018-02-11 23:25:05 -08:00
Ricardo Constantino
eaa97daf65
ytdl_hook: pass http proxy to ffmpeg
FFmpeg only suppports http proxies and ignores it if
the resulting url is https. Also, no SOCKS.
Use it like `--ytdl-raw-options=proxy=[http://127.0.0.1:3128]` so
it doesn't confuse mpv because of the colons.

You need to pass it as an option because youtube-dl doesn't give
us the proxy.

Or just set `http_proxy` environment variable as recommended before.

Added example using -append, which doesn't need escaping.
2018-01-30 12:19:34 +00:00
Ricardo Constantino
93403b13a4
ytdl_hook: pre-append id-only playlist items with shortened youtube URL 2018-01-29 21:39:12 +00:00
Ricardo Constantino
2a0f9fc158
ytdl_hook: whitelist segmented DASH and HLS for the manifests code
Close #5453
2018-01-27 12:24:40 +00:00
Ricardo Constantino
7eb3427573
ytdl_hook: prefer hls/dash manifest if available
This makes all the video/audio variants available for selection.

Might break with non-hls/dash, or even with dash if FFmpeg wasn't
compiled with the demuxer.
2018-01-26 20:57:10 +00:00
Ricardo Constantino
ce42a96533
ytdl_hook: fix safe url checking with EDL urls 2018-01-26 18:54:17 +00:00
Ricardo Constantino
f8263e82cc
ytdl_hook: move url_is_safe earlier in code
lua isn't javascript.
2018-01-26 11:29:55 +00:00
Ricardo Constantino
e6e6b0dcc7
ytdl_hook: whitelist protocols from urls retrieved from youtube-dl
Not very clean since there's a lot of potential unsafe urls that youtube-dl
can give us, depending on whether it's a single url, split tracks,
playlists, segmented dash, etc.
2018-01-26 01:47:43 +00:00
Ricardo Constantino
86004909ac
ytdl_hook: support native dash demuxer, if present
Uses track tbr instead of track disposition id for dash selection

Works just as expected because youtube-dl also takes tbr from the manifests.
2018-01-15 11:20:02 +00:00
Ricardo Constantino
b478d2b1ce
ytdl_hook: look for the right ytdl binary according to system
package.config is available in 5.1, 5.2, 5.3 and luajit, so should be fine.
The first character is the path separator, so it's '\' on windows and '/'
on *nix.

This should also prevent cases where users download the wrong binary.
2018-01-12 18:17:37 +00:00
Ricardo Constantino
2d6fdccb92
ytdl_hook: be more informative when youtube-dl fails 2018-01-12 01:52:37 +00:00
Ricardo Constantino
154ff98128
ytdl_hook: don't try to use webpage_url if non-existent 2018-01-11 00:16:53 +00:00
Ricardo Constantino
b62066433d
ytdl_hook: actually use the script option from 87d3af6 2018-01-07 16:15:47 +00:00
Ricardo Constantino
87d3af6f19
ytdl_hook: add script option to revert to trying youtube-dl first
Should only make a difference if most of the URLs you open need
youtube-dl parsing.
2018-01-07 15:56:55 +00:00
Ricardo Constantino
cf8855cd2e
ytdl_hook: check for possible infinite loop in playlist generation 2018-01-06 18:43:46 +00:00
Ricardo Constantino
442ff93626
ytdl_hook: add additional check for comedycentral urls
If this breaks another site again, remove this whole if and just leave them as
separate playlist items.

Close #5364
2018-01-06 18:22:08 +00:00
Ricardo Constantino
cf411a9489
ytdl_hook: update obsolete warning about retrying URL if failed 2018-01-04 20:35:43 +00:00
Ricardo Constantino
89f81da481
player: add on_load_fail hook 2018-01-02 16:01:22 +00:00
Ricardo Constantino
0da5688c84
ytdl_hook: fix single-entry playlists
Close #5313
2018-01-02 14:28:03 +00:00
Ricardo Constantino
b1b03da137 ytdl_hook: use table concat for playlist building
Faster and more efficient than string concat with large playlists.
2017-12-24 14:13:57 -07:00
Ricardo Constantino
1623430b20 ytdl_hook: don't preappend ytdl:// to non-youtube links in playlists
Close #5003
2017-12-24 14:13:57 -07:00
Kevin Mitchell
985e83e217 Revert "ytdl: handle HLS with FFmpeg"
Apparently, this breaks youtube live and possibly other things.

This reverts commit 06519aae58.
2017-12-07 00:46:27 -08:00
wm4
06519aae58 ytdl: handle HLS with FFmpeg
Using youtube-dl's metadata ends up with stupid things like missing
variant streams, or missing audio streams entirely.
2017-12-06 23:59:59 -08:00
Ricardo Constantino
d280b3db93
ytdl_hook: resolve relative paths when joining segment urls
FFmpeg/mpv don't do it automatically.
See #4827
2017-09-03 13:42:51 +01:00
Ricardo Constantino
2b83f7e391
ytdl_hook: support fragments with relative paths
Unbreaks segmented DASH with the change in
https://github.com/rg3/youtube-dl/commit/1141e9104 which made each
segment URL only use relative path from fragment_base_url with a
different key.
2017-08-06 13:27:53 +01:00
Jagannathan Tiruvallur Eachambadi
46bfa3726f
ytdl_hook: add a header to support geo-bypass
youtube-dl supports bypassing some geographic restrictions by
setting X-Forwarded-For header when used with geo-bypass and
geo-bypass-country.
2017-07-16 13:20:17 +01:00
Ricardo Constantino
db60cbb80a
ytdl_hook: actually load the script-opts
Also, comma-separated list doesn't actually work, even quote-surrounded.
Switch to using | instead.
2017-07-11 23:42:22 +01:00
Ricardo Constantino
042e98f4c9
ytdl_hook: add option to exclude URLs from being parsed
This is more of a niche usecase than --ytdl-format and --ytdl-raw-options,
so a simple script option should be enough.

Either create lua-settings/ytdl_hook.conf with
'exclude=example.com,sub.example.com' option or
"--script-opts=ytdl_hook-exclude=example.com,sub.example.com"
2017-07-11 14:18:29 +01:00