From a37faec700265585a9fe1fd7c2c2d3b5dc589c89 Mon Sep 17 00:00:00 2001 From: Kuba Orlik Date: Tue, 20 Sep 2022 20:36:51 +0200 Subject: [PATCH] Better device picker --- record.ts | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/record.ts b/record.ts index ca46fcd..e29931b 100755 --- a/record.ts +++ b/record.ts @@ -1,6 +1,6 @@ #!/usr/bin/env -S ts-node-esm --compilerOptions='{"module": "es2022"}' -$.verbose = false; +$.verbose = true; import { $ } from "zx"; // Or @@ -15,10 +15,23 @@ function sleep(time: number) { } void (async function () { - const pick_device = - await $`ls -1 /dev/video* | xargs -I {} bash -c "v4l2-ctl --device {} --info | grep --extended-regexp \\"(Model|Card type)\\" | awk -F: '{print \\$2}' | awk '{print \"{}\" \",\" \\$0}' | tr , '\n'" | zenity --list --column=device --column=name`; - - const dev = `/dev/video${pick_device.stdout.split(" ")[0]}`; + const device_ids = (await $`ls -1 /dev/video*`).stdout + .split("\n") + .slice(0, -1); + const device_names = await Promise.all( + device_ids.map(async (device_id) => { + return ( + await $`v4l2-ctl --device ${device_id} --info | grep --extended-regexp "(Model|Card type)" | head -n 1 | cut -d: -f2` + ).stdout.replace("\n", ""); + }) + ); + let zenity_args = ""; + for (let i in device_ids) { + zenity_args += device_ids[i] + "\n" + device_names[i] + "\n"; + } + const dev = ( + await $`echo ${zenity_args} | zenity --list --column=device --column=name` + ).stdout.replace("\n", ""); const source = spawn("ffmpeg", [ "-f",