From 578e8ea540d185b6f579b234d74f8c8ca556bacc Mon Sep 17 00:00:00 2001 From: Sam Therapy Date: Sun, 19 Jun 2022 16:17:04 +0200 Subject: [PATCH] Add spinny on upload Signed-off-by: Sam Therapy --- README.md | 8 ++++++++ generator.ts | 8 ++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9ada1f3..b9e4ea5 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,14 @@ deno install --allow-read --allow-write --allow-run "https://git.froth.zone/sam/ you may need to add this to your PATH. An alternative I have is setting `DENO_INSTALL_ROOT` to `~/.local/bin`, which I have in my PATH. +## Upgrading +You can upgrade in a similar way to installing: + +```bash +deno cache --reload "https://git.froth.zone/sam/cytube-json-generator/raw/branch/master/generator.ts" +``` +then [install](#installation) again. + ## Usage `generator video.mp4 subs.srt` will generate a JSON file for the video and diff --git a/generator.ts b/generator.ts index cca53ef..f2bfde4 100644 --- a/generator.ts +++ b/generator.ts @@ -5,6 +5,7 @@ import { underline, } from "https://deno.land/std@0.139.0/fmt/colors.ts"; import { readableStreamFromReader } from "https://deno.land/std@0.139.0/streams/mod.ts"; +import Kia from "https://deno.land/x/kia@0.4.1/mod.ts"; import srt2webvtt from "https://git.froth.zone/sam/srt-to-vtt/raw/branch/master/mod.ts"; async function main(): Promise { @@ -169,7 +170,8 @@ async function ffprobe(videoFile: string): Promise> { * @returns the URL of the uploaded file directly */ async function upload(location: string): Promise { - console.log(`Uploading ${location}, this will take time...`); + const kia: Kia = new Kia(`Uploading ${location}, this will take time...`); + kia.start(); const file = await Deno.open(location, { read: true }); const stream = readableStreamFromReader(file); @@ -182,12 +184,14 @@ async function upload(location: string): Promise { }, body: stream, }).catch(() => { + kia.fail(`Error uploading ${location}: fetch failed`); Deno.exit(1); }); const jsondata = await res.json().catch(() => { + kia.fail(`Error uploading ${location}: JSON response malformed`); Deno.exit(1); }); - console.log(`Successfully uploaded ${location} to ${jsondata.url}.\n`); + kia.succeed(`Successfully uploaded ${location} to ${jsondata.url}.\n`); return jsondata.direct_url; }