c045f6ad80
Build and Push Docker Image / build (push) Successful in 2m30s
Episodes without a title in the filename (e.g. "Lost - S02E21 - [DSNP WEBDL-1080p]") had their name set to "[DSNP WEBDL-1080p]" because the non-greedy (.+?) still matched into the bracket. Changed capture group to ([^\[]+?) so it refuses to match "[", falling back to the SxxExx identifier instead. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
137 lines
4.5 KiB
TypeScript
137 lines
4.5 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("episode without episode title falls back to SxxExx", () => {
|
|
const result = parsePath(
|
|
"/tv/Lost (2004)/Season 02/Lost (2004) - S02E21 - [DSNP WEBDL-1080p][EAC3 5.1][h264]-FLUX.mkv",
|
|
MOVIES,
|
|
TV,
|
|
);
|
|
expect(result).not.toBeNull();
|
|
expect(result!.type).toBe("Episode");
|
|
expect(result!.seriesName).toBe("Lost");
|
|
expect(result!.seasonNumber).toBe(2);
|
|
expect(result!.episodeNumber).toBe(21);
|
|
expect(result!.name).toBe("S02E21");
|
|
});
|
|
|
|
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();
|
|
});
|
|
});
|