From c7689af9ff002f9d41afcbc93f9d92aeebee60b3 Mon Sep 17 00:00:00 2001 From: LordMZTE Date: Sat, 2 Oct 2021 16:48:26 +0200 Subject: [PATCH] port playtwitch to ocaml --- scripts/playtwitch | 34 ++++++++++++++++++++-------------- scripts/sysupdate | 2 +- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/scripts/playtwitch b/scripts/playtwitch index 7b78bac..38bd0e4 100755 --- a/scripts/playtwitch +++ b/scripts/playtwitch @@ -1,18 +1,24 @@ -#!/bin/sh +#!/usr/bin/env scriptisto -# play a twitch stream using streamlink +(* + scriptisto-begin + script_src: playtwitch.ml + build_cmd: dune build playtwitch.exe + target_bin: ./_build/default/playtwitch.exe + files: + - path: dune + content: (executable (name playtwitch) (libraries clap)) + scriptisto-end +*) -__usage=" -USAGE: - $0 [quality] +Clap.description "play a twitch stream using streamlink"; +let stream_name = Clap.mandatory_string ~placeholder:"stream_name" () in +let quality = Clap.default_string ~placeholder:"quality" "best" in +Clap.close (); -ARGS: - Name of the stream to play - [quality] quality to use [default: best] -" +let stream_name = "https://twitch.tv/" ^ stream_name in -if [ -z $1 ] || [ $# -gt 2 ] || [ $1 = "--help" ]; then - echo -e "$__usage" -else - streamlink https://twitch.tv/$1 ${2:-best} -fi +let exit = + String.concat " " [ "streamlink"; stream_name; quality ] |> Sys.command +in +if exit != 0 then Stdlib.print_endline "streamlink crashed :(" diff --git a/scripts/sysupdate b/scripts/sysupdate index e927c1f..92de037 100755 --- a/scripts/sysupdate +++ b/scripts/sysupdate @@ -27,7 +27,7 @@ let run cmd = (String.concat " " [ "Command"; cmd; "exited with code"; string_of_int status ])) | _ -> - Stdlib.print_endline (String.concat " " [ "Command"; cmd; "not found." ]) + String.concat " " [ "Command"; cmd; "not found." ] |> Stdlib.print_endline let () = Clap.description "Update the system";