Skip to content
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

uosc badges only displayed after changing audio/video quality or reloading stream #21

Closed
xfzv opened this issue Jan 10, 2023 · 6 comments

Comments

@xfzv
Copy link

xfzv commented Jan 10, 2023

I have the following in uosc.conf:

controls=menu,gap,<has_many_audio>audio,<!has_many_audio,has_audio,stream>command:graphic_eq:script-binding quality_menu/audio_formats_toggle#@aformats>1?Audio,<has_chapter>chapters,<has_sub>subtitles,<!has_many_video,video,stream>command:theaters:script-binding quality_menu/video_formats_toggle#@vformats>1?Video
  • When opening a stream, this is what the uosc controls bar looks like:
    image

  • After choosing another video quality (not sure why the audio icon disappeared):
    image

  • After either choosing another audio quality or reloading the stream with script-binding quality_menu/reload:
    image

Is this a limitation or is there a way to get the badges for audio and video right when the stream starts?

I'm using yt-dlp 2023.01.06 if that matters.

@christoph-heinrich
Copy link
Owner

I've never encountered that and your controls config works just fine for me when I tested it with YouTube videos.
Does that always happen for you or only with specific videos?

@xfzv
Copy link
Author

xfzv commented Jan 10, 2023

I've never encountered that and your controls config works just fine for me when I tested it with YouTube videos. Does that always happen for you or only with specific videos?

I've tried about 5 YouTube and Twitch videos and it happens every time.

I also deleted all plugins and config files except uosc and quality-menu to make sure it wasn't a conflict with another plugin:

$ tree ~/.config/mpv
/home/xfzv/.config/mpv
├── fonts
│   ├── uosc_icons.otf
│   └── uosc_textures.ttf
├── input.conf
├── mpv.conf
├── script-opts
│   └── uosc.conf
└── scripts
    ├── quality-menu.lua
    ├── uosc.lua
    └── uosc_shared
        ├── elements
        │   ├── BufferingIndicator.lua
        │   ├── Button.lua
        │   ├── Controls.lua
        │   ├── Curtain.lua
        │   ├── CycleButton.lua
        │   ├── Element.lua
        │   ├── Elements.lua
        │   ├── Menu.lua
        │   ├── PauseIndicator.lua
        │   ├── Speed.lua
        │   ├── Timeline.lua
        │   ├── TopBar.lua
        │   ├── Volume.lua
        │   └── WindowBorder.lua
        ├── lib
        │   ├── ass.lua
        │   ├── menus.lua
        │   ├── std.lua
        │   ├── text.lua
        │   └── utils.lua
        └── main.lua

7 directories, 27 files

The video and audio quality are immediately available if I click on the respective uosc buttons (or trigger quality_menu/video_formats_toggle ; quality_menu/audio_formats_toggle with my keybindings), but the badges are only displayed after changing quality or reloading the stream.

@christoph-heinrich
Copy link
Owner

christoph-heinrich commented Jan 10, 2023

Then let's insert some print statements to find out when those values get set to what.

diff --git a/quality-menu.lua b/quality-menu.lua
index 5b84c24..b537d0b 100644
--- a/quality-menu.lua
+++ b/quality-menu.lua
@@ -411,6 +411,7 @@ local function process_json_string(url, json)
     local vres, ares, vfmt, afmt = process_json(json)
     url_data[url] = { voptions = vres, aoptions = ares, vfmt = vfmt, afmt = afmt }
     if uosc and get_url() == url then
+        print("process_json_string vformats " .. #vres .. " aformats " .. #ares)
         mp.commandv('script-message-to', 'uosc', 'set', 'vformats', #vres)
         mp.commandv('script-message-to', 'uosc', 'set', 'aformats', #ares)
     end
@@ -866,9 +867,11 @@ local function file_start()
 
     if uosc then
         if data then
+            print("file_start vformats " .. #data.voptions .. " aformats " .. #data.aoptions)
             mp.commandv('script-message-to', 'uosc', 'set', 'vformats', #data.voptions)
             mp.commandv('script-message-to', 'uosc', 'set', 'aformats', #data.aoptions)
         else
+            print("file_start vformats 0 aformats 0")
             mp.commandv('script-message-to', 'uosc', 'set', 'vformats', 0)
             mp.commandv('script-message-to', 'uosc', 'set', 'aformats', 0)
         end

Watch the output in the console.

If we can't find out what's causing this via some print statements (or inserting more logging in general), I'll have to make this work with the mocking and log parsing thing I've been working on, but that would require a lot of work.

@xfzv
Copy link
Author

xfzv commented Jan 10, 2023

mpv --no-really-quiet 'https://yt.artemislena.eu/watch?v=bH02RWAXyWc'
Resuming playback. This behavior can be disabled with --no-resume-playback.
[quality_menu] fetching available formats with youtube-dl...
Saving state.
Not seekable, or time unknown - not saving position.
 (+) Video --vid=1 (*) (h264 1280x720 30.000fps)
 (+) Audio --aid=1 (*) (aac 2ch 44100Hz)
AO: [pulse] 44100Hz stereo 2ch float
VO: [gpu] 1280x720 yuv420p
(Paused) AV: 00:00:00 / 00:11:19 (0%) A-V:  0.000 DS: 6.000/0 Cache: 678s/107MB

(pressed F5 to reload the video at this point)

Behavior of playlist-pos when writing the same value will change (currently restarts, it will stop doing this).
[auto_save_state] Deleting state (end-file stop)

Resuming playback. This behavior can be disabled with --no-resume-playback.
[quality_menu] file_start vformats 19 aformats 7
(Paused) AV: 00:00:00 / 00:11:19 (0%) A-V:  0.000 DS: 6.000/0 Cache: 678s/107MB
 (+) Video --vid=1 (*) (h264 1280x720 30.000fps)
 (+) Audio --aid=1 (*) (aac 2ch 44100Hz)
(Paused) AV: 00:00:00 / 00:11:19 (0%) A-V:  0.000 DS: 6.000/0 Cache: 678s/107MB

@christoph-heinrich
Copy link
Owner

I've managed to reproduce it now with a minimal test config. It's a race condition with the detection of uosc. A nice solution would require some refactoring to call ytdl asynchronously, but the following change should work.

diff --git a/quality-menu.lua b/quality-menu.lua
index 5b84c24..25d68fb 100644
--- a/quality-menu.lua
+++ b/quality-menu.lua
@@ -934,5 +934,6 @@ mp.register_script_message('uosc-version', function(version)
     version = tonumber((version:gsub('%.', '')))
     ---@diagnostic disable-next-line: cast-local-type
     uosc = version and version >= 400
+    file_start()
 end)
 mp.commandv('script-message-to', 'uosc', 'get-version', mp.get_script_name())

@xfzv
Copy link
Author

xfzv commented Jan 10, 2023

I've managed to reproduce it now with a minimal test config. It's a race condition with the detection of uosc. A nice solution would require some refactoring to call ytdl asynchronously, but the following change should work.

diff --git a/quality-menu.lua b/quality-menu.lua
index 5b84c24..25d68fb 100644
--- a/quality-menu.lua
+++ b/quality-menu.lua
@@ -934,5 +934,6 @@ mp.register_script_message('uosc-version', function(version)
     version = tonumber((version:gsub('%.', '')))
     ---@diagnostic disable-next-line: cast-local-type
     uosc = version and version >= 400
+    file_start()
 end)
 mp.commandv('script-message-to', 'uosc', 'get-version', mp.get_script_name())

Can confirm adding this fixes the issue, I've just tried with multiple videos.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants