main
|
Last change
on this file since c807e22 was 1579b4f, checked in by Filip Gavrilovski <filipgavrilovski28@…>, 5 months ago |
|
refactor artist, collection, listener components to have similar style as other components; refactor some dto-s
|
-
Property mode
set to
100644
|
|
File size:
558 bytes
|
| Line | |
|---|
| 1 | export const toEmbedUrl = (url: string): string => {
|
|---|
| 2 | try {
|
|---|
| 3 | const parsed = new URL(url);
|
|---|
| 4 | // youtube.com/watch?v=ID
|
|---|
| 5 | if (
|
|---|
| 6 | (parsed.hostname === "www.youtube.com" ||
|
|---|
| 7 | parsed.hostname === "youtube.com") &&
|
|---|
| 8 | parsed.searchParams.has("v")
|
|---|
| 9 | ) {
|
|---|
| 10 | return `https://www.youtube.com/embed/${parsed.searchParams.get("v")}`;
|
|---|
| 11 | }
|
|---|
| 12 | // youtu.be/ID
|
|---|
| 13 | if (parsed.hostname === "youtu.be") {
|
|---|
| 14 | return `https://www.youtube.com/embed${parsed.pathname}`;
|
|---|
| 15 | }
|
|---|
| 16 | // already an embed URL or other provider – return as-is
|
|---|
| 17 | return url;
|
|---|
| 18 | } catch {
|
|---|
| 19 | return url;
|
|---|
| 20 | }
|
|---|
| 21 | };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.