96bf208a16
Parses title, year, provider IDs (imdb/tmdb/tvdb), season, episode number, and container from on-disk paths without requiring Jellyfin. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
133 lines
4.1 KiB
TypeScript
133 lines
4.1 KiB
TypeScript
import { describe, expect, test } from "bun:test";
|
|
import { parsePath } from "../path-parser";
|
|
|
|
const MOVIES = "/movies";
|
|
const TV = "/tv";
|
|
|
|
describe("parsePath", () => {
|
|
test("movie with imdb id", () => {
|
|
const result = parsePath(
|
|
"/movies/Hot Fuzz (2007)/Hot Fuzz (2007) [imdbid-tt0425112] - [Bluray-1080p][DTS 5.1][x264]-CtrlHD.mkv",
|
|
MOVIES,
|
|
TV,
|
|
);
|
|
expect(result).not.toBeNull();
|
|
expect(result!.type).toBe("Movie");
|
|
expect(result!.name).toBe("Hot Fuzz");
|
|
expect(result!.year).toBe(2007);
|
|
expect(result!.imdbId).toBe("tt0425112");
|
|
expect(result!.tmdbId).toBeNull();
|
|
expect(result!.tvdbId).toBeNull();
|
|
expect(result!.container).toBe("mkv");
|
|
expect(result!.seriesName).toBeNull();
|
|
expect(result!.seasonNumber).toBeNull();
|
|
expect(result!.episodeNumber).toBeNull();
|
|
});
|
|
|
|
test("movie with tmdb id", () => {
|
|
const result = parsePath(
|
|
"/movies/Alien (1979)/Alien (1979) [tmdbid-348] - [Bluray-1080p].mkv",
|
|
MOVIES,
|
|
TV,
|
|
);
|
|
expect(result).not.toBeNull();
|
|
expect(result!.type).toBe("Movie");
|
|
expect(result!.name).toBe("Alien");
|
|
expect(result!.year).toBe(1979);
|
|
expect(result!.tmdbId).toBe("348");
|
|
expect(result!.imdbId).toBeNull();
|
|
});
|
|
|
|
test("movie with both imdb and tmdb ids", () => {
|
|
const result = parsePath(
|
|
"/movies/The Matrix (1999)/The Matrix (1999) [imdbid-tt0133093][tmdbid-603] - [Bluray-1080p].mkv",
|
|
MOVIES,
|
|
TV,
|
|
);
|
|
expect(result).not.toBeNull();
|
|
expect(result!.imdbId).toBe("tt0133093");
|
|
expect(result!.tmdbId).toBe("603");
|
|
});
|
|
|
|
test("episode standard format", () => {
|
|
const result = parsePath(
|
|
"/tv/Breaking Bad (2008)/Season 05/Breaking Bad (2008) - S05E03 - Hazard Pay [WEBDL-1080p][AC3 5.1][h264]-BS.mkv",
|
|
MOVIES,
|
|
TV,
|
|
);
|
|
expect(result).not.toBeNull();
|
|
expect(result!.type).toBe("Episode");
|
|
expect(result!.seriesName).toBe("Breaking Bad");
|
|
expect(result!.year).toBe(2008);
|
|
expect(result!.seasonNumber).toBe(5);
|
|
expect(result!.episodeNumber).toBe(3);
|
|
expect(result!.name).toBe("Hazard Pay");
|
|
expect(result!.tvdbId).toBeNull();
|
|
expect(result!.container).toBe("mkv");
|
|
});
|
|
|
|
test("episode with tvdb id in series folder", () => {
|
|
const result = parsePath(
|
|
"/tv/Arrow (2012) [tvdbid-257655]/Season 01/Arrow (2012) - S01E01 - Pilot [Bluray-1080p].mkv",
|
|
MOVIES,
|
|
TV,
|
|
);
|
|
expect(result).not.toBeNull();
|
|
expect(result!.type).toBe("Episode");
|
|
expect(result!.seriesName).toBe("Arrow");
|
|
expect(result!.year).toBe(2012);
|
|
expect(result!.seasonNumber).toBe(1);
|
|
expect(result!.episodeNumber).toBe(1);
|
|
expect(result!.name).toBe("Pilot");
|
|
expect(result!.tvdbId).toBe("257655");
|
|
});
|
|
|
|
test("multi-episode file uses first episode number", () => {
|
|
const result = parsePath(
|
|
"/tv/Breaking Bad (2008)/Season 02/Breaking Bad (2008) - S02E01-E13 - Seven Thirty-Seven [info].mkv",
|
|
MOVIES,
|
|
TV,
|
|
);
|
|
expect(result).not.toBeNull();
|
|
expect(result!.seasonNumber).toBe(2);
|
|
expect(result!.episodeNumber).toBe(1);
|
|
expect(result!.name).toBe("Seven Thirty-Seven");
|
|
});
|
|
|
|
test("mp4 container", () => {
|
|
const result = parsePath(
|
|
"/movies/Jaws (1975)/Jaws (1975) [imdbid-tt0073195] - [Bluray-1080p].mp4",
|
|
MOVIES,
|
|
TV,
|
|
);
|
|
expect(result).not.toBeNull();
|
|
expect(result!.container).toBe("mp4");
|
|
});
|
|
|
|
test("non-video file returns null", () => {
|
|
expect(parsePath("/movies/Hot Fuzz (2007)/Hot Fuzz (2007).nfo", MOVIES, TV)).toBeNull();
|
|
expect(parsePath("/movies/Hot Fuzz (2007)/Hot Fuzz (2007).srt", MOVIES, TV)).toBeNull();
|
|
expect(parsePath("/movies/Hot Fuzz (2007)/poster.jpg", MOVIES, TV)).toBeNull();
|
|
});
|
|
|
|
test("file not under moviesRoot or tvRoot returns null", () => {
|
|
expect(
|
|
parsePath("/other/Hot Fuzz (2007)/Hot Fuzz (2007) [imdbid-tt0425112].mkv", MOVIES, TV),
|
|
).toBeNull();
|
|
});
|
|
|
|
test("movie without provider ids (bare folder)", () => {
|
|
const result = parsePath(
|
|
"/movies/No Country for Old Men (2007)/No Country for Old Men (2007) - [Bluray-1080p].mkv",
|
|
MOVIES,
|
|
TV,
|
|
);
|
|
expect(result).not.toBeNull();
|
|
expect(result!.type).toBe("Movie");
|
|
expect(result!.name).toBe("No Country for Old Men");
|
|
expect(result!.year).toBe(2007);
|
|
expect(result!.imdbId).toBeNull();
|
|
expect(result!.tmdbId).toBeNull();
|
|
});
|
|
});
|