jonniek / mpv-playlistmanager

Mpv lua script to create and manage playlists
The Unlicense
537 stars 42 forks source link

auto calculate showamount, fix #106 #132

Closed verygoodlee closed 9 months ago

verygoodlee commented 9 months ago

Some test cases, only list key options

Known bugs

  1. If options like this, the font size of each line is different from the global style_ass_tags, auto calculate is based on style_ass_tags's font size, so it must have a bug, but I think nobody would set this strange configuration, this bug can be ignored
    style_ass_tags={\fs15}
    playlist_header={\fs20}Playlist [%cursor/%plen]
    normal_file={\fs16}○ %name
    hovered_file={\fs16}● %name
    playing_hovered_file={\fs18}▶ %name
    ...
  2. [fixed] If some long file names occupy more than one line, it will definitely overflow, I have no idea to get the number of filename occupied lines. It's better to use showamount=auto and slice_longfilenames=yes together.
  3. [fixed] scale_playlist_by_window=no is required, at present, I don't know how scale_playlist_by_window=yes works
verygoodlee commented 9 months ago

In scale_playlist_by_window=yes case, there is still no progress. https://github.com/jonniek/mpv-playlistmanager/blob/7b8292589212a5bac1f312a555ec20aa561f972a/playlistmanager.lua#L671-L672 mp.set_osd_ass(0, 0, ass.text), how does it work, I can't find it in the Reference Manual, @jonniek do you have any documents about it? If not, may need to find the answer in mpv source code

jonniek commented 9 months ago

Here is the source https://github.com/mpv-player/mpv/blob/e22a2f04833852ce825eb7c1235d9bdaaa9b2397/player/lua/defaults.lua#L688

I think it was deprecated by https://mpv.io/manual/stable/#lua-scripting-mp-create-osd-overlay(format)

The overlay looks like this

 {"res_x" = 0, "format" = "ass-events", "res_y" = 720, "id" = 1, "data" = ""}

So I guess it's possible to mutate the resolution and update:

local ov = mp.create_osd_overlay("ass-events")
ov.data = "Hello world"
ov.res_x = 0
ov.res_y = 0
ov:update()

But it doesn't seem to have the effect of scaling the text. Seems like this setting has probably been broken for a long time. I think we can remove this setting and move to using the overlay API that is documented (not touch the size). I think I tried to implement it before at some point but there was some issue with the sizing but I can't remember exactly.

So probably it should be something like:

local playlist_osd_overlay = mp.create_osd_overlay("ass-events")

function draw_playlist()
  -- ...
  playlist_osd_overlay.data = ass.text
  playlist_osd_overlay:update()
end

function remove_keybinds()
  playlist_osd_overlay.data = ""
  playlist_osd_overlay:update()
  -- ...
end
verygoodlee commented 9 months ago

see https://mpv.io/manual/stable/#command-interface-ass-events

If res_y is set to 0, PlayResY is initialized to an arbitrary default value (but note that the default for this command is 720, not 0). If res_x is set to 0, PlayResX is set based on res_y such that a virtual ASS pixel has a square pixel aspect ratio.

The key point is the arbitrary default value, and I finally found it in the source code. https://github.com/mpv-player/mpv/blob/e22a2f04833852ce825eb7c1235d9bdaaa9b2397/sub/osd_libass.c#L111-L112 It's named MP_ASS_FONT_PLAYRESY, is a constant value 288. https://github.com/mpv-player/mpv/blob/e22a2f04833852ce825eb7c1235d9bdaaa9b2397/sub/ass_mp.h#L33

verygoodlee commented 9 months ago

For the issue of long filename, I think it's better to overflow to the right than to the bottom, we can use ASS Tag \q2 to make long filenames overflow to the right. image

jonniek commented 9 months ago

For the issue of long filename, I think it's better to overflow to the right than to the bottom, we can use ASS Tag \q2 to make long filenames overflow to the right.

Nice, that is probably a good default. I experimented a bit with a scrolling text, but it feels a bit jarring. I think overflowing the window makes more sense as a default.

I'll test the PR out a bit tomorrow and merge if I don't find any issues.

jonniek commented 9 months ago

Thanks for the PR! This is a great feature. I changed the default to be auto sized, and other configs a bit. Let me know if you think there are any issues in the changes I pushed.

verygoodlee commented 9 months ago

You replaced mp.set_osd_ass(...) by mp.create_osd_overlay("ass-events"), but no value is assigned to it's res_y, the default value is 720, current calculation of showamount is incorrect, and it has caused a new isue.

You need to change these two lines to local h = 720, https://github.com/jonniek/mpv-playlistmanager/blob/759b4076005f6df18d2717e8d695045709d55c05/playlistmanager.lua#L242 https://github.com/jonniek/mpv-playlistmanager/blob/759b4076005f6df18d2717e8d695045709d55c05/playlistmanager.lua#L651 and this comment need to modify, both them are based on 720p https://github.com/jonniek/mpv-playlistmanager/blob/759b4076005f6df18d2717e8d695045709d55c05/playlistmanager.lua#L253

update: find an old issue, curtain_opacity=1 has no effect. settings.curtain_opacity <= 1.0 https://github.com/jonniek/mpv-playlistmanager/blob/759b4076005f6df18d2717e8d695045709d55c05/playlistmanager.lua#L654

jonniek commented 9 months ago

Oh I see, I didn't notice any difference in rendering by setting the size, but I didn't test with the curtain.

I think it's fixed now, thanks!

verygoodlee commented 9 months ago

you pushed your test conf curtain_opacity=1.0 🤣