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

Issues with mpris:length #234

Closed
yaflow-droid opened this issue Apr 8, 2021 · 3 comments
Closed

Issues with mpris:length #234

yaflow-droid opened this issue Apr 8, 2021 · 3 comments

Comments

@yaflow-droid
Copy link

The player I am using is spotify.

When trying to execute the command playerctl metadata --format="{{duration(mpris:length)}} -p spotify", I'm getting this error:

Could not execute command: function position can only be called on int64 values

I also tried playerctl metadata --format={{duration(mpris:length - position)}} -p spotify and I'm getting this error

Could not execute command: Got unsuported operand types for -: 't' and 'x'

@acrisci
Copy link
Member

acrisci commented Apr 8, 2021

Spotify is giving me mpris:length in type t (uint64) instead of x which is against spec. I can work around this by allowing that type to be an arg to the function and generalizing the - operand to work between any number types.

@king-gizzard
Copy link

is there a workaround that can be applied to the playerctl cli as is?
i'd be willing to try and help with this issue otherwise, but - fair warning - am quite inexperienced when it comes to contribution/collaboration.

@acrisci
Copy link
Member

acrisci commented Sep 9, 2021

Sure just make this work with type t.

static GVariant *helperfn_duration(struct token *token, GVariant **args, int nargs,
GError **error) {
if (nargs != 1) {
g_set_error(error, playerctl_formatter_error_quark(), 1,
"function uc takes exactly one argument (got %d)", nargs);
return NULL;
}
GVariant *value = args[0];
if (value == NULL) {
return g_variant_new("s", "");
}
// mpris durations are represented as int64 in microseconds
if (!g_variant_type_equal(g_variant_get_type(value), G_VARIANT_TYPE_INT64)) {
g_set_error(error, playerctl_formatter_error_quark(), 1,
"function position can only be called on int64 values");
return NULL;
}
gint64 duration = g_variant_get_int64(value);
gint64 seconds = (duration / 1000000) % 60;
gint64 minutes = (duration / 1000000 / 60) % 60;
gint64 hours = (duration / 1000000 / 60 / 60);
GString *formatted = g_string_new("");
if (hours != 0) {
g_string_append_printf(formatted, "%" PRId64 ":%02" PRId64 ":%02" PRId64, hours, minutes,
seconds);
} else {
g_string_append_printf(formatted, "%" PRId64 ":%02" PRId64, minutes, seconds);
}
gchar *formatted_inner = g_string_free(formatted, FALSE);
GVariant *ret = g_variant_new("s", formatted_inner);
g_free(formatted_inner);
return ret;
}

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

No branches or pull requests

3 participants