/** * playerctl_player_get_album: * @self: a #PlayerctlPlayer * @err: (allow-none): the location of a GError or NULL * * Gets the album from the metadata of the current track, or empty string if * no track is playing. * * Returns: (transfer full): The album from the metadata of the current track */ gchar *playerctl_player_get_album(PlayerctlPlayer *self, GError **err) { GError *tmp_error = NULL; g_return_val_if_fail(err == NULL || *err == NULL, NULL); if (self->priv->init_error != NULL) { g_propagate_error(err, g_error_copy(self->priv->init_error)); return NULL; } return playerctl_player_print_metadata_prop(self, "xesam:album", NULL); }
int main (int argc, char *argv[]) { GOptionContext *context = NULL; GError *error = NULL; context = g_option_context_new("- Controller for MPRIS players"); g_option_context_add_main_entries(context, entries, NULL); g_option_context_set_description(context, description); g_option_context_set_summary(context, summary); if (!g_option_context_parse(context, &argc, &argv, &error)) { g_printerr("Option parsing failed: %s\n", error->message); return 1; } if (version_opt) { g_print("v%s\n", PLAYERCTL_VERSION_S); return 0; } if (list_all_opt) { gchar *player_names = list_player_names(&error); if (error != NULL) { g_printerr("Could not list players: %s\n", error->message); return 1; } if (player_names[0] == '\0') g_printerr("%s\n", "No players were found"); else g_print("%s", player_names); return 0; } if (command == NULL) { g_print(g_option_context_get_help(context, TRUE, NULL)); return 0; } PlayerctlPlayer *player = playerctl_player_new(player_name, &error); if (error != NULL) { g_printerr("Connection to player failed: %s\n", error->message); return 1; } if (g_strcmp0(command[0], "volume") == 0) { /* VOLUME */ gdouble level; if (command[1]) { /* set */ level = g_ascii_strtod(command[1], NULL); g_object_set(player, "volume", level, NULL); } else { /* get */ g_object_get(player, "volume", &level, NULL); g_print("%g\n", level); } } else if (g_strcmp0(command[0], "play") == 0) { /* PLAY */ playerctl_player_play(player, &error); } else if (g_strcmp0(command[0], "pause") == 0) { /* PAUSE */ playerctl_player_pause(player, &error); } else if (g_strcmp0(command[0], "play-pause") == 0) { /* PLAY-PAUSE */ playerctl_player_play_pause(player, &error); } else if (g_strcmp0(command[0], "stop") == 0) { /* STOP */ playerctl_player_stop(player, &error); } else if (g_strcmp0(command[0], "next") == 0) { /* NEXT */ playerctl_player_next(player, &error); } else if (g_strcmp0(command[0], "previous") == 0) { /* PREVIOUS */ playerctl_player_previous(player, &error); } else if (g_strcmp0(command[0], "metadata") == 0) { /* METADATA */ gchar *value = NULL; if (g_strcmp0(command[1], "artist") == 0) value = playerctl_player_get_artist(player, &error); else if (g_strcmp0(command[1], "title") == 0) value = playerctl_player_get_title(player, &error); else if (g_strcmp0(command[1], "album") == 0) value = playerctl_player_get_album(player, &error); else value = playerctl_player_print_metadata_prop(player, command[1], &error); g_print("%s", value); g_free(value); } else if (g_strcmp0(command[0], "status") == 0) { /* STATUS */ gchar *status = NULL; g_object_get(player, "status", &status, NULL); if (status) { g_print("%s\n", status); } else { g_print("Not available\n"); } g_free(status); } else { /* unrecognized command */ g_print(g_option_context_get_help(context, TRUE, NULL)); } if (error != NULL) { g_printerr("An error occurred: %s\n", error->message); return 1; } return 0; }