christoph-heinrich / mpv-quality-menu

A userscript for MPV that allows you to change the streamed video and audio quality (ytdl-format) on the fly.
GNU General Public License v2.0
126 stars 3 forks source link

combine audio and video tracks with audio and video quality in the Context Menu uosc #24

Closed candrapersada closed 1 year ago

candrapersada commented 1 year ago

can you combine the audio and video track Streaming m3u or m3u8 with audio and video youtube quality in the Context Menu

christoph-heinrich commented 1 year ago

~What do you mean combining them? Showing streaming formats and tracks at the same time doesn't make sense as they are different things.~

Edit: I finally realized what was meant further down and made it work.

christoph-heinrich commented 1 year ago

~Oh the context menu. Sorry I missed that at first and thought you meant the menu for selecting formats.~

~Here is an excerpt from my input.conf that might help you. It creates two top level elements for track and stream quality selection. For tracks it creates subelements for video-, audio- and subtitle-track-menu and for streaming formats it has the video- and audio-format-menu.~

#           ignore                                 #! Tracks >
#           ignore                                 #! Stream Quality >

V           script-binding uosc/video              #! Tracks > Select video
'           script-binding uosc/video              #! Tracks >
A           script-binding uosc/audio              #! Tracks > Select audio
\           script-binding uosc/audio              #! Tracks >
S           script-binding uosc/subtitles          #! Tracks > Select subtitles

F           script-binding quality_menu/video_formats_toggle #! Stream Quality > Video
Alt+f       script-binding quality_menu/audio_formats_toggle #! Stream Quality > Audio
candrapersada commented 1 year ago

why include_unknown=yes not working to change the hls video quality or tracks

christoph-heinrich commented 1 year ago

I have no idea what you mean, I've just tried include_unknown=yes and it works just fine for me. Do you have an example of how it fails?

candrapersada commented 1 year ago

switch from 1920x1080 to 854x480 doesn't work properly gambar gambar

christoph-heinrich commented 1 year ago

I've also tested switching to a format that would usually be filtered out with include_unknown=no and that worked, but depending on the website you might encounter formats that don't work correctly and I might not be able to do something about it even if I knew an the example in question.

Ultimately that script can only display what it gets from youtube-dl/yt-dlp and then set the format for mpv. If I get incorrect information or setting the format doesn't work for whatever reason, there is nothing I can do. mpv itself also relies on youtube-dl/yt-dlp to extract the download url, so it's certainly possible that you encountered a shortcoming of youtube-dl/yt-dlp itself and if you're willing to dig into it a bit, you could open an issue about it on their issue tracker.

christoph-heinrich commented 1 year ago

Did you by any chance set the ytdl-format with a per file option? I remember it failing like that when it got set like that by a different script some months ago.

christoph-heinrich commented 1 year ago

I've fixed the problem with per file options in the file_local_options branch. Does this work for you?

candrapersada commented 1 year ago

not working for mpv --referrer="https://gdriveplayer.link/" https://hive.gdriveplayer.link/cFOD7Lf0vS3efI4oPaeSbtYWOCWwxbugEATK5blx9mzwT4lw-TjGV3Y6MxcJ9G1SEKyMTWHJ4wM6jiVVOKIfDQ/_D4l-wWpS2Sg8BmjyMnaJpRHFnhuc2lZRvSj4Cfj0Sg/video.m3u8

christoph-heinrich commented 1 year ago

Ah I see, it fails because it requires a "Referer" header. I'm surprised that you even had options to choose from, because this script didn't add the header and without that yt-dlp failed for me.

I made it work by applying that patch to quality-menu ``` diff diff --git a/quality-menu.lua b/quality-menu.lua index 2304976..c7aeffe 100644 --- a/quality-menu.lua +++ b/quality-menu.lua @@ -572,6 +572,11 @@ local function download_formats(url) command[#command + 1] = '-f' command[#command + 1] = ytdl_format end + local referrer = mp.get_property('referrer') + if referrer and #referrer > 0 then + command[#command + 1] = '--add-header' + command[#command + 1] = 'Referer:' .. referrer + end if opts.ytdl_ver == 'yt-dlp' then command[#command + 1] = '--no-match-filter' end msg.verbose('calling ytdl with command: ' .. table.concat(command, ' ')) ```
and that very similar patch to the builtin ytdl_hook.lua ``` diff diff --git a/player/lua/ytdl_hook.lua b/player/lua/ytdl_hook.lua index f40579ad36..5c8f339b60 100644 --- a/player/lua/ytdl_hook.lua +++ b/player/lua/ytdl_hook.lua @@ -796,6 +796,12 @@ function run_ytdl_hook(url) end end + local referrer = mp.get_property('referrer') + if referrer and #referrer > 0 then + command[#command + 1] = '--add-header' + command[#command + 1] = 'Referer:' .. referrer + end + if (allsubs == true) then table.insert(command, "--all-subs") end ```

