Skip to content

Commit

Permalink
mediainfo test file
Browse files Browse the repository at this point in the history
  • Loading branch information
MrBrax committed Oct 5, 2023
1 parent 7a5125c commit 4eefe36
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 6 deletions.
81 changes: 81 additions & 0 deletions server/src/Helpers/Video.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// BEGIN: 7d4e1f7d9f5a
import path from "node:path";
import { videometadata } from "./Video";

// mock Config.getInstance() to return our mock config with mediainfo path set
jest.mock("../Core/Config", () => {
const config = {
cfg: (key: string) => {
if (key === "mediainfo_path") {
return "mediainfo";
}
return null;
},
hasValue: (key: string) => {
if (key === "mediainfo_path") {
return true;
}
return false;
},
initialised: true,
};
return {
Config: {
getInstance: jest.fn(() => config),
},
};
});

describe("videometadata", () => {
it("should throw an error if the file does not exist", async () => {
await expect(videometadata("nonexistentfile.mp4")).rejects.toThrow();
});

it("should return metadata for a valid video file", async () => {
const metadata = await videometadata(
path.join(
__dirname,
"..",
"..",
"tests",
"mockdata",
"testvideo.mp4"
)
);
expect(metadata).toBeDefined();
if (metadata.type !== "video") {
throw new Error("Expected metadata.type to be video");
}
expect(metadata.type).toBe("video");
expect(metadata.container).toBe("MPEG-4");
expect(metadata.video_codec).toBe("AVC");
expect(metadata.audio_codec).toBe("AAC");
expect(metadata.width).toBe(1920);
expect(metadata.height).toBe(1080);
expect(metadata.duration).toBe(1);
expect(metadata.bitrate).toBe(6125255);
expect(metadata.fps).toBe(60);
expect(metadata.fps_mode).toBe("VFR");
});

it("should return metadata for a valid audio file", async () => {
const metadata = await videometadata(
path.join(
__dirname,
"..",
"..",
"tests",
"mockdata",
"testaudio.mp3"
)
);
expect(metadata).toBeDefined();
if (metadata.type !== "audio") {
throw new Error("Expected metadata.type to be audio");
}
expect(metadata.type).toBe("audio");
expect(metadata.container).toBe("MPEG Audio");
expect(metadata.audio_codec).toBe("MPEG Audio");
});
});
// END: 7d4e1f7d9f5a
12 changes: 6 additions & 6 deletions server/src/Helpers/Video.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import { BaseConfigCacheFolder, BaseConfigDataFolder } from "@/Core/BaseConfig";
import { Config } from "@/Core/Config";
import { Helper } from "@/Core/Helper";
import { LiveStreamDVR } from "@/Core/LiveStreamDVR";
import { LOGLEVEL, log } from "@/Core/Log";
import type { FFProbe } from "@common/FFProbe";
import type {
AudioMetadata,
Expand All @@ -8,11 +13,6 @@ import type { MediaInfo } from "@common/mediainfofield";
import { createHash } from "node:crypto";
import fs from "node:fs";
import path from "node:path";
import { BaseConfigCacheFolder, BaseConfigDataFolder } from "@/Core/BaseConfig";
import { Config } from "@/Core/Config";
import { Helper } from "@/Core/Helper";
import { LiveStreamDVR } from "@/Core/LiveStreamDVR";
import { LOGLEVEL, log } from "@/Core/Log";
import type { RemuxReturn } from "../Providers/Twitch";
import { progressOutput } from "./Console";
import { execSimple, startJob } from "./Execute";
Expand Down Expand Up @@ -413,7 +413,7 @@ export async function mediainfo(filename: string): Promise<MediaInfo> {
}

if (!fs.existsSync(filename)) {
throw new Error("File not found for mediainfo");
throw new Error(`File not found for mediainfo: ${filename}`);
}

if (fs.statSync(filename).size == 0) {
Expand Down
Binary file added server/tests/mockdata/testaudio.mp3
Binary file not shown.
Binary file added server/tests/mockdata/testvideo.mp4
Binary file not shown.

0 comments on commit 4eefe36

Please sign in to comment.