social-embeds 0.9.2 → 0.9.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/components/apple-embed.js +4 -4
- package/dist/components/bluesky-embed.js +2 -2
- package/dist/components/dailymotion-embed.js +2 -2
- package/dist/components/facebook-embed.js +2 -2
- package/dist/components/flickr-embed.js +2 -2
- package/dist/components/giphy-embed.js +2 -2
- package/dist/components/imgur-embed.js +2 -2
- package/dist/components/instagram-embed.js +2 -2
- package/dist/components/kick-embed.js +2 -2
- package/dist/components/linkedin-embed.js +2 -2
- package/dist/components/pinterest-embed.js +2 -2
- package/dist/components/reddit-embed.js +2 -2
- package/dist/components/rumble-embed.js +2 -2
- package/dist/components/snapchat-embed.js +2 -2
- package/dist/components/soundcloud-embed.js +2 -2
- package/dist/components/spotify-embed.js +2 -2
- package/dist/components/strava-embed.js +2 -2
- package/dist/components/streamable-embed.js +2 -2
- package/dist/components/telegram-embed.js +2 -2
- package/dist/components/tenor-embed.js +2 -2
- package/dist/components/threads-embed.js +2 -2
- package/dist/components/tiktok-embed.js +2 -2
- package/dist/components/truthsocial-embed.js +2 -2
- package/dist/components/tumblr-embed.js +2 -2
- package/dist/components/twitch-embed.js +2 -2
- package/dist/components/vimeo-embed.js +2 -2
- package/dist/components/x-embed.js +2 -2
- package/dist/components/youtube-embed.js +2 -2
- package/dist/element.js +1 -1
- package/dist/parser/iframe.js +2 -2
- package/dist/parser/matchers/applemusic.js +33 -0
- package/dist/parser/matchers/applepodcasts.js +32 -0
- package/dist/parser/matchers/bluesky.js +41 -0
- package/dist/parser/matchers/dailymotion.js +47 -0
- package/dist/parser/matchers/facebook.js +118 -0
- package/dist/parser/matchers/flickr.js +100 -0
- package/dist/parser/matchers/giphy.js +38 -0
- package/dist/parser/matchers/imgur.js +76 -0
- package/dist/parser/matchers/instagram.js +43 -0
- package/dist/parser/matchers/kick.js +48 -0
- package/dist/parser/matchers/linkedin.js +31 -0
- package/dist/parser/matchers/pinterest.js +32 -0
- package/dist/parser/matchers/reddit.js +43 -0
- package/dist/parser/matchers/rumble.js +32 -0
- package/dist/parser/matchers/snapchat.js +60 -0
- package/dist/parser/matchers/soundcloud.js +87 -0
- package/dist/parser/matchers/spotify.js +39 -0
- package/dist/parser/matchers/strava.js +31 -0
- package/dist/parser/matchers/streamable.js +59 -0
- package/dist/parser/matchers/telegram.js +34 -0
- package/dist/parser/matchers/tenor.js +34 -0
- package/dist/parser/matchers/threads.js +36 -0
- package/dist/parser/matchers/tiktok.js +25 -0
- package/dist/parser/matchers/truthsocial.js +34 -0
- package/dist/parser/matchers/tumblr.js +51 -0
- package/dist/parser/matchers/twitch.js +90 -0
- package/dist/parser/matchers/vimeo.js +71 -0
- package/dist/parser/matchers/x.js +50 -0
- package/dist/parser/matchers/youtube.js +123 -0
- package/dist/parser/platform.d.ts +13 -5
- package/dist/parser/platform.js +11 -1
- package/dist/parser/platforms/applemusic.js +6 -33
- package/dist/parser/platforms/applepodcasts.js +6 -32
- package/dist/parser/platforms/bluesky.js +7 -41
- package/dist/parser/platforms/dailymotion.js +6 -47
- package/dist/parser/platforms/facebook.js +7 -118
- package/dist/parser/platforms/flickr.js +7 -101
- package/dist/parser/platforms/giphy.js +6 -38
- package/dist/parser/platforms/imgur.js +7 -76
- package/dist/parser/platforms/instagram.js +6 -42
- package/dist/parser/platforms/kick.js +6 -48
- package/dist/parser/platforms/linkedin.js +7 -32
- package/dist/parser/platforms/pinterest.js +6 -32
- package/dist/parser/platforms/reddit.js +6 -44
- package/dist/parser/platforms/rumble.js +5 -32
- package/dist/parser/platforms/snapchat.js +5 -60
- package/dist/parser/platforms/soundcloud.js +6 -87
- package/dist/parser/platforms/spotify.js +6 -39
- package/dist/parser/platforms/strava.js +5 -30
- package/dist/parser/platforms/streamable.js +5 -59
- package/dist/parser/platforms/telegram.js +6 -35
- package/dist/parser/platforms/tenor.js +8 -36
- package/dist/parser/platforms/threads.js +6 -36
- package/dist/parser/platforms/tiktok.js +6 -25
- package/dist/parser/platforms/truthsocial.js +6 -35
- package/dist/parser/platforms/tumblr.js +7 -52
- package/dist/parser/platforms/twitch.js +6 -90
- package/dist/parser/platforms/vimeo.js +6 -71
- package/dist/parser/platforms/x.js +8 -49
- package/dist/parser/platforms/youtube.js +6 -122
- package/package.json +1 -1
|
@@ -1,52 +1,13 @@
|
|
|
1
|
-
import { sizeOf, withSize } from "../platform.js";
|
|
1
|
+
import { parserOf, sizeOf, withSize } from "../platform.js";
|
|
2
2
|
import { coerce, parseUrl } from "../url.js";
|
|
3
|
-
import
|
|
3
|
+
import "../frames.js";
|
|
4
|
+
import { CHANNEL, CLIP, COLLECTION, VIDEO, channel, clip, collection, twitchMatcher, vod } from "../matchers/twitch.js";
|
|
4
5
|
// src/parser/platforms/twitch.ts
|
|
5
|
-
const HOSTS = /* @__PURE__ */ new Set([
|
|
6
|
-
"twitch.tv",
|
|
7
|
-
"www.twitch.tv",
|
|
8
|
-
"m.twitch.tv"
|
|
9
|
-
]);
|
|
10
|
-
const CHANNEL = /^[A-Za-z0-9_]{3,25}$/;
|
|
11
|
-
const VIDEO = /^v?(\d{1,12})$/;
|
|
12
|
-
const COLLECTION = /^[A-Za-z0-9_-]{6,30}$/;
|
|
13
|
-
const CLIP = /^[A-Za-z0-9_-]{6,100}$/;
|
|
14
|
-
const TIME = /^(?:\d+h)?(?:\d+m)?(?:\d+s)?$/;
|
|
15
|
-
const RESERVED = /* @__PURE__ */ new Set([
|
|
16
|
-
"directory",
|
|
17
|
-
"videos",
|
|
18
|
-
"collections",
|
|
19
|
-
"settings",
|
|
20
|
-
"subscriptions",
|
|
21
|
-
"inventory",
|
|
22
|
-
"wallet",
|
|
23
|
-
"drops",
|
|
24
|
-
"search",
|
|
25
|
-
"downloads",
|
|
26
|
-
"jobs",
|
|
27
|
-
"turbo",
|
|
28
|
-
"p",
|
|
29
|
-
"login",
|
|
30
|
-
"signup"
|
|
31
|
-
]);
|
|
32
6
|
const PLAYER_OPTIONS = [
|
|
33
7
|
"autoplay",
|
|
34
8
|
"muted",
|
|
35
9
|
"time"
|
|
36
10
|
];
|
|
37
|
-
function target(path, id) {
|
|
38
|
-
return {
|
|
39
|
-
platform: "twitch",
|
|
40
|
-
kind: "video",
|
|
41
|
-
url: path,
|
|
42
|
-
id,
|
|
43
|
-
variant: "iframe"
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
const channel = (name) => target(`https://www.twitch.tv/${name.toLowerCase()}`, name.toLowerCase());
|
|
47
|
-
const vod = (id) => target(`https://www.twitch.tv/videos/${id}`, id);
|
|
48
|
-
const collection = (id) => target(`https://www.twitch.tv/collections/${id}`, id);
|
|
49
|
-
const clip = (slug) => target(`https://clips.twitch.tv/${slug}`, slug);
|
|
50
11
|
function playerOptions(query) {
|
|
51
12
|
const options = {};
|
|
52
13
|
for (const name of PLAYER_OPTIONS) {
|
|
@@ -64,44 +25,7 @@ function fromPlayer(url) {
|
|
|
64
25
|
const list = url.query.get("collection");
|
|
65
26
|
return list !== void 0 && COLLECTION.test(list) ? collection(list) : null;
|
|
66
27
|
}
|
|
67
|
-
|
|
68
|
-
if (url.host === "clips.twitch.tv") {
|
|
69
|
-
const slug = url.path.replace(/^\/|\/$/g, "");
|
|
70
|
-
return CLIP.test(slug) ? {
|
|
71
|
-
found: clip(slug),
|
|
72
|
-
options: {}
|
|
73
|
-
} : null;
|
|
74
|
-
}
|
|
75
|
-
if (!HOSTS.has(url.host)) return null;
|
|
76
|
-
const parts = url.path.replace(/^\/|\/$/g, "").split("/");
|
|
77
|
-
const [first = "", second, third] = parts;
|
|
78
|
-
if (parts.length === 2 && first === "videos") {
|
|
79
|
-
const [, id] = VIDEO.exec(second ?? "") ?? [];
|
|
80
|
-
if (id === void 0) return null;
|
|
81
|
-
const time = url.query.get("t");
|
|
82
|
-
return {
|
|
83
|
-
found: vod(id),
|
|
84
|
-
options: time !== void 0 && TIME.test(time) && time ? { time } : {}
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
if (parts.length === 2 && first === "collections") return COLLECTION.test(second ?? "") ? {
|
|
88
|
-
found: collection(second ?? ""),
|
|
89
|
-
options: {}
|
|
90
|
-
} : null;
|
|
91
|
-
if (parts.length === 3 && second === "clip") return CHANNEL.test(first) && CLIP.test(third ?? "") ? {
|
|
92
|
-
found: clip(third ?? ""),
|
|
93
|
-
options: {}
|
|
94
|
-
} : null;
|
|
95
|
-
if (parts.length === 1 && CHANNEL.test(first) && !RESERVED.has(first.toLowerCase())) return {
|
|
96
|
-
found: channel(first),
|
|
97
|
-
options: {}
|
|
98
|
-
};
|
|
99
|
-
return null;
|
|
100
|
-
}
|
|
101
|
-
const twitch = {
|
|
102
|
-
platform: "twitch",
|
|
103
|
-
name: "Twitch",
|
|
104
|
-
shapes: ["video iframe"],
|
|
28
|
+
const twitch = /* @__PURE__ */ parserOf(twitchMatcher, {
|
|
105
29
|
parse(root) {
|
|
106
30
|
if (root.tag !== "iframe") return null;
|
|
107
31
|
const src = parseUrl(root.attrs.get("src") ?? "");
|
|
@@ -117,14 +41,6 @@ const twitch = {
|
|
|
117
41
|
options: playerOptions(src.query)
|
|
118
42
|
}, sizeOf(root));
|
|
119
43
|
},
|
|
120
|
-
isOwnScript: () => false
|
|
121
|
-
|
|
122
|
-
const page = fromPage(url);
|
|
123
|
-
return page && {
|
|
124
|
-
...page.found,
|
|
125
|
-
options: page.options
|
|
126
|
-
};
|
|
127
|
-
},
|
|
128
|
-
ownsFrame: twitchFrame
|
|
129
|
-
};
|
|
44
|
+
isOwnScript: () => false
|
|
45
|
+
});
|
|
130
46
|
export { twitch };
|
|
@@ -1,46 +1,9 @@
|
|
|
1
|
-
import { sizeOf, unwrapRatio, withSize } from "../platform.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { parserOf, sizeOf, unwrapRatio, withSize } from "../platform.js";
|
|
2
|
+
import { parseUrl } from "../url.js";
|
|
3
|
+
import { HOSTS, fromPage, fromPlayer, vimeoMatcher } from "../matchers/vimeo.js";
|
|
4
4
|
// src/parser/platforms/vimeo.ts
|
|
5
|
-
const HOSTS = /* @__PURE__ */ new Set(["vimeo.com", "www.vimeo.com"]);
|
|
6
|
-
const VIDEO = "(\\d{1,12})";
|
|
7
|
-
const HASH = "([0-9a-f]{6,20})";
|
|
8
|
-
const PAGE_PATHS = [
|
|
9
|
-
new RegExp(`^/${VIDEO}(?:/${HASH})?/?$`),
|
|
10
|
-
new RegExp(`^/channels/[A-Za-z0-9_-]{1,64}/${VIDEO}/?$`),
|
|
11
|
-
new RegExp(`^/groups/[A-Za-z0-9_-]{1,64}/videos/${VIDEO}/?$`),
|
|
12
|
-
new RegExp(`^/showcase/\\d{1,12}/video/${VIDEO}/?$`)
|
|
13
|
-
];
|
|
14
|
-
const PLAYER_PATH = new RegExp(`^/video/${VIDEO}/?$`);
|
|
15
5
|
const WRAPPER = /^padding:\s*(\d{1,3}(?:\.\d{1,4})?)% 0 0 0;\s*position:\s*relative;?$/;
|
|
16
6
|
const SCRIPT = /^(?:https?:)?\/\/player\.vimeo\.com\/api\/player\.js$/;
|
|
17
|
-
const DROPPED = /* @__PURE__ */ new Set([
|
|
18
|
-
"h",
|
|
19
|
-
"app_id",
|
|
20
|
-
"player_id"
|
|
21
|
-
]);
|
|
22
|
-
const START = /^t=(\d+(?:\.\d+)?|(?:\d+h)?(?:\d+m)?(?:\d+s)?)$/;
|
|
23
|
-
function video(id, hash) {
|
|
24
|
-
return {
|
|
25
|
-
platform: "vimeo",
|
|
26
|
-
kind: "video",
|
|
27
|
-
url: `https://vimeo.com/${id}${hash ? `/${hash}` : ""}`,
|
|
28
|
-
id,
|
|
29
|
-
variant: "iframe"
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
function start(url) {
|
|
33
|
-
const [, time] = START.exec(url.fragment ?? "") ?? [];
|
|
34
|
-
return time ? { t: time } : {};
|
|
35
|
-
}
|
|
36
|
-
function fromPage(url) {
|
|
37
|
-
if (!url || !HOSTS.has(url.host)) return null;
|
|
38
|
-
for (const path of PAGE_PATHS) {
|
|
39
|
-
const [, id, hash] = path.exec(url.path) ?? [];
|
|
40
|
-
if (id !== void 0) return video(id, hash);
|
|
41
|
-
}
|
|
42
|
-
return null;
|
|
43
|
-
}
|
|
44
7
|
function isLink(node, test) {
|
|
45
8
|
if (node?.type !== "element" || node.tag !== "a" || node.attrs.size !== 1) return false;
|
|
46
9
|
const href = parseUrl(node.attrs.get("href") ?? "");
|
|
@@ -55,25 +18,7 @@ function isCredit(element, embed) {
|
|
|
55
18
|
const [title, from, author, on, home, stop, ...rest] = element.children;
|
|
56
19
|
return rest.length === 0 && isLink(title, (url) => fromPage(url)?.id === embed.id) && isText(from, "from") && isLink(author, () => true) && isText(on, "on") && isLink(home, (url) => url.path === "" || url.path === "/") && isText(stop, ".");
|
|
57
20
|
}
|
|
58
|
-
|
|
59
|
-
if (url?.host !== "player.vimeo.com") return null;
|
|
60
|
-
const [, id] = PLAYER_PATH.exec(url.path) ?? [];
|
|
61
|
-
if (id === void 0) return null;
|
|
62
|
-
const hash = url.query.get("h");
|
|
63
|
-
if (hash !== void 0 && !new RegExp(`^${HASH}$`).test(hash)) return null;
|
|
64
|
-
const options = Object.fromEntries([...url.query].filter(([key]) => !DROPPED.has(key)).map(([key, value]) => [key, coerce(value)]));
|
|
65
|
-
return {
|
|
66
|
-
...video(id, hash),
|
|
67
|
-
options: {
|
|
68
|
-
...options,
|
|
69
|
-
...start(url)
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
const vimeo = {
|
|
74
|
-
platform: "vimeo",
|
|
75
|
-
name: "Vimeo",
|
|
76
|
-
shapes: ["video iframe"],
|
|
21
|
+
const vimeo = /* @__PURE__ */ parserOf(vimeoMatcher, {
|
|
77
22
|
parse(root) {
|
|
78
23
|
const wrapped = unwrapRatio(root, WRAPPER);
|
|
79
24
|
const iframe = wrapped?.iframe ?? root;
|
|
@@ -82,16 +27,6 @@ const vimeo = {
|
|
|
82
27
|
return embed && withSize(embed, wrapped?.size ?? sizeOf(iframe));
|
|
83
28
|
},
|
|
84
29
|
isOwnScript: (src) => SCRIPT.test(src),
|
|
85
|
-
isOwnExtra: isCredit
|
|
86
|
-
|
|
87
|
-
const player = fromPlayer(url);
|
|
88
|
-
if (player) return player;
|
|
89
|
-
const page = fromPage(url);
|
|
90
|
-
return page && {
|
|
91
|
-
...page,
|
|
92
|
-
options: start(url)
|
|
93
|
-
};
|
|
94
|
-
},
|
|
95
|
-
ownsFrame: vimeoFrame
|
|
96
|
-
};
|
|
30
|
+
isOwnExtra: isCredit
|
|
31
|
+
});
|
|
97
32
|
export { vimeo };
|
|
@@ -1,17 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { attributeOptions } from "../platform.js";
|
|
3
|
-
import { coerce
|
|
1
|
+
import { hasClass, rebuild } from "../html.js";
|
|
2
|
+
import { attributeOptions, parserOf } from "../platform.js";
|
|
3
|
+
import { coerce } from "../url.js";
|
|
4
|
+
import { FALLBACK, lastStatus, xMatcher } from "../matchers/x.js";
|
|
4
5
|
// src/parser/platforms/x.ts
|
|
5
|
-
const HOSTS = /* @__PURE__ */ new Set([
|
|
6
|
-
"x.com",
|
|
7
|
-
"www.x.com",
|
|
8
|
-
"mobile.x.com",
|
|
9
|
-
"twitter.com",
|
|
10
|
-
"www.twitter.com",
|
|
11
|
-
"mobile.twitter.com"
|
|
12
|
-
]);
|
|
13
|
-
const STATUS_PATH = /^\/([A-Za-z0-9_]{1,15})\/status\/(\d{1,20})\/?$/;
|
|
14
|
-
const LINK_PATH = /^\/(?:([A-Za-z0-9_]{1,15})|i\/web)\/status\/(\d{1,20})(?:\/(?:photo|video)\/[1-4])?\/?$/;
|
|
15
6
|
const SCRIPT = /^(?:https?:)?\/\/platform\.(?:x|twitter)\.com\/widgets\.js$/;
|
|
16
7
|
const OPTION_ATTRIBUTES = [
|
|
17
8
|
["data-theme", "theme"],
|
|
@@ -23,35 +14,10 @@ const OPTION_ATTRIBUTES = [
|
|
|
23
14
|
["data-dnt", "dnt"],
|
|
24
15
|
["data-width", "width"]
|
|
25
16
|
];
|
|
26
|
-
const
|
|
27
|
-
["p", ["lang", "dir"]],
|
|
28
|
-
["a", ["href"]],
|
|
29
|
-
["br", []]
|
|
30
|
-
]);
|
|
31
|
-
function post(url, path = STATUS_PATH) {
|
|
32
|
-
if (!url || !HOSTS.has(url.host)) return null;
|
|
33
|
-
const [, user = "i", id] = path.exec(url.path) ?? [];
|
|
34
|
-
if (id === void 0) return null;
|
|
35
|
-
return {
|
|
36
|
-
platform: "x",
|
|
37
|
-
kind: "post",
|
|
38
|
-
url: `https://x.com/${user}/status/${id}`,
|
|
39
|
-
id,
|
|
40
|
-
variant: "sdk"
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
function fallbackNamesPost(html, id) {
|
|
44
|
-
const [root] = parseHtml(`<blockquote class="twitter-tweet">${html}</blockquote>`) ?? [];
|
|
45
|
-
return root?.type === "element" && x.parse(root)?.id === id;
|
|
46
|
-
}
|
|
47
|
-
const x = {
|
|
48
|
-
platform: "x",
|
|
49
|
-
name: "X",
|
|
50
|
-
shapes: ["post sdk"],
|
|
51
|
-
trustsFallback: (html, embed) => rebuildsAs(html, FALLBACK) && fallbackNamesPost(html, embed.id),
|
|
17
|
+
const x = /* @__PURE__ */ parserOf(xMatcher, {
|
|
52
18
|
parse(root) {
|
|
53
19
|
if (root.tag !== "blockquote" || !(hasClass(root, "twitter-tweet") || hasClass(root, "twitter-video"))) return null;
|
|
54
|
-
const status =
|
|
20
|
+
const status = lastStatus(root.children);
|
|
55
21
|
if (!status) return null;
|
|
56
22
|
return {
|
|
57
23
|
...status,
|
|
@@ -59,13 +25,6 @@ const x = {
|
|
|
59
25
|
fallbackHtml: rebuild(root.children, FALLBACK)
|
|
60
26
|
};
|
|
61
27
|
},
|
|
62
|
-
isOwnScript: (src) => SCRIPT.test(src)
|
|
63
|
-
|
|
64
|
-
const status = post(url, LINK_PATH);
|
|
65
|
-
return status && {
|
|
66
|
-
...status,
|
|
67
|
-
options: {}
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
};
|
|
28
|
+
isOwnScript: (src) => SCRIPT.test(src)
|
|
29
|
+
});
|
|
71
30
|
export { x };
|
|
@@ -1,78 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { parserOf, sizeOf, withSize } from "../platform.js";
|
|
2
2
|
import { coerce, parseUrl } from "../url.js";
|
|
3
|
-
import { YOUTUBE_HOSTS, YOUTUBE_NOCOOKIE_HOSTS
|
|
3
|
+
import { YOUTUBE_HOSTS, YOUTUBE_NOCOOKIE_HOSTS } from "../frames.js";
|
|
4
|
+
import { fromEmbed, startOf, youtubeMatcher } from "../matchers/youtube.js";
|
|
4
5
|
// src/parser/platforms/youtube.ts
|
|
5
|
-
const
|
|
6
|
-
const VIDEO_ID = /^(?!videoseries|live_stream)[A-Za-z0-9_-]{11}$/;
|
|
7
|
-
const EMBED_PATH = /^\/embed\/(?:(videoseries|live_stream)|([A-Za-z0-9_-]{11}))\/?$/;
|
|
8
|
-
const URL_PATHS = /^\/(shorts|live)\/((?!videoseries|live_stream)[A-Za-z0-9_-]{11})\/?$/;
|
|
9
|
-
const SHORT_LINK_PATH = /^\/([A-Za-z0-9_-]{11})\/?$/;
|
|
10
|
-
const PLAYLIST_ID = /^[A-Za-z0-9_-]{10,64}$/;
|
|
11
|
-
const CHANNEL_ID = /^UC[A-Za-z0-9_-]{22}$/;
|
|
12
|
-
const CHANNEL_LIVE_PATH = /^\/channel\/(UC[A-Za-z0-9_-]{22})\/live\/?$/;
|
|
13
|
-
const DURATION = /^(?:(\d{1,5})h)?(?:(\d{1,6})m)?(?:(\d{1,7})s?)?$/;
|
|
14
|
-
const FRAGMENT_START = /^t=(.+)$/;
|
|
15
|
-
/** `90`, `90s`, `1m30s`, `1h2m3s` → seconds. */
|
|
16
|
-
function seconds(value) {
|
|
17
|
-
if (value === void 0 || value === "") return void 0;
|
|
18
|
-
const match = DURATION.exec(value);
|
|
19
|
-
if (!match) return void 0;
|
|
20
|
-
const [, hours = "0", minutes = "0", secs = "0"] = match;
|
|
21
|
-
return Number(hours) * 3600 + Number(minutes) * 60 + Number(secs);
|
|
22
|
-
}
|
|
23
|
-
/** `start` wins over `t`; `t` is converted, because the embed player only reads `start`. */
|
|
24
|
-
function startOf(query) {
|
|
25
|
-
return seconds(query.get("start")) ?? seconds(query.get("t"));
|
|
26
|
-
}
|
|
27
|
-
function found(id, url) {
|
|
28
|
-
return {
|
|
29
|
-
platform: "youtube",
|
|
30
|
-
kind: "video",
|
|
31
|
-
url,
|
|
32
|
-
id,
|
|
33
|
-
variant: "iframe"
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
function video(id, shorts = false) {
|
|
37
|
-
return found(id, shorts ? `${BASE}/shorts/${id}` : `${BASE}/watch?v=${id}`);
|
|
38
|
-
}
|
|
39
|
-
function playlist(id) {
|
|
40
|
-
return id !== void 0 && PLAYLIST_ID.test(id) ? found(id, `${BASE}/playlist?list=${id}`) : null;
|
|
41
|
-
}
|
|
42
|
-
function live(id) {
|
|
43
|
-
return id !== void 0 && CHANNEL_ID.test(id) ? found(id, `${BASE}/channel/${id}/live`) : null;
|
|
44
|
-
}
|
|
45
|
-
/** `key` is the query parameter that names the content, for a playlist or a channel's stream. */
|
|
46
|
-
function fromEmbed(url) {
|
|
47
|
-
const [, series, id] = EMBED_PATH.exec(url.path) ?? [];
|
|
48
|
-
if (id !== void 0) return { found: video(id) };
|
|
49
|
-
if (series === "videoseries") {
|
|
50
|
-
const list = playlist(url.query.get("list"));
|
|
51
|
-
return list && {
|
|
52
|
-
found: list,
|
|
53
|
-
key: "list"
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
if (series === "live_stream") {
|
|
57
|
-
const stream = live(url.query.get("channel"));
|
|
58
|
-
return stream && {
|
|
59
|
-
found: stream,
|
|
60
|
-
key: "channel"
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
return null;
|
|
64
|
-
}
|
|
65
|
-
function urlOptions(url, nocookie) {
|
|
66
|
-
const start = startOf(url.query) ?? seconds(FRAGMENT_START.exec(url.fragment ?? "")?.[1]);
|
|
67
|
-
return {
|
|
68
|
-
...start === void 0 ? {} : { start },
|
|
69
|
-
...nocookie ? { nocookie: true } : {}
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
const youtube = {
|
|
73
|
-
platform: "youtube",
|
|
74
|
-
name: "YouTube",
|
|
75
|
-
shapes: ["video iframe"],
|
|
6
|
+
const youtube = /* @__PURE__ */ parserOf(youtubeMatcher, {
|
|
76
7
|
parse(root) {
|
|
77
8
|
if (root.tag !== "iframe") return null;
|
|
78
9
|
const src = parseUrl(root.attrs.get("src") ?? "");
|
|
@@ -90,53 +21,6 @@ const youtube = {
|
|
|
90
21
|
options
|
|
91
22
|
}, sizeOf(root));
|
|
92
23
|
},
|
|
93
|
-
isOwnScript: () => false
|
|
94
|
-
|
|
95
|
-
if (url.host === "youtu.be") {
|
|
96
|
-
const [, id] = SHORT_LINK_PATH.exec(url.path) ?? [];
|
|
97
|
-
return id === void 0 ? null : {
|
|
98
|
-
...video(id),
|
|
99
|
-
options: urlOptions(url, false)
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
const nocookie = YOUTUBE_NOCOOKIE_HOSTS.has(url.host);
|
|
103
|
-
if (!nocookie && !YOUTUBE_HOSTS.has(url.host)) return null;
|
|
104
|
-
const options = urlOptions(url, nocookie);
|
|
105
|
-
if (underPath(url.path, "/embed")) {
|
|
106
|
-
const player = fromEmbed(url);
|
|
107
|
-
return player && {
|
|
108
|
-
...player.found,
|
|
109
|
-
options
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
if (nocookie) return null;
|
|
113
|
-
if (/^\/watch\/?$/.test(url.path)) {
|
|
114
|
-
const id = url.query.get("v");
|
|
115
|
-
return id !== void 0 && VIDEO_ID.test(id) ? {
|
|
116
|
-
...video(id),
|
|
117
|
-
options
|
|
118
|
-
} : null;
|
|
119
|
-
}
|
|
120
|
-
if (/^\/playlist\/?$/.test(url.path)) {
|
|
121
|
-
const list = playlist(url.query.get("list"));
|
|
122
|
-
return list && {
|
|
123
|
-
...list,
|
|
124
|
-
options
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
const [, channel] = CHANNEL_LIVE_PATH.exec(url.path) ?? [];
|
|
128
|
-
const stream = live(channel);
|
|
129
|
-
if (stream) return {
|
|
130
|
-
...stream,
|
|
131
|
-
options
|
|
132
|
-
};
|
|
133
|
-
const [, kind, id] = URL_PATHS.exec(url.path) ?? [];
|
|
134
|
-
if (kind === void 0 || id === void 0) return null;
|
|
135
|
-
return {
|
|
136
|
-
...video(id, kind === "shorts"),
|
|
137
|
-
options
|
|
138
|
-
};
|
|
139
|
-
},
|
|
140
|
-
ownsFrame: youtubeFrame
|
|
141
|
-
};
|
|
24
|
+
isOwnScript: () => false
|
|
25
|
+
});
|
|
142
26
|
export { youtube };
|