-
Notifications
You must be signed in to change notification settings - Fork 3.1k
ytdl_hook.lua: trim preceding text before JSON #16800
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
specifying |
@sfan5 I haven't tried looking for other examples but I can explain my rationale. I have added it to my config for debugging, sometimes the formats may not be available so it's always handy to see the list when I use So IMO it's a valid use case and we should try to cater for all valid configurations anyway, especially since there are no downsides in this case. |
Download the artifacts for this pull request: Windows |
This looks like a hacky way to extract json. Isn't there a way to redirect json to stderr or pipe? So we can access it cleanly, regardless of other output? Could you raise this issue upstream? |
@kasper93 Agreed, it's hacky, but it's a quick fix for an edge case, I'm still in favour of merging this until upstream has this sorted out, it might take some time for that to happen. I will create an issue there and see what happens in the meanwhile. |
Personally I would expect yt-dlp to return an error if I simultaneously used
Yes there is and you said it yourself: the hacky code in mpv |
I was thinking more along the lines of just ignoring the request since dumping the JSON should take precedence ideally. It could also write an error to
That can be overridden with
Well it's a fix to improve integration with a 3rd-party tool, so it's acceptable IMO. We can always remove it once upstream has a fix for this edge-case. |
For this specific case we could also just specify |
@guidocella I'm using |
Oh that would be better, I was thinking of adding it directly to the default command in |
There might be additional text in the output before the JSON payload if certain options like `--list-format` are specified in the config.
What if format/title or anything in printed output contains |
@kasper93 Well that would be an issue, but it's highly unlikely. We can modify the code to loop until it finds the right Also I have an update regarding upstream, I talked with the developers in yt-dlp's Discord and they want me to open an issue in their repo, but even assuming that they do fix this, we would still have an issue as yt-dlp is a fork of the real upstream... and that hasn't received any updates in over 4 months, so it's very unlikely that it's going to be fixed soon. These are our options:
Option 3 is the most immediate fix available, and obviously it's my preferred option until this is fixed in upstream as it's dependent on external factors. |
I don't think this needs to be fixed with
I think I got the same results yesterday but now |
I opened an issue in upstream: yt-dlp/yt-dlp#14378
Perhaps it stopped working after updating, I did an update yesterday and I cannot use |
|
There is an option 4 which is "consider --list-formats in user-specified options as invalid", with practically no downsides and no workarounds needed in mpv. |
@sfan5 I'm sorry but I have to disagree, option 4 is just accepting that we can't handle certain valid (as considered by youtube-dl) options with a very real downside of not being able to use it in mpv entirely. If this isn't fix isn't incorporated then users would be forced to maintain a separate config just for mpv and have it go out of sync potentially with the default config. Compared with Option 3 it's just a simple check in the Lua code, and the only downside is that our code is a bit hacky now, but we can always remove it once upstream has fixed the issue. |
I don't think "upstream" youtube-dl is used by anyone anymore, it doesn't even work for youtube. If the project is unmaintaned and doesn't fix bugs it will remain broken, we don't have to add random workarounds for abandoned software. That being said, proper fix is to update |
Instead of The ytdl hook should be able to assume standard settings rather than what has been configured by the user; if the system-wide settings have been made in a way that breaks the ytdl hook code, that is a problem with the system-wide installation. Then the hook options can safely add its own options, such as Having said that, options that have only a |
@dirkf That's an ideologically different take than what's currently implemented, I agree that having a separate yt-dl config for mpv has its benefits but it is my opinion that by default we should respect the user's config, they have configured it that way for a particular reason. As a real world example, maybe they have bandwidth limits and only want to view videos within a certain resolution, or only want to view videos in a free format like VP9 or AV1 instead of the H26X formats.
We can go one level deeper and think about why it breaks the hook and fix the breakage... that's what I did :)
I agree, I was looking for such an option as well. There's already an issue open with yt-dlp to fix the root cause but it may take some time. In the meanwhile we can have this hotfix merged and remove it once upstream has dealt with it. Without this hotfix users would be forced to compromise in some other way... personally I'd just make a wrapper script which just filters the output to just the JSON because I don't want to maintain a separate config just for mpv. |
Hence my suggestion to have a well known user config location for the ytdl hook. In the example, the config for limited bandwidth and/or screen resolution would probably be better in the system-wide config*; if not, or for one user's foibles, the user could link or copy or edit the user config to that location, or perhaps there could be a hook option to choose between hook default location, yt-dl default location or specified location. * Another real-world example, though not using mpv: for a set-top box installation, where the built-in player is the only way to access its H.264 decoder and can't handle more than 50fps+1080p, we put that system config in the yt-dl package for the platform. |
@dirkf Pardon me, but I don't really understand what you're suggesting, it just sounds like a more complicated way to do what are already able to do in mpv currently with just normal config options. Also it does not solve the issue if the user is able to customize the config, one way or another. |
So, with minimal knowledge of the hook internals, this is my suggestion...
For implementation, check for the presence of the well known ytdl hook user config and add Examples:
|
Personally I do not see the problem that is solved by making ytdl_hook not respect the global ytdl configuration file. |
You can already do |
Support explicit |
That's great news, we can now work around this by explicitly passing that option in mpv... so a new PR? 🤔 Also since this is a fix in the forked upstream how should we handle this? |
There might be additional text in the output before the JSON payload if certain options like
--list-format
are specified in the config.