Compare commits

...

2 Commits

Author SHA1 Message Date
grumbulon 428ee0d71c Wrote test for small change I made in main fn :) 2022-05-30 21:52:57 -04:00
grumbulon cb88d162a8 preserve file name for JSON file title field and for VTT file 2022-05-30 21:20:15 -04:00
2 changed files with 39 additions and 3 deletions

34
file_name_test.ts Normal file
View File

@ -0,0 +1,34 @@
import { assertEquals } from "https://deno.land/std@0.141.0/testing/asserts.ts";
//Create map of video files and subtitles for testing
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"
);
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"
);
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"
);
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"
);
Deno.test({
name: "File parsing test",
fn: () => {
files.forEach((file) => {
const videoName = file
.split("/")
.pop()!
.slice(0, file.length - 4) as string;
assertEquals(videoName, file.slice(0, file.length - 4));
});
},
});

View File

@ -59,7 +59,9 @@ async function main(): Promise<void> {
// Get video file length
const videoFile: string = args._[0] as string;
const videoName = videoFile.split("/").pop()!.split(".")[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 stats = await ffprobe(videoFile).catch(() => {
Deno.exit(1);
});
@ -91,7 +93,7 @@ async function main(): Promise<void> {
// Upload the subtitles
const subtitlesUrl = await upload(`./${videoName}.vtt`);
const subtitleName = `${videoName}.vtt`
// Generate the JSON
const json = {
title: videoName,
@ -107,7 +109,7 @@ async function main(): Promise<void> {
{
url: subtitlesUrl,
contentType: "text/vtt",
name: "Subs or shit IDK",
name: subtitleName,
default: true,
},
],