diff --git a/frontend/components/VideoList.tsx b/frontend/components/VideoList.tsx index 9d5cab5..2c54fc3 100644 --- a/frontend/components/VideoList.tsx +++ b/frontend/components/VideoList.tsx @@ -89,6 +89,7 @@ class VideoList extends React.Component { duration, fileName, title, + slug, sourceVideoStart, sourceVideoEnd, }, @@ -100,6 +101,7 @@ class VideoList extends React.Component { id={id} thumbnailServerURL={thumbnailServerURL} fileName={fileName} + slug={slug} title={title} sourceVideoStart={sourceVideoStart} sourceVideoEnd={sourceVideoEnd} diff --git a/frontend/components/VideoListItem.tsx b/frontend/components/VideoListItem.tsx index 252537e..8ea517d 100644 --- a/frontend/components/VideoListItem.tsx +++ b/frontend/components/VideoListItem.tsx @@ -39,6 +39,7 @@ export default function VideoListItem({ duration, id, fileName, + slug, title, sourceVideoStart, sourceVideoEnd, @@ -47,6 +48,7 @@ export default function VideoListItem({ duration: number | string, id: string, fileName: string, + slug: string, title: string, sourceVideoStart: number | string, sourceVideoEnd: number | string, @@ -77,7 +79,6 @@ export default function VideoListItem({ } displayDuration = videoEnd - videoStart; } - const titleUrlSlug = sanitizeTitle(title); const listGroupItem = ( @@ -131,7 +132,7 @@ export default function VideoListItem({ ); if (fileName) { return ( - + {listGroupItem} ); diff --git a/frontend/pages/[id]/[vslug].tsx b/frontend/pages/[id]/[vslug].tsx index 390967d..0279d98 100644 --- a/frontend/pages/[id]/[vslug].tsx +++ b/frontend/pages/[id]/[vslug].tsx @@ -115,7 +115,7 @@ const getProps = withSession(async (req, _res, { id, vslug }: VideoPlayerPagePar redirect: true, id, video, - vslug: sanitizeTitle(video.title), + vslug: video.slug, }, }; } @@ -132,13 +132,13 @@ const getProps = withSession(async (req, _res, { id, vslug }: VideoPlayerPagePar redirect: true, id, video: realVIndex, - vslug: sanitizeTitle(video.title), + vslug: video.slug, }, }; } // Check if we can find any video with matching vslug - const video = videos.find(({ title }: { title: string }) => sanitizeTitle(title) === vslug); + const video = videos.find(({ slug }: VideoEntry) => slug === vslug); if (!video) { return { props: {} }; } diff --git a/frontend/util/api.ts b/frontend/util/api.ts index d081b7c..35b65d2 100644 --- a/frontend/util/api.ts +++ b/frontend/util/api.ts @@ -15,8 +15,9 @@ * along with this program. If not, see . */ -import { VideoList } from './datatypes/VideoList'; +import { VideoEntry, VideoList } from './datatypes/VideoList'; import { VideoOnDemandIndex } from './datatypes/VideoOnDemandIdentifier'; +import sanitizeTitle from './sanitizeTitle'; const upstreamURL = process.env.UPSTREAM_URL; const upstreamDirectURL = process.env.UPSTREAM_DIRECT_URL || upstreamURL; @@ -73,7 +74,26 @@ export async function getIndex(): Promise { } export async function getVideos(id: string): Promise { - return getDirect(`videos/${id}.json`); + const result: VideoList = await getDirect(`videos/${id}.json`); + result.videos = result.videos.reduce((all: Array, { + slug, + title, + ...video + }: VideoEntry) => [ + ...all, + { + ...video, + title, + slug: typeof slug === 'string' + ? slug + : sanitizeTitle(title + ( + all.find(v => v.title === title) + ? ` ${all.filter(v => v.title === title).length + 1}` + : '' + )), + }, + ], []) + return result; } export function getDownloadURL(id: string, fileName: string): string { diff --git a/frontend/util/datatypes/VideoList.ts b/frontend/util/datatypes/VideoList.ts index 5180190..4139267 100644 --- a/frontend/util/datatypes/VideoList.ts +++ b/frontend/util/datatypes/VideoList.ts @@ -19,6 +19,7 @@ export interface VideoEntry { fileName:string title: string duration?: number | string, + slug: string, sourceVideoURL: string sourceVideoStart: number | string sourceVideoEnd: number | string