Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Playlists not displaying correctly in terminal #5868

Closed
guibog opened this issue May 30, 2018 · 11 comments
Closed

Playlists not displaying correctly in terminal #5868

guibog opened this issue May 30, 2018 · 11 comments

Comments

@guibog
Copy link

guibog commented May 30, 2018

mpv version and platform

mpv 0.27.2 (C) 2000-2017 mpv/MPlayer/mplayer2 projects

Reproduction steps

  • Have L run echo "${playlist}" in ~/.mpv/input.conf
  • Use mpv folder_with_mp3_files/ to play a list of audio files
  • Type L to display the currently playing list in the terminal

Expected behavior

A nicely formatted playlist should be displayed showing currently playing item, etc.

Actual behavior

The terminal has some broken characters:

�{\alpha&HFF}➜ {\r}�02~130~Sanchez & The Shockers~Liquorice Latex (Original Mix).mp3
�{\alpha&HFF}➜ {\r}�03~131~Paolo Bolognesi~Test Flat.mp3
�{\alpha&HFF}➜ {\r}�04~126~Genetik & Gio Martinez~Pixel (Bingo Players Dead Pixel Remix).mp3
�{\alpha&HFF}➜ {\r}�05~130~Balthazar & JackRock~Tribalero (Original Mix) - remix.mp3
�➜ �06~130~Dubfire~Cage.mp3
�{\alpha&HFF}➜ {\r}�07~141~Bruno Power~Superbattlerz (Erik T Remix).mp3
�{\alpha&HFF}➜ {\r}�08~141~Danny C & Lethal MG~Jump Higher (G-Style 2007).mp3
�{\alpha&HFF}➜ {\r}�09~142~Mark With A K~Don_t Fuck With Me.mp3
�{\alpha&HFF}➜ {\r}�10~142~Coone - Villian~Bounce On Ya Sneakers.mp3
�{\alpha&HFF}➜ {\r}�11~141~Q-Ic & Lethal MG~Punk Shock.mp3
�{\alpha&HFF}➜ {\r}�12~130~Dim Chris~Sucker (Fred Pellichero Remix).mp3

Problem seems to be there:

https://github.com/mpv-player/mpv/blob/master/player/command.c#L127

I upgraded recently to Ubuntu 18.04, and got a new mpv version with it. I cannot say if the problem is with some missing font on my side, or wrong encoding, or if it is a new mpv feature. I was using this playlist feature and had no problem with my previous setup (mpv 0.14.0 and Ubuntu 16.04)

I also searched for a config to disable special characters in the terminal display, did not find it (the man page is kind of "rich"...)

Log file

https://0x0.st/s23T.txt

@Argon-
Copy link
Member

Argon- commented May 30, 2018

This is on purpose.
The stuff you are seeing is ASS formatting and makes for a nice presentation on the video window (where these sequences get rendered by libass). The plain-text playlist used to get quite confusing with multiple entries. Therefore, this change was made, sacrificing readability in the terminal.

Corresponding commit: 05c398f

@Argon- Argon- closed this as completed May 30, 2018
@guibog
Copy link
Author

guibog commented May 31, 2018

Ok, but then there's no simple way to display currently playing list in terminal? (I know it is a bit weird but I have been using mpv as terminal based music player for years: with a few tweaks in config it works really well...)

@Argon-
Copy link
Member

Argon- commented May 31, 2018

Yes, unfortunately. You are also not the first to have this problem/a desire for clean terminal output.
The problem with the property notation (${}) is that you can only get the OSD formatting (with ASS sequences as you see them) or a raw formatting (should be JSON in this case, so not much more useful).
When you query a property with a Lua script there are more options and you can retrieve a property as string but without OSD formatting.

You could try the following (untested) Lua script:

mp.add_forced_key_binding("L", "print-playlist", function() print(mp.get_property("playlist", "(empty)")) end)

Save it as a file and put it into a scripts folder within your mpv folder.

