summaryrefslogtreecommitdiffstats
path: root/player/lua/ytdl_hook.lua
Commit message (Collapse)AuthorAgeFilesLines
* ytdl_hook: fix mixed thumbnail.preference availabilityChristoph Heinrich2023-11-061-1/+1
|
* lua: remove a ton of unneeded parenthesesDudemanguy2023-11-021-40/+40
| | | | | | | | | | | 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.
* ytdl_hook: reverse thumbnail orderChristoph Heinrich2023-10-301-1/+2
| | | | | | 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.
* ytdl_hook: support the preference field of thumbnailsChristoph Heinrich2023-10-301-1/+4
| | | | | | | 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.
* ytdl_hook: add thumbnail optionChristoph Heinrich2023-10-301-12/+6
| | | | | Opening speed could be improved with the "async" prefix, but then the tracks would be out of order.
* ytdl_hook: support thumbnailsEva2023-10-301-3/+36
| | | | | | Similar to "write-sub=", adding "write-thumbnail=" to raw-options will add the highest resolution thumbnail as a video track. Closes #7041
* ytdl_hook: remove extra playlist insertDudemanguy2023-10-211-1/+0
| | | | | | b388c735408af1a78e8f6165fa3af31bc623ef8f should have deleted this line since the insert is done a little below it instead, but it was missed during review.
* ytdl_hook: parse the separate cookies fieldUmar Getagazov2023-10-211-1/+104
| | | | | https://github.com/yt-dlp/yt-dlp/security/advisories/GHSA-v8mc-9377-rwjj https://github.com/yt-dlp/yt-dlp/commit/1ceb657bdd25
* ytdl_hook.lua: set metadata with single tracksGuido Cella2023-10-111-3/+4
| | | | | | | | | | Use EDL for single tracks with metadata to set the uploader, channel url and description metadata with --ytdl-format=best. Currently, these are only set with the other ytdl formats with video and audio in different streams. The uploader tag is commonly available in sites other than Youtube too, so it may be simpler to always use EDL with single tracks.
* ytdl_hook: improve Windows exe search with suffixfireattack2023-08-131-3/+3
|
* ytdl_hook: fix clip start and endArnold Stanovský2023-04-121-3/+13
|
* ytdl_hook: only log error when no fallback url availableChristoph Heinrich2023-03-031-1/+2
| | | | | | | | | | An error indicates that something doesn't work, but as long as a safe url is available, playback is still expected to work. Thus reduce logging level of MP4 DASH without fragments message and add a new error message for when there is no safe url available either. Also adds a missing space.
* ytdl_hook: init fragment requires other fragmentsChristoph Heinrich2023-03-031-1/+1
| | | | | | | With dash the first fragment was always considered an init fragment if there wasn't a duration. However that only makes sense when there are also other fragments, so check if there are other fragments in addition to the lack of a duration.
* {console,ytdl_hook}: use the platform propertyDudemanguy2023-02-271-1/+1
| | | | | | The console.lua check is still kind of dumb since we check an environment variable to distinguish between wayland and x11, but otherwise it should be better in theory.
* ytdl_hook: don't overwrite force-media-titleChristoph Heinrich2023-02-271-2/+5
| | | | | | | | | | | | | | | | ytdl_hook always set force-media-title, making users unable to force a media-title via options. To prevent that, check if force-media-title is already set to avoid overwriting it. A better solution would be to use tags like is already done for some metadata, however that doesn't work when `all_formats=yes` is used. See cbb8f534b064f144820435148e516978de08cb30 A comment was added to hint at why it isn't done via tags. ref. https://github.com/mpv-player/mpv/pull/10453#issuecomment-1445277496
* ytdl_hook.lua: make exec return a single valueGuido Cella2023-02-271-15/+15
| | | | | | | | | | | | | | This refactors exec to only return the result of the subprocess command, and makes the rest of run_ytdl_hook use the fields of this result, because specifying all those return values multiple times is unwieldy now that exec is called several times, and this is easier to read anyway. I removed the line err = string.format("%s returned '%d'", err, es) altogether instead of updating the es variable, because there was no chance of it being executed since it would only happen when result.killed_by_us is true, but run_ytdl_hook returns early when it is.
* ytdl_hook: reverse order of tracksChristoph Heinrich2022-11-011-1/+7
| | | | | | | | | | | | | Only matters when configuring ytdl_hook with `all_formats=yes`. So far the tracks were ordered from worst to best quality. Web players with quality selection always show the highest quality option at the top. Since tracks are usually listed with the first track at the top, that should also be the highest quality one. yt-dlp/youtube-dl sorts it's formats from worst to best. Iterate in reverse to get best track first.
* ytdl_hook: use subtitle `name` as title if availableChristoph Heinrich2022-09-231-1/+2
| | | | | So far the `ext` was always used as the title, but `name` is more appropriate when it's available.
* ytdl_hook: simplify exclude option parsingChristoph Heinrich2022-09-141-5/+2
| | | | | The parsing used to be unnecessarily complicated, now it's easier to read and understand.
* ytdl_hook: improve track detectionChristoph Heinrich2022-08-171-13/+12
| | | | | | | | | | | | | | | | Every format that was not detected as a video format was added to the audio tracks. This resulted in e.g. YouTube storyboards from ending up in the list of audio tracks. Now formats that are already known to be neither video formats nor audio formats, will also not end up in any track list. Formats where it is unknown if they are video or audio get added to tracks if `force_all_formats` is used, otherwise only formats that are known to contain video or audio become video or audio tracks respectively. https://github.com/yt-dlp/yt-dlp/issues/4373#issuecomment-1186637357
* ytdl_hook: consistant behavior for single formatChristoph Heinrich2022-08-141-1/+17
| | | | | | | | | | | | | | One would expect that e.g. `--script-opts=ytdl_hook-all_formats=no --ytdl-format=bestaudio` and `--script-opts=ytdl_hook-all_formats=yes --ytdl-format=bestaudio` to play the exact same tracks without manual intervention. This already worked when two formats were requested. For a single format with `all_formats=yes` it would also play a track that was not requested when available. This was inconsistant with the behavior of `all_formats=no` (default), which would not play a second track when only a single one was requested. This combined with #10395 now plays the exact same tracks with `all_formats=yes` as without, even when only one format is requested.
* ytdl_hook: fix default track for single formatChristoph Heinrich2022-08-121-2/+2
| | | | | | | | | | | | | | | | | Tracks are marked as default tracks based on what yt-dlp/youtube-dl returns in the field `requested_formats`. The problem is that this field only exists when there is more then one requested format. So `ytdl-format=bestvideo+bestaudio` would have that field, but `ytdl-format=bestaudio` would not, leading to no tracks being marked as default tracks. The requested formats can also be found under `requested_downloads`, which exists regardless of the number of requested formats. However when there is more then one requested format, `requested_downloads` doesn't contain those formats directly and instead has a field `requested_formats` that is identical to the other `requested_formats`. Therefore use `requested_downloads` as a fallback for when `requested_formats` doesn't exist.
* ytdl_hook: fix playlist index extractionChristoph Heinrich2022-07-261-2/+4
| | | | | | | The example given in #3024 would not play the correct video when combined with `--ytdl-raw-options=yes-playlist=`. Allowing `youtube:tab` as extractor and correcting the id check fixes that.
* ytdl_hook: always set HTTP headersChristoph Heinrich2022-07-181-2/+6
| | | | | In some cases HTTP headers were not set, leading to some sites not working despite being supported by yt-dlp/youtube-dl.
* ytdl_hook.lua: consider any subprocess status != 0 as errorAvi Halachmi (:avih)2022-03-031-1/+6
| | | | | | | | | | | Previously only status<0 was considered as error, but status>0 is also an error (the process exit code). Change to status != 0. This likely makes little to no difference in practice, because if stdout is empty or can't be parsed as JSON then it's considered an error anyway, but still, this is more correct. Also, on error, add the complete subprocess result to the verbose log.
* ytdl_hook: fix url_is_safe to match URL protocols properlyGeorge Brooke2022-03-021-1/+1
| | | | | | | | | | | | | | | | | | | | | | Some youtube_dl extractors retrieve URLs which contain other URLs inside of them, for example Funimation, like this: https://example.com/video?parameter=https://example.net/something The url_is_safe function uses a pattern to match the protocol at the start of the URL. Before this commit, this pattern was not compliant with the URL spec (see the definition of "A URL-scheme string"): https://url.spec.whatwg.org/#url-writing Therefore it would match any characters, including "://", until the last occurence of "://" in the string. Thus the above URL would match https://example.com/video?parameter=https which is not in safe_protos so the video will not play. Now the protocol can only start with a letter and only contain alphanumerics, "." "+" or "-" as the spec says, so it will only match the first protocol in the URL ("https" in the above example.) Previously the URL also had to contain "//" after the ":". Data URLs do not contain "//": https://datatracker.ietf.org/doc/html/rfc2397 so now the pattern does not look for "//", only ":".
* ytdl_hook.lua: improve check for sub language before inserting all-subsUmar Javed2021-11-151-1/+1
| | | | | | | youtube-dl and yt-dlp both support --sub-langs and --srt-lang in addition to --sub-lang for defining languages of subtitles. This hook only checked for sub-lang in --ytdl-raw-options and inserted --all-subs in its absence.
* ytdl_hook.lua: search for yt-dlp by defaultGuido Cella2021-09-251-18/+48
| | | | | | | | | | | Because youtube-dl is inactive and the yt-dlp fork is becoming more popular, make mpv use yt-dlp without any extra configuration. yt-dlp is ordered before youtube-dl because it's more obscure, so users who have yt-dlp installed are more likely to want to use it rather than youtube-dl. Fixes #9208.
* ytdl_hook: improve handling of json parsing errorsRetusthese2021-05-291-10/+12
| | | | | | | | | | This moves the JSON parsing above the main youtube-dl error-handling block and integrates parsing errors into that block. Now, if a parsing error occurs, youtube-dl's stderr will be logged as it is with other errors. This also catches errors that cause youtube-dl to output "null", which would previously be mishandled as a parsing error and crash ytdl_hook when it attempted to concatenate the error string from parse_json.
* ytdl_hook: expose some JSON fields as tagsYour Name2021-05-111-0/+29
| | | | | | | | | | 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).
* ytdl_hook: fix crash on missing track bitraternhmjoj2021-03-081-1/+1
| | | | | | | | Some tracks happen to lack bitrate information (ie. no tbr value). In that case, just ignore the track while computing the max bitrate. For an example, this is a stream in which all audio tracks have no bitrate: https://www.raiplay.it/dirette/rai1
* ytdl_hook: if ytdl not found in config dirs, use ytdl_path as isRicardo Constantino2020-10-271-1/+4
|
* ytdl_hook: support alternative youtube-dl pathRicardo Constantino2020-10-271-2/+4
| | | | | Allows using a youtube-dl not in PATH or a compatible fork of youtube-dl.
* ytdl_hook: sort subtitle list by languagewm42020-08-121-1/+7
| | | | | | The subtitle list is returned in randomized order, because a table (i.e. JSON object) is used. To make the order stable across repeated invocations, sort it by language.
* ytdl_hook: fix typo in unexpected error messageDerek Guenther2020-08-011-1/+1
|
* ytdl_hook: enable runtime changes of script optionssfan52020-03-291-1/+4
|
* ytdl_hook: fix URL extraction for manifestssfan52020-02-231-4/+4
|
* ytdl_hook: prefer "format" over "format_note" field for track titleswm42020-02-211-1/+1
| | | | | Much more verbose, but on the other hand format_note is useless for the alphabetic site with fragmented DASH streams.
* ytdl_hook: use "format" as fallback for "format_note" for stream titleswm42020-02-211-1/+1
| | | | | "format_note" normally contains a semi-informative description of the format. But some extractors, confusingly, have it in the "format" field.
* ytdl_hook: fix audio codec with some extractorswm42020-02-211-5/+11
| | | | | E.g. soundcloud. While it still worked, not having the audio codec was pretty annoying.
* ytdl_hook: fix Lua escapeswm42020-02-211-3/+3
| | | | | | This was obviously nonsense. In Lua 5.1 this appeared to work correctly, but it really turned "\." into "." (making the pattern accept any character). The proper way is using "%" for escaping.
* ytdl_hook, edl: add fps, samplerate codec parameterswm42020-02-211-2/+9
| | | | Well, didn't help much in the case I was interested it.
* ytdl_hook: make codec mapping more declarativewm42020-02-211-12/+9
|
* ytdl_hook: remove some old playlist redirection hackwm42020-02-211-6/+0
| | | | Should not be needed anymore. In fact, it's probably dangerous.
* ytdl_hook: enable default selection via --ytdl-format with all_formatswm42020-02-211-1/+25
| | | | | | | | | In all_formats mode, we've ignored what --ytdl-format did so far, since we've converted the full format list, instead of just the formats selected by youtube-dl. But we can easily restore --ytdl-format behavior: just mark the selected tracks as default tracks.
* ytdl_hook: add length parameter to delay-loaded tracks only oncewm42020-02-211-3/+3
| | | | | This was done for each media type, so muxed tracks had it twice, which logged a dumb warning. Move it out of the per-media type loop.
* ytdl_hook: remove bitrate estimation from file sizewm42020-02-211-4/+0
| | | | | I think this is unnecessary, and at worst done by youtube-dl itself (didn't check).
* ytdl_hook: use tbr for all tracks if vbr/abr not availablewm42020-02-211-0/+9
| | | | | | | | | | | | | | | | | | vbr and abr are the video and audio bitrates. Sometimes there is a weird mix of any of them available, but in these cases, it's not good to fall back to tbr if a specific track has no vbr/abr. For example, the alphabetic site provides tbr only for the muxed fallback stream, but using tbr would make the primitive mpv hls_bitrate selection pick the compatibility stream for audio, because it appears to have a higher bitrate than the other audio-only streams (because the bitrate includes video). So we must not use tbr in this case. On the other hand, formats coming from youtube-dl HLS master playlist use will only have tbr set. So as a heuristic, use the tbr only if it's the only bitrate available in any track entry.
* ytdl_hook: replace skip_muxed with force_all_formats optionwm42020-02-211-26/+10
| | | | | | | | | | | | | I don't think the skip_muxed option was overlay useful. While it was nice to filter out the low quality muxed versions (as it happens on the alphabetic site, I suspect it's compatibility stuff), it's not really necessary, and just makes for another tricky and rarely used configuration option. (This was different before muxed tracks were also delay-loaded, and including the muxed versions slowed down loading.) Add the force_all_formats option instead, which handles the HLS case. Set it to true because they are also delay-loaded now, and don't slow down startup as much.
* ytdl_hook: delay-load interleaved fileswm42020-02-211-23/+36
| | | | | | (Or if it's about HLS, just "muxed"/multiplexed streams.) This only affects all_formats=yes,skip_muxed=no modes.
* ytdl_hook: signal duration in all_formats modewm42020-02-201-1/+6
| | | | | | If all streams were delay loaded, there was actually no duration present at all in the EDL metadata. So the length was considered unknown by the player frontend.
* ytdl_hook: attempt to filter out muxed streams if all_formats is usedwm42020-02-201-74/+147
| | | | | | | | | | | | | See manpage additions. We would have to extend delay_open to support multiple sub-tracks (for audio and video), and we'd still don't know (?) whether it might contain more than one stream each (thinking of HLS master streams). And if it's a true interleaved file (such as a "normal" mp4 file provided as fallback for more primitive players), we'd either have to signal such "bundled" tracks, or waste bandwidth. This restructures a lot. The if/else tree in add_single_video for format selection was a bit annoying, so it's split into separate if blocks, where it checks each time whether a URL was determined yet.
* ytdl_hook: remove forgotten debug messagewm42020-02-201-1/+0
| | | | It even has a typo.
* ytdl_hook: use bitrate fields for bitrate metadata instead of file sizeswm42020-02-201-1/+8
| | | | If available.
* ytdl_hook: try to skip interleaved streams with all_formatswm42020-02-201-2/+11
| | | | | | | | | | | | | | | | | If a "format" has both audio and video codec set, it might contain both audio and video. all_format assumes that each format is just a quality variant containing a single track. This seems to happen with sites that provide a HLS master URL. youtube-dl tends to "butcher" it, and the result isn't very ideal. I guess HLS "renditions" simply don't map well to youtube-dl's output format and what mpv expects. Playing master HLS directly is also less than ideal, because of libavformat's stupid probing. Fix this by not using the delay-opening mechanism if it appears like we detected such a case. Add a metadata override to set the track titles to "muxed-N", to indicate that they form a single unit. (Mostly helpful for testing.)
* ytdl_hook: iterate format list by array orderwm42020-02-201-1/+1
| | | | | Shouldn't have any consequences. Probably makes the user-visible order more stable.
* ytdl_hook: add all_formats optionwm42020-02-191-18/+85
| | | | | | | | | Pretty worthless I guess. I only tested one site (and 2 videos), it's somewhat likely that it will break with other sites. Even if you leave the option disabled (the default). Slightly related to #3548. This will allows you to use the bitrate stream selection mechanism, that was added for HLS, with normal videos.
* ytdl_hook: add a way to not pass --format to the command linewm42020-02-191-2/+5
| | | | Might be helpful for... whatever.
* ytdl_hook.lua: delay load subtitleswm42020-02-151-2/+12
| | | | | | | | | | | | | | | | 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.
* ytdl_hook: --vid=no should not ignore --ytdl-format in config filewm42019-10-241-3/+1
| | | | | | Do this only if ytdl-format was not set at all. Fixes: #6636
* ytdl_hook: check youtube-dl version if it breaksNicolas F2019-10-131-2/+32
| | | | | | |