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

Add option to output metadata as JSON #64

Closed
b0o opened this issue May 11, 2018 · 6 comments
Closed

Add option to output metadata as JSON #64

b0o opened this issue May 11, 2018 · 6 comments

Comments

@b0o
Copy link

b0o commented May 11, 2018

I'm having a bit of a tough time parsing the metadata output.

According to #22, it's formatted in "GVariant", which is rather obscure and lacks many utilities to assist with parsing it.

It seems a more standard format like JSON would make more sense.

Adding a flag like --output=FORMAT where FORMAT is one of json, gvariant, etc. and keeping gvariant as the default would ensure this change wouldn't break any existing dependent code.

@acrisci
Copy link
Member

acrisci commented May 22, 2018

keeping gvariant as the default would ensure this change wouldn't break any existing dependent code.

I don't know if this is something to really be concerned about. It's a weird output format and I don't think anyone is parsing it.

It seems a more standard format like JSON would make more sense.

The only concern I have is adding a dependency.

What is the use case you have for parsing the json that can't be handled with getting a metadata prop with a command such as playerctl metadata artist?

@b0o
Copy link
Author

b0o commented May 22, 2018

@acrisci It would just be nice to be able to get all of the metadata at once rather than querying for each prop individually (which is what I'm doing now). Other than that, there's not a huge need for it.

I definitely understand the concern for adding a dependency. Maybe a simpler option would be to just output newline-delimited key=val pairs which would be trivial both to implement and parse.

@acrisci
Copy link
Member

acrisci commented May 22, 2018

Yeah, that is a bit awkward and you bring up some good points that the current output format is weird. But I think json is a bit overkill if you're just trying to print something like "artist -title" or something.

I've thought of a few ways to make this easier. Let me know if you like these ideas better than the json.

Idea 1: tsv output format

$ playerctl metadata gives tsv output which is human readable and fairly machine readable. It gets a little tricky with lists though.

xesam:title      Rise
xesam:artist     Katy Perry
xesam:album      Rise
...

Idea 2: format string

Playerctl metadata queries accept a format string like this:

$ playerctl metadata --format='%xesam:artist - %xesam:title'

This prints Katy Perry - Rise.

@b0o
Copy link
Author

b0o commented May 22, 2018

What about just modifying the playerctl metadata [KEY] command to accept multiple keys?

E.g.

$ playerctl metadata xesam:artist xesam:title mpris:length xesam:userRating
Bonobo
Outlier
475000000
1

@acrisci
Copy link
Member

acrisci commented May 22, 2018

I think these are all good ideas :) let's break this up into separate issues and close this since we can do the same thing without a dependency. If you want to work on any of them feel free to pick it up.

If anyone has a use case that is not covered here where you really need json, feel free to reopen.

@b0o
Copy link
Author

b0o commented May 22, 2018

Sounds good, opened #68 and closing this.

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