diff --git a/src/main/lkt.c b/src/main/lkt.c index cc044f05a918122590e5dcac07e4e10e3c97e282..c0e0eb3693e68778021f93f1f4f91e2d0d5d6caf 100644 --- a/src/main/lkt.c +++ b/src/main/lkt.c @@ -276,6 +276,54 @@ populate__(struct lkt_cmd_args *args) rescan_or_update__(args, "__rescan"); } +noreturn void +queue_import__(struct lkt_cmd_args *args) +{ + if (args->argc != 1) + fail("Invalid argument"); + FILE *sock = lkt_connect(); + char buff[LKT_MESSAGE_MAX]; + write_socket(sock, "load %s\n", args->argv[0]); + exit_with_status(sock, buff); +} + +noreturn void +queue_replace__(struct lkt_cmd_args *args) +{ + if (args->argc != 1) + fail("Invalid argument"); + bool play = false; + char buff[LKT_MESSAGE_MAX]; + FILE *sock = lkt_connect(); + + for (;;) { + memset(buff, 0, LKT_MESSAGE_MAX * sizeof(char)); + read_socket(sock, buff, LKT_MESSAGE_MAX - 1); + size_t len = strcspn(buff, LKT_KEY_VALUE_SEP); + + if (STR_NMATCH(buff, "state", len)) { + char *it = lkt_skip_key(buff); + play = STR_NMATCH(it, "play", 4); + break; + } + + if (STR_NMATCH(buff, "OK", 2)) + break; + else if (STR_NMATCH(buff, "ACK", 3)) + fail("ACK"); + } + + fclose(sock); + sock = lkt_connect(); + write_socket(sock, "command_list_begin\n"); + write_socket(sock, "clear\n"); + write_socket(sock, "load %s\n", args->argv[0]); + if (play) + write_socket(sock, "play\n"); + write_socket(sock, "command_list_end\n"); + exit_with_status(sock, buff); +} + noreturn void config__(struct lkt_cmd_args *args) { @@ -816,14 +864,16 @@ search_with_cmd(search_queue__, playlistfind) /* Parsing stuff. */ static struct lkt_cmd_opt options_queue[] = { - { .name = "insert", .call = queue_insert__ }, - { .name = "pos", .call = queue_pos__ }, - { .name = "pop", .call = queue_pop__ }, - { .name = "add", .call = queue_add__ }, - { .name = "seek", .call = queue_seek__ }, - { .name = "delete", .call = queue_delete__ }, - { .name = "clear", .call = queue_clear__ }, - { .name = "crop", .call = queue_crop__ }, + { .name = "insert", .call = queue_insert__ }, + { .name = "pos", .call = queue_pos__ }, + { .name = "pop", .call = queue_pop__ }, + { .name = "add", .call = queue_add__ }, + { .name = "seek", .call = queue_seek__ }, + { .name = "delete", .call = queue_delete__ }, + { .name = "clear", .call = queue_clear__ }, + { .name = "crop", .call = queue_crop__ }, + { .name = "replace", .call = queue_replace__ }, + { .name = "import", .call = queue_import__ }, LKT_OPT_DEFAULT(queue_list__), };