mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
feat(post): support youtube links from Invidious instances
working Invidious instances: https://docs.invidious.io/instances/ https://uptime.invidious.io/
This commit is contained in:
@@ -46,26 +46,47 @@ interface EmbedComponentProps {
|
|||||||
parsedUrl: URL;
|
parsedUrl: URL;
|
||||||
}
|
}
|
||||||
|
|
||||||
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',
|
||||||
|
// working Invidious instances - https://docs.invidious.io/instances/ - https://uptime.invidious.io/
|
||||||
|
'yewtu.be',
|
||||||
|
'inv.nadeko.net',
|
||||||
|
'yt.artemislena.eu',
|
||||||
|
'invidious.nerdvpn.de',
|
||||||
|
]);
|
||||||
|
|
||||||
const YoutubeEmbed = ({ parsedUrl }: EmbedComponentProps) => {
|
const YoutubeEmbed = ({ parsedUrl }: EmbedComponentProps) => {
|
||||||
let embedSrc = '';
|
let embedSrc = '';
|
||||||
|
|
||||||
|
const isInvidious = parsedUrl.host !== 'youtube.com' && parsedUrl.host !== 'www.youtube.com' && parsedUrl.host !== 'youtu.be' && parsedUrl.host !== 'www.youtu.be';
|
||||||
|
|
||||||
if (parsedUrl.searchParams.has('list')) {
|
if (parsedUrl.searchParams.has('list')) {
|
||||||
const playlistId = parsedUrl.searchParams.get('list');
|
const playlistId = parsedUrl.searchParams.get('list');
|
||||||
embedSrc = `https://www.youtube.com/embed/videoseries?list=${playlistId}`;
|
embedSrc = `https://www.youtube.com/embed/videoseries?list=${playlistId}`;
|
||||||
} else {
|
} else {
|
||||||
let videoId = parsedUrl.searchParams.get('v');
|
let videoId = parsedUrl.searchParams.get('v');
|
||||||
|
|
||||||
if (!videoId && parsedUrl.host.includes('youtu.be')) {
|
if (!videoId) {
|
||||||
|
if (parsedUrl.host.includes('youtu.be')) {
|
||||||
videoId = parsedUrl.pathname.substring(1);
|
videoId = parsedUrl.pathname.substring(1);
|
||||||
|
} else if (isInvidious) {
|
||||||
|
if (parsedUrl.pathname.startsWith('/watch')) {
|
||||||
|
videoId = parsedUrl.searchParams.get('v');
|
||||||
|
} else {
|
||||||
|
videoId = parsedUrl.pathname.split('/').pop() || null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (videoId) {
|
if (videoId) {
|
||||||
embedSrc = `https://www.youtube.com/embed/${videoId}`;
|
embedSrc = `https://www.youtube.com/embed/${videoId}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (embedSrc) {
|
if (embedSrc) {
|
||||||
return (
|
return (
|
||||||
<iframe
|
<iframe
|
||||||
|
|||||||
Reference in New Issue
Block a user