@guibog
Copy link
Author

guibog commented Jun 1, 2018

Thanks a lot! I adapted a bit the script to my needs, leaving it here just in case:

$ cat .mpv/scripts/pl.lua
json = require "json"
mp.add_forced_key_binding(
    "L",
    "print-playlist",
    function()
        pl = json.decode(mp.get_property("playlist", "[]"))
        for _, v in pairs(pl) do
            print (v["current"] and ">" or " ", v["filename"])
        end
    end
)

@rofrol
Copy link

rofrol commented Jan 12, 2020

Mapping to L does not work for me. I have used ' instead.

Also there are many json modules for lua. With this query I have found craigmj/json4lua.

Also mpv needs lua 5.2.

On Ubuntu you need to install:

sudo apt install lua5.2 lua5.2-dev luarocks

Then

sudo luarocks install json4Lua

I see there is also https://github.com/mpx/lua-cjson/ but I have not tried it

@ghost
Copy link

ghost commented Jan 12, 2020

Not only does mpv provide a parse_json function to Lua, but also you don't need to deal with json at all if you use get_property_native.

@Jack-O-Brian
Copy link

Jack-O-Brian commented Jun 15, 2020

One change I think the print-playlist function script should have is no default keybinding, so you can bind it in input.conf.

json = require "json"
mp.add_forced_key_binding(
    null,
    "print-playlist",
    function()
        pl = json.decode(mp.get_property("playlist", "[]"))
        for _, v in pairs(pl) do
            print (v["current"] and ">" or " ", v["filename"])
        end
    end
)

in .mpv/scripts/pl.lua, and in .mpv/input.conf just put a line that says l script-binding print-playlist

one thing I've been wondering about: can you have a keybindings change depending on if you're playing with and without video for mpv? Reason for this is the script won't show playlist for videos: it just prints to the console. But if you can have mpv see that you're playing a video, than it will change print-playlist key press to show_text ${playlist}

@jagrg
Copy link

jagrg commented Jul 17, 2020

I'm getting good results with this script (lightly tested). It also prints the playlist conditionally. Thanks to @HawaiinPizza's for the suggestion. Here's the output:

Marcos Valle - Moça flor (8/12)
A: 00:00:01 / 00:03:01 (0%)
[+                                                                                       ]
[print_playlist]   A morte de um deus de sal 
[print_playlist]   Ainda mais lindo 
[print_playlist]   Amor de nada 
[print_playlist]   Canção pequenina 
[print_playlist]   E vem o sol 
[print_playlist]   Ela é Carioca 
[print_playlist]   Ilusão à toa 
[print_playlist] > Moça flor 
[print_playlist]   Razão do amor 
[print_playlist]   Sonho de Maria 
[print_playlist]   Tudo de você 
[print_playlist]   Vivo sonhando 

(Paused) A: 00:00:18 / 00:03:01 (9%)
[────────+                                                                               ]

@ghost
Copy link

ghost commented Sep 27, 2023

I'm getting good results with this script

@jagrg You appear to have misspelled the URL (see archive.org history)


The Gitlab repo now redirects to gitlab.com/users/sign_in
Did you share the correct repo? Has the file been removed?

If you still have the LUA script stored locally, is sharing here viable?

@jagrg
Copy link

jagrg commented Sep 27, 2023 via email

@ghost
Copy link

ghost commented Sep 29, 2023

Sorry about that. Here it goes: https://git.sr.ht/~jagrg/dotfiles/tree/master/item/common/.config/mpv/scripts/print-playlist.lua

Functions, but the script has l mapped to its "show playlist" function — overrides native mpv keybindings:

l
Set/clear A-B loop points. See ab-loop command for details.

Can be mapped to another key in input.conf (doesn't clear the existing binding, presumably requires editing the LUA script):

KEY script-binding print-playlist

Also printing [print_playlist] on every line may not have any benefit. I'd replace with numerical order if I knew how.

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

5 participants