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

JSON output format #305

Open
musjj opened this issue Mar 31, 2023 · 3 comments
Open

JSON output format #305

musjj opened this issue Mar 31, 2023 · 3 comments

Comments

@musjj
Copy link

musjj commented Mar 31, 2023

Bringing back this idea from an old issue: #64
I still think there's some value to a JSON output format, even when there's --format now.

For example, I wanted to have a conditional formatting:
If both the artist and title name is available, I want to display {{ artist }} - {{ title }}.
If only the title name is available, I want to display {{ title }}.
I tried playing around with the default function, but I don't think this is possible.

This can be potentially implemented as part of the format string, but I think it's easier to just have the tool output JSON. This will be very powerful, because once you have a JSON string, you can do any logic you want with it. Also, JSON is available everywhere these days, even in the shell with tools like jq.

@hseg
Copy link

hseg commented Aug 28, 2023

(note conditional formatting is also requested in #296 - this is clearly a pain point)

@bbb651
Copy link

bbb651 commented Oct 24, 2023

+1 I think it's a lot better to include a small dependency than to reinvent the wheel with formatting.

My use case is using playerctl from within eww, which accepts json.

I made a python script using dbus-python (P.S. is it a good idea to relay on the playerctld mrpis insterface?) as a workaround for now

#!/usr/bin/env python3

import dbus
import json

player = dbus.SessionBus().get_object('org.mpris.MediaPlayer2.playerctld', '/org/mpris/MediaPlayer2')
metadata = player.Get('org.mpris.MediaPlayer2.Player', 'Metadata', dbus_interface='org.freedesktop.DBus.Properties')
print(json.dumps(metadata))

@rice-cracker-dev
Copy link

+1

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

4 participants