forked from sam/cytube-json-generator
Add spinny on upload
Signed-off-by: Sam Therapy <sam@samtherapy.net>
This commit is contained in:
parent
428ee0d71c
commit
578e8ea540
2 changed files with 14 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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<void> {
|
||||
|
@ -169,7 +170,8 @@ async function ffprobe(videoFile: string): Promise<Record<string, unknown>> {
|
|||
* @returns the URL of the uploaded file directly
|
||||
*/
|
||||
async function upload(location: string): Promise<string> {
|
||||
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<string> {
|
|||
},
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue