Compare commits

..

1 commit

Author SHA1 Message Date
e3708f1d6e test 2022-07-25 19:11:54 -04:00
4 changed files with 11 additions and 28 deletions

View file

@ -18,16 +18,6 @@ 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

View file

@ -3,21 +3,21 @@ import { assertEquals } from "https://deno.land/std@0.141.0/testing/asserts.ts";
const files = new Map<string, string>();
files.set(
"8.Mile.2002.720p.BluRay.999MB.HQ.x265.10bit.mp4",
"8.Mile.2002.720p.BluRay.999MB.HQ.x265.10bit.srt",
"8.Mile.2002.720p.BluRay.999MB.HQ.x265.10bit.srt"
);
files.set("Blade.Runner (1997).mp4", "Blade.Runner (1997).srt");
files.set(
"Total.Recall.1990.REMASTERED.720p.BluRay.999MB.HQ.x265.mp4",
"Total.Recall.1990.REMASTERED.720p.BluRay.999MB.HQ.x265.srt",
"Total.Recall.1990.REMASTERED.720p.BluRay.999MB.HQ.x265.srt"
);
files.set("", "");
files.set(
"[Biraru] Chi's Sweet Home - 022 [DVD][576p][10-bit][x264][AC3][3CBD659E].mkv",
"[Biraru] Chi's Sweet Home - 022 [DVD][576p][10-bit][x264][AC3][3CBD659E].srt",
"[Biraru] Chi's Sweet Home - 022 [DVD][576p][10-bit][x264][AC3][3CBD659E].srt"
);
files.set(
"[Reaktor] Legend of the Galactic Heroes - Ginga Eiyuu Densetsu - Gaiden - Arc 1 - E1 [720p][x265][10-bit].mp4",
"[Reaktor] Legend of the Galactic Heroes - Ginga Eiyuu Densetsu - Gaiden - Arc 1 - E1 [720p][x265][10-bit].srt",
"[Reaktor] Legend of the Galactic Heroes - Ginga Eiyuu Densetsu - Gaiden - Arc 1 - E1 [720p][x265][10-bit].srt"
);
Deno.test({

View file

@ -5,7 +5,6 @@ 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> {
@ -60,12 +59,9 @@ async function main(): Promise<void> {
// Get video file length
const videoFile: string = args._[0] as string;
//preserve file name for JSON file and strip file extension and final .
const videoName = videoFile.split("/").pop()!.slice(
0,
videoFile.length - 4,
) as string;
const videoName = videoFile.split('/').pop()!.slice(0,videoFile.length-4) as string;
const stats = await ffprobe(videoFile).catch(() => {
Deno.exit(1);
});
@ -97,7 +93,7 @@ async function main(): Promise<void> {
// Upload the subtitles
const subtitlesUrl = await upload(`./${videoName}.vtt`);
const subtitleName = `${videoName}.vtt`;
const subtitleName = `${videoName}.vtt`
// Generate the JSON
const json = {
title: videoName,
@ -122,7 +118,7 @@ async function main(): Promise<void> {
await Deno.writeTextFile("./result.json", JSON.stringify(json));
const result = await upload("./result.json");
console.log(`JSON file uploaded to: ${result}`);
console.log(result);
Deno.exit();
}
@ -161,7 +157,7 @@ async function ffprobe(videoFile: string): Promise<Record<string, unknown>> {
}
// Make the duration actually a number
json.duration = Number(json.duration);
if (code !== 0) {
if (code != 0) {
throw new Error();
}
return json;
@ -173,8 +169,7 @@ async function ffprobe(videoFile: string): Promise<Record<string, unknown>> {
* @returns the URL of the uploaded file directly
*/
async function upload(location: string): Promise<string> {
const kia: Kia = new Kia(`Uploading ${location}, this will take time...`);
kia.start();
console.log(`Uploading ${location}, this will take time...`);
const file = await Deno.open(location, { read: true });
const stream = readableStreamFromReader(file);
@ -187,14 +182,12 @@ 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);
});
kia.succeed(`Successfully uploaded ${location} to ${jsondata.url}.\n`);
console.log(`Successfully uploaded ${location} to ${jsondata.url}.\n`);
return jsondata.direct_url;
}

0
test Normal file
View file