Something went wrong. Try again.
various tools I have been using throughout the years
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960#define _POSIX_C_SOURCE 200809L
#include "mpd_common.h"
#include <limits.h>#include <string.h>
static void usage(FILE *file, const char *program) { fprintf(file, "Usage: %s [--keep N]\n", program);}
int main(int argc, char **argv) { size_t keep = 0U; for (int i = 1; i < argc; i++) { if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) { usage(stdout, argv[0]); return 0; } if (strcmp(argv[i], "--keep") == 0 && i + 1 < argc) { if (!mt_parse_size(argv[++i], &keep) || keep > UINT_MAX) { fprintf(stderr, "mpd: invalid --keep value\n"); return 2; } } else { usage(stderr, argv[0]); return 2; } }
struct mpd_connection *connection = mt_connect(); if (connection == NULL) return 1; struct mt_player_state state; bool ok = mt_get_player_state(connection, &state); unsigned remove = 0U; if (ok && state.song_pos != UINT_MAX && state.song_pos > (unsigned)keep) remove = state.song_pos - (unsigned)keep; if (ok && remove > 0U) { enum mt_state_match match = mt_player_state_is(connection, state.queue_version, state.song_id); if (match == MT_STATE_CHANGED) { fprintf(stderr, "mpd: player or queue changed before trimming; retry the " "command\n"); ok = false; } else if (match == MT_STATE_ERROR) { ok = false; } } if (ok && remove > 0U && !mpd_run_delete_range(connection, 0U, remove)) { mt_report_error(connection, "trim played tracks"); ok = false; } if (ok) printf("Removed %u played track%s.\n", remove, remove == 1U ? "" : "s");
mt_player_state_clear(&state); mpd_connection_free(connection); return ok ? 0 : 1;}