But having to modify the builtin script is a shitty solution, so here is a better one.

I've pushed a new commit to the file_local_options branch. Running mpv with --ytdl-raw-options-append=add-header="Referer:https://gdriveplayer.link/" works now.

candrapersada commented 1 year ago

what does [ffmpeg] https: HTTP error 404 Not Found mean mpv --ytdl-raw-options-append=add-header="Referer:https://gdriveplayer.link/" https://hive.gdriveplayer.link/cFOD7Lf0vS3efI4oPaeSbtYWOCWwxbugEATK5blx9mzwT4lw-TjGV3Y6MxcJ9G1SEKyMTWHJ4wM6jiVVOKIfDQ/_D4l-wWpS2Sg8BmjyMnaJpRHFnhuc2lZRvSj4Cfj0Sg/video.m3u8

[ffmpeg] https: HTTP error 404 Not Found
Failed to open https://hive.gdriveplayer.link/l2LQM46woKinxKA8uF2_EuSGr5UYoHv09J_P6F6qOrcmdP7DSH35i-is3NRm4YHbmL18verZdx4fwK5ZJbtYeA/YBrrzi8FujGiurpOb07fUnka-eKGJil_ypqxUzQc4UI/video.m3u8.
 (+) Video --vid=1 (h264 480x360 24.000fps)
 (+) Audio --aid=1 (aac 2ch 48000Hz)
[quality_menu] fetching available formats...
christoph-heinrich commented 1 year ago

That message is harmless in this case. It appears because mpv first tries to open the link with ffmpeg, but since it doesn't get the "Referer" header it can't open it, then it falls back to the ytdl_hook. Keep in mind that quality-menu only works when mpv uses the ytdl_hook, so while passing --referrer= will make that message go away, that will also prevent you from changing the format via quality-menu. You can tell mpv to try ytdl before ffmpeg by passing --script-opts-append=ytdl_hook-try_ytdl_first=yes, but with that certain links might take longer to open then they otherwise would (e.g. direct links to .mp4 and such).

candrapersada commented 1 year ago

so why include_unknown=yes not working to change the hls video quality or tracks from ffmpeg

christoph-heinrich commented 1 year ago

quality-menu works by setting the ytdl-format option of mpv, which, as the name suggests, is specific to youtube-dl/yt-dlp.

I'm not aware of a similar option for the ffmpeg code path, but since opening it via ffmpeg will add the different formats as tracks, you can switch between them by changing the video track.

christoph-heinrich commented 1 year ago

As the menu works now with your video, I'll consider this solved.

candrapersada commented 1 year ago

how to use User-Agent in --ytdl-raw-options-append=add-header="Referer:https://gdriveplayer.link/"

christoph-heinrich commented 1 year ago

how to use User-Agent in --ytdl-raw-options-append=add-header="Referer:https://gdriveplayer.link/"

Purely based on looking at the man page, I'd say --ytdl-raw-options-append=add-header="User-Agent:UA". You can have arbitrarily many --ytdl-raw-options-append= options, so just add one for each header you want to add.

candrapersada commented 1 year ago

what I mean is how to use the header User-Agent+Referer

christoph-heinrich commented 1 year ago

That's why I said you can have that multiple times.

--ytdl-raw-options-append=add-header="Referer:https://gdriveplayer.link/" --ytdl-raw-options-append=add-header="User-Agent:UA"

candrapersada commented 1 year ago

mpv --ytdl-raw-options-append=add-header="Referer:https://gdriveplayer.link/" --ytdl-raw-options-append=add-header="User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36" https://hive.gdriveplayer.link/XQMBENUxXwjmL3_e-WLtxriJd8y0w02h4X0kOz4Pw2c3ClHE3wZyDzb5lFYyRBDiBV_cw_txjpFrrjfzvsjAeA/VEd9m4bviG1nehygjwk_R0YsRa5pb0WcwQvXwjCy0_8/video.m3u8

[ytdl_hook] ERROR: [generic] None: Unable to download webpage: HTTP Error 404: Not Found (caused by <HTTPError 404: 'Not Found'>); please report this issue on  https://github.com/yt-dlp/yt-dlp/issues?q= , filling out the appropriate issue template. Confirm you are on the latest version using  yt-dlp -U
[ytdl_hook] youtube-dl failed: unexpected error occurred
christoph-heinrich commented 1 year ago

Huh, turns out that "list" is actually map... sounds like a flaw in mpv to me. To work around that you can try using the specific options for ytdl instead of the generic "add-header" --ytdl-raw-options-append=referer="https://gdriveplayer.link/" --ytdl-raw-options-append=user-agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36"