mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
feat(embed): add support to youtube playlists
This commit is contained in:
@@ -49,23 +49,34 @@ interface EmbedComponentProps {
|
|||||||
const youtubeHosts = new Set<string>(['youtube.com', 'www.youtube.com', 'youtu.be', 'www.youtu.be', 'm.youtube.com', 'music.youtube.com']);
|
const youtubeHosts = new Set<string>(['youtube.com', 'www.youtube.com', 'youtu.be', 'www.youtu.be', 'm.youtube.com', 'music.youtube.com']);
|
||||||
|
|
||||||
const YoutubeEmbed = ({ parsedUrl }: EmbedComponentProps) => {
|
const YoutubeEmbed = ({ parsedUrl }: EmbedComponentProps) => {
|
||||||
let youtubeId = parsedUrl.searchParams.get('v');
|
let embedSrc = '';
|
||||||
|
|
||||||
if (!youtubeId && parsedUrl.host.includes('youtu.be')) {
|
if (parsedUrl.searchParams.has('list')) {
|
||||||
youtubeId = parsedUrl.pathname.substring(1);
|
const playlistId = parsedUrl.searchParams.get('list');
|
||||||
|
embedSrc = `https://www.youtube.com/embed/videoseries?list=${playlistId}`;
|
||||||
|
} else {
|
||||||
|
let videoId = parsedUrl.searchParams.get('v');
|
||||||
|
|
||||||
|
if (!videoId && parsedUrl.host.includes('youtu.be')) {
|
||||||
|
videoId = parsedUrl.pathname.substring(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (youtubeId) {
|
if (videoId) {
|
||||||
|
embedSrc = `https://www.youtube.com/embed/${videoId}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (embedSrc) {
|
||||||
return (
|
return (
|
||||||
<iframe
|
<iframe
|
||||||
className={styles.videoEmbed}
|
className={styles.videoEmbed}
|
||||||
height='100%'
|
height='100%'
|
||||||
width='100%'
|
width='100%'
|
||||||
referrerPolicy='origin'
|
referrerPolicy='origin'
|
||||||
allow='accelerometer; encrypted-media; gyroscope; picture-in-picture; web-share'
|
allow='accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share'
|
||||||
allowFullScreen
|
allowFullScreen
|
||||||
title={parsedUrl.href}
|
title={parsedUrl.href}
|
||||||
src={`https://www.youtube.com/embed/${youtubeId}`}
|
src={embedSrc}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user