From 7ee1c137604394378260c0fe0f55c991d5f59766 Mon Sep 17 00:00:00 2001
From: adrifcastr <adrifcastr@gmail.com>
Date: Fri, 23 Jun 2023 10:23:46 +0200
Subject: [PATCH] human readable urls

---
 src/backend/metadata/getmeta.ts | 12 ++++++++++--
 src/backend/metadata/tmdb.ts    |  9 ++++++++-
 2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/src/backend/metadata/getmeta.ts b/src/backend/metadata/getmeta.ts
index a0fea637..8e9ab5e3 100644
--- a/src/backend/metadata/getmeta.ts
+++ b/src/backend/metadata/getmeta.ts
@@ -1,4 +1,5 @@
 import { FetchError } from "ofetch";
+import slugify from "slugify";
 
 import { formatJWMeta, mediaTypeToJW } from "./justwatch";
 import {
@@ -203,10 +204,17 @@ export async function convertLegacyUrl(
   // movies always have an imdb id on tmdb
   if (imdbId && mediaType === MWMediaType.MOVIE) {
     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) {
-    return `/media/tmdb-${type}-${tmdbId}`;
+    return `/media/tmdb-${type}-${tmdbId}-${slugify(meta.meta.title, {
+      lower: true,
+      strict: true,
+    })}`;
   }
 }
diff --git a/src/backend/metadata/tmdb.ts b/src/backend/metadata/tmdb.ts
index 1c442028..1caa2b55 100644
--- a/src/backend/metadata/tmdb.ts
+++ b/src/backend/metadata/tmdb.ts
@@ -1,3 +1,5 @@
+import slugify from "slugify";
+
 import { conf } from "@/setup/config";
 
 import { MWMediaMeta, MWMediaType, MWSeasonMeta } from "./types/mw";
@@ -75,7 +77,12 @@ export function formatTMDBMeta(
 }
 
 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(