human readable urls

This commit is contained in:
adrifcastr 2023-06-23 10:23:46 +02:00
parent 430b9564ab
commit 7ee1c13760
2 changed files with 18 additions and 3 deletions

View File

@ -1,4 +1,5 @@
import { FetchError } from "ofetch"; import { FetchError } from "ofetch";
import slugify from "slugify";
import { formatJWMeta, mediaTypeToJW } from "./justwatch"; import { formatJWMeta, mediaTypeToJW } from "./justwatch";
import { import {
@ -203,10 +204,17 @@ export async function convertLegacyUrl(
// movies always have an imdb id on tmdb // movies always have an imdb id on tmdb
if (imdbId && mediaType === MWMediaType.MOVIE) { if (imdbId && mediaType === MWMediaType.MOVIE) {
const movieId = await getMovieFromExternalId(imdbId); const movieId = await getMovieFromExternalId(imdbId);
if (movieId) return `/media/tmdb-movie-${movieId}`; if (movieId)
return `/media/tmdb-movie-${movieId}-${slugify(meta.meta.title, {
lower: true,
strict: true,
})}`;
} }
if (tmdbId) { if (tmdbId) {
return `/media/tmdb-${type}-${tmdbId}`; return `/media/tmdb-${type}-${tmdbId}-${slugify(meta.meta.title, {
lower: true,
strict: true,
})}`;
} }
} }

View File

@ -1,3 +1,5 @@
import slugify from "slugify";
import { conf } from "@/setup/config"; import { conf } from "@/setup/config";
import { MWMediaMeta, MWMediaType, MWSeasonMeta } from "./types/mw"; import { MWMediaMeta, MWMediaType, MWSeasonMeta } from "./types/mw";
@ -75,7 +77,12 @@ export function formatTMDBMeta(
} }
export function TMDBMediaToId(media: MWMediaMeta): string { export function TMDBMediaToId(media: MWMediaMeta): string {
return ["tmdb", mediaTypeToTMDB(media.type), media.id].join("-"); return [
"tmdb",
mediaTypeToTMDB(media.type),
media.id,
slugify(media.title, { lower: true, strict: true }),
].join("-");
} }
export function decodeTMDBId( export function decodeTMDBId(