forked from sam/cytube-json-generator
Compare commits
4 commits
Author | SHA1 | Date | |
---|---|---|---|
519f89fa7a | |||
31d9cc44b7 | |||
f178bb67bb | |||
578e8ea540 |
3 changed files with 28 additions and 11 deletions
10
README.md
10
README.md
|
@ -18,6 +18,16 @@ 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
|
||||
|
|
|
@ -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({
|
||||
|
|
21
generator.ts
21
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<void> {
|
||||
|
@ -59,9 +60,12 @@ 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);
|
||||
});
|
||||
|
@ -93,7 +97,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,
|
||||
|
@ -118,7 +122,7 @@ async function main(): Promise<void> {
|
|||
await Deno.writeTextFile("./result.json", JSON.stringify(json));
|
||||
const result = await upload("./result.json");
|
||||
|
||||
console.log(result);
|
||||
console.log(`JSON file uploaded to: ${result}`);
|
||||
Deno.exit();
|
||||
}
|
||||
|
||||
|
@ -157,7 +161,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;
|
||||
|
@ -169,7 +173,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 +187,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