From 8a4b86e9fa060b99e974766c0e6dbc67f99d5496 Mon Sep 17 00:00:00 2001 From: Vijay <74645268+vijaysingh2219@users.noreply.github.com> Date: Wed, 17 Apr 2024 00:05:43 +0530 Subject: [PATCH] Integrated Youtube Renderer with video player --- prisma/seed.ts | 72 ++++--- src/components/YoutubeRenderer.tsx | 18 +- .../admin/ContentRendererClient.tsx | 197 ++++++++++-------- 3 files changed, 172 insertions(+), 115 deletions(-) diff --git a/prisma/seed.ts b/prisma/seed.ts index fe3ba0b86..9be7ad0f8 100644 --- a/prisma/seed.ts +++ b/prisma/seed.ts @@ -147,30 +147,54 @@ async function main() { data: { id: 1, contentId: 3, - video_1080p_mp4_1: 'https://www.w3schools.com/html/mov_bbb.mp4', - video_1080p_mp4_2: 'https://www.w3schools.com/html/mov_bbb.mp4', - video_1080p_mp4_3: 'https://www.w3schools.com/html/mov_bbb.mp4', - video_1080p_mp4_4: 'https://www.w3schools.com/html/mov_bbb.mp4', - video_1080p_1: 'https://www.w3schools.com/html/mov_bbb.mp4', - video_1080p_2: 'https://www.w3schools.com/html/mov_bbb.mp4', - video_1080p_3: 'https://www.w3schools.com/html/mov_bbb.mp4', - video_1080p_4: 'https://www.w3schools.com/html/mov_bbb.mp4', - video_720p_mp4_1: 'https://www.w3schools.com/html/mov_bbb.mp4', - video_720p_mp4_2: 'https://www.w3schools.com/html/mov_bbb.mp4', - video_720p_mp4_3: 'https://www.w3schools.com/html/mov_bbb.mp4', - video_720p_mp4_4: 'https://www.w3schools.com/html/mov_bbb.mp4', - video_720p_1: 'https://www.w3schools.com/html/mov_bbb.mp4', - video_720p_2: 'https://www.w3schools.com/html/mov_bbb.mp4', - video_720p_3: 'https://www.w3schools.com/html/mov_bbb.mp4', - video_720p_4: 'https://www.w3schools.com/html/mov_bbb.mp4', - video_360p_mp4_1: 'https://www.w3schools.com/html/mov_bbb.mp4', - video_360p_mp4_2: 'https://www.w3schools.com/html/mov_bbb.mp4', - video_360p_mp4_3: 'https://www.w3schools.com/html/mov_bbb.mp4', - video_360p_mp4_4: 'https://www.w3schools.com/html/mov_bbb.mp4', - video_360p_1: 'https://www.w3schools.com/html/mov_bbb.mp4', - video_360p_2: 'https://www.w3schools.com/html/mov_bbb.mp4', - video_360p_3: 'https://www.w3schools.com/html/mov_bbb.mp4', - video_360p_4: 'https://www.w3schools.com/html/mov_bbb.mp4', + // video_1080p_mp4_1: 'https://www.w3schools.com/html/mov_bbb.mp4', + // video_1080p_mp4_2: 'https://www.w3schools.com/html/mov_bbb.mp4', + // video_1080p_mp4_3: 'https://www.w3schools.com/html/mov_bbb.mp4', + // video_1080p_mp4_4: 'https://www.w3schools.com/html/mov_bbb.mp4', + // video_1080p_1: 'https://www.w3schools.com/html/mov_bbb.mp4', + // video_1080p_2: 'https://www.w3schools.com/html/mov_bbb.mp4', + // video_1080p_3: 'https://www.w3schools.com/html/mov_bbb.mp4', + // video_1080p_4: 'https://www.w3schools.com/html/mov_bbb.mp4', + // video_720p_mp4_1: 'https://www.w3schools.com/html/mov_bbb.mp4', + // video_720p_mp4_2: 'https://www.w3schools.com/html/mov_bbb.mp4', + // video_720p_mp4_3: 'https://www.w3schools.com/html/mov_bbb.mp4', + // video_720p_mp4_4: 'https://www.w3schools.com/html/mov_bbb.mp4', + // video_720p_1: 'https://www.w3schools.com/html/mov_bbb.mp4', + // video_720p_2: 'https://www.w3schools.com/html/mov_bbb.mp4', + // video_720p_3: 'https://www.w3schools.com/html/mov_bbb.mp4', + // video_720p_4: 'https://www.w3schools.com/html/mov_bbb.mp4', + // video_360p_mp4_1: 'https://www.w3schools.com/html/mov_bbb.mp4', + // video_360p_mp4_2: 'https://www.w3schools.com/html/mov_bbb.mp4', + // video_360p_mp4_3: 'https://www.w3schools.com/html/mov_bbb.mp4', + // video_360p_mp4_4: 'https://www.w3schools.com/html/mov_bbb.mp4', + // video_360p_1: 'https://www.w3schools.com/html/mov_bbb.mp4', + // video_360p_2: 'https://www.w3schools.com/html/mov_bbb.mp4', + // video_360p_3: 'https://www.w3schools.com/html/mov_bbb.mp4', + // video_360p_4: 'https://www.w3schools.com/html/mov_bbb.mp4', + video_1080p_mp4_1: 'https://www.youtube.com/watch?v=IJkYipYNEtI', + video_1080p_mp4_2: 'https://www.youtube.com/watch?v=IJkYipYNEtI', + video_1080p_mp4_3: 'https://www.youtube.com/watch?v=IJkYipYNEtI', + video_1080p_mp4_4: 'https://www.youtube.com/watch?v=IJkYipYNEtI', + video_1080p_1: 'https://www.youtube.com/watch?v=IJkYipYNEtI', + video_1080p_2: 'https://www.youtube.com/watch?v=IJkYipYNEtI', + video_1080p_3: 'https://www.youtube.com/watch?v=IJkYipYNEtI', + video_1080p_4: 'https://www.youtube.com/watch?v=IJkYipYNEtI', + video_720p_mp4_1: 'https://www.youtube.com/watch?v=IJkYipYNEtI', + video_720p_mp4_2: 'https://www.youtube.com/watch?v=IJkYipYNEtI', + video_720p_mp4_3: 'https://www.youtube.com/watch?v=IJkYipYNEtI', + video_720p_mp4_4: 'https://www.youtube.com/watch?v=IJkYipYNEtI', + video_720p_1: 'https://www.youtube.com/watch?v=IJkYipYNEtI', + video_720p_2: 'https://www.youtube.com/watch?v=IJkYipYNEtI', + video_720p_3: 'https://www.youtube.com/watch?v=IJkYipYNEtI', + video_720p_4: 'https://www.youtube.com/watch?v=IJkYipYNEtI', + video_360p_mp4_1: 'https://www.youtube.com/watch?v=IJkYipYNEtI', + video_360p_mp4_2: 'https://www.youtube.com/watch?v=IJkYipYNEtI', + video_360p_mp4_3: 'https://www.youtube.com/watch?v=IJkYipYNEtI', + video_360p_mp4_4: 'https://www.youtube.com/watch?v=IJkYipYNEtI', + video_360p_1: 'https://www.youtube.com/watch?v=IJkYipYNEtI', + video_360p_2: 'https://www.youtube.com/watch?v=IJkYipYNEtI', + video_360p_3: 'https://www.youtube.com/watch?v=IJkYipYNEtI', + video_360p_4: 'https://www.youtube.com/watch?v=IJkYipYNEtI', slides: 'https://appx-recordings.s3.ap-south-1.amazonaws.com/drm/100x/slides/Loops%2C+callbacks.pdf', }, diff --git a/src/components/YoutubeRenderer.tsx b/src/components/YoutubeRenderer.tsx index 3710c8704..ef849b19d 100644 --- a/src/components/YoutubeRenderer.tsx +++ b/src/components/YoutubeRenderer.tsx @@ -2,25 +2,33 @@ import React from 'react'; interface Props { videoURL: string; - width: string; - height: string; + width?: string; + height?: string; style?: React.CSSProperties; + className?: string; } -export const YoutubeRenderer = ({ width, height, videoURL, style }: Props) => { +export const YoutubeRenderer = ({ + width, + height, + videoURL, + style, + className, +}: Props) => { if (!videoURL) { return null; } return ( ); }; diff --git a/src/components/admin/ContentRendererClient.tsx b/src/components/admin/ContentRendererClient.tsx index d864a5f3a..a1a6e22c4 100644 --- a/src/components/admin/ContentRendererClient.tsx +++ b/src/components/admin/ContentRendererClient.tsx @@ -5,6 +5,20 @@ import { VideoPlayerSegment } from '@/components/VideoPlayerSegment'; import VideoContentChapters from '../VideoContentChapters'; import { useMemo, useState } from 'react'; import { handleMarkAsCompleted } from '@/lib/utils'; +import YoutubeRenderer from '../YoutubeRenderer'; + +const isYouTubeUrl = (url: string): boolean => { + const youtubePattern: RegExp = + /(?:youtu|youtube)(?:\.com|\.be)\/(?:watch\?v=)?([\w-]+)/; + return youtubePattern.test(url); +}; + +const extractYouTubeIdFromUrl = (url: string): string | null => { + const match: RegExpMatchArray | null = url.match( + /(?:youtu\.be\/|(?:youtube\.com\/(?:v\/|u\/\w\/|embed\/|watch\?v=)))([\w-]+)/, + ); + return match ? match[1] : null; +}; export const ContentRendererClient = ({ metadata, @@ -63,6 +77,11 @@ export const ContentRendererClient = ({ src: mpdUrl, type: 'application/x-mpegURL', }; + } else if (isYouTubeUrl(mpdUrl)) { + return { + src: mpdUrl, + type: 'video/youtube', + }; } return { src: mpdUrl, @@ -89,101 +108,107 @@ export const ContentRendererClient = ({ return (
-
- { - setContentCompleted(true); - }} + {source.type === 'video/youtube' ? ( + -
-
-
-
- {content.title} + ) : ( +
+ { + setContentCompleted(true); + }} + /> +
+
+
+
+ {content.title} +
+ +
- +
+ {/* */} +
+ {metadata.slides ? ( + + ) : null} + {!showChapters && metadata.segments?.length > 0 && ( + + )} +
- -
- {/* */} -
- {metadata.slides ? ( - - ) : null} - {!showChapters && metadata.segments?.length > 0 && ( + {nextContent ? ( +
- )} -
+ {nextContent.title} + {' '} +
+ ) : null}
- {nextContent ? ( -
- {' '} -
- ) : null} -
- + )} {showChapters && (