social-embeds 0.8.0 → 0.8.1
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 +55 -48
- package/dist/components/hooks.js +3 -1
- package/dist/components/script-embed.js +8 -7
- package/dist/core/drivers.js +8 -1
- package/dist/core/plans/youtube.js +15 -3
- package/dist/element.d.ts +1 -1
- package/dist/element.js +1 -1
- package/dist/loader/load-script.js +2 -0
- package/dist/parser/frames.js +70 -0
- package/dist/parser/iframe.js +2 -2
- package/dist/parser/parse-embed.js +2 -2
- package/dist/parser/platforms/applemusic.js +3 -3
- package/dist/parser/platforms/applepodcasts.js +3 -3
- package/dist/parser/platforms/dailymotion.js +6 -8
- package/dist/parser/platforms/facebook.js +5 -9
- package/dist/parser/platforms/giphy.js +6 -6
- package/dist/parser/platforms/kick.js +4 -4
- package/dist/parser/platforms/linkedin.js +4 -4
- package/dist/parser/platforms/pinterest.js +3 -3
- package/dist/parser/platforms/reddit.js +3 -2
- package/dist/parser/platforms/rumble.js +3 -2
- package/dist/parser/platforms/soundcloud.js +3 -3
- package/dist/parser/platforms/spotify.js +4 -4
- package/dist/parser/platforms/streamable.js +3 -2
- package/dist/parser/platforms/tenor.js +3 -2
- package/dist/parser/platforms/tiktok.js +6 -6
- package/dist/parser/platforms/truthsocial.js +2 -1
- package/dist/parser/platforms/tumblr.js +4 -2
- package/dist/parser/platforms/twitch.js +6 -7
- package/dist/parser/platforms/vimeo.js +31 -12
- package/dist/parser/platforms/x.js +1 -1
- package/dist/parser/platforms/youtube.js +73 -23
- package/dist/parser/url.js +1 -1
- package/package.json +1 -1
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { sizeOf, underPath, withSize } from "../platform.js";
|
|
2
2
|
import { coerce, parseUrl } from "../url.js";
|
|
3
|
+
import { YOUTUBE_HOSTS, YOUTUBE_NOCOOKIE_HOSTS, youtubeFrame } from "../frames.js";
|
|
3
4
|
// src/parser/platforms/youtube.ts
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
]);
|
|
9
|
-
const NOCOOKIE_HOSTS = /* @__PURE__ */ new Set(["youtube-nocookie.com", "www.youtube-nocookie.com"]);
|
|
10
|
-
const VIDEO_ID = /^(?!videoseries)[A-Za-z0-9_-]{11}$/;
|
|
11
|
-
const EMBED_PATH = /^\/embed\/((?!videoseries)[A-Za-z0-9_-]{11})\/?$/;
|
|
12
|
-
const URL_PATHS = /^\/(shorts|embed|live)\/((?!videoseries)[A-Za-z0-9_-]{11})\/?$/;
|
|
5
|
+
const BASE = "https://www.youtube.com";
|
|
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})\/?$/;
|
|
13
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\/?$/;
|
|
14
13
|
const DURATION = /^(?:(\d{1,5})h)?(?:(\d{1,6})m)?(?:(\d{1,7})s?)?$/;
|
|
14
|
+
const FRAGMENT_START = /^t=(.+)$/;
|
|
15
15
|
/** `90`, `90s`, `1m30s`, `1h2m3s` → seconds. */
|
|
16
16
|
function seconds(value) {
|
|
17
17
|
if (value === void 0 || value === "") return void 0;
|
|
@@ -24,17 +24,46 @@ function seconds(value) {
|
|
|
24
24
|
function startOf(query) {
|
|
25
25
|
return seconds(query.get("start")) ?? seconds(query.get("t"));
|
|
26
26
|
}
|
|
27
|
-
function
|
|
27
|
+
function found(id, url) {
|
|
28
28
|
return {
|
|
29
29
|
platform: "youtube",
|
|
30
30
|
kind: "video",
|
|
31
|
-
url
|
|
31
|
+
url,
|
|
32
32
|
id,
|
|
33
33
|
variant: "iframe"
|
|
34
34
|
};
|
|
35
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
|
+
}
|
|
36
65
|
function urlOptions(url, nocookie) {
|
|
37
|
-
const start = startOf(url.query);
|
|
66
|
+
const start = startOf(url.query) ?? seconds(FRAGMENT_START.exec(url.fragment ?? "")?.[1]);
|
|
38
67
|
return {
|
|
39
68
|
...start === void 0 ? {} : { start },
|
|
40
69
|
...nocookie ? { nocookie: true } : {}
|
|
@@ -45,17 +74,17 @@ const youtube = {
|
|
|
45
74
|
parse(root) {
|
|
46
75
|
if (root.tag !== "iframe") return null;
|
|
47
76
|
const src = parseUrl(root.attrs.get("src") ?? "");
|
|
48
|
-
const nocookie = src !== null &&
|
|
77
|
+
const nocookie = src !== null && YOUTUBE_NOCOOKIE_HOSTS.has(src.host);
|
|
49
78
|
if (!src || !(nocookie || YOUTUBE_HOSTS.has(src.host))) return null;
|
|
50
|
-
const
|
|
51
|
-
if (
|
|
52
|
-
const entries = [...src.query].filter(([key]) => key !== "t").map(([key, value]) => [key, coerce(value)]);
|
|
79
|
+
const player = fromEmbed(src);
|
|
80
|
+
if (!player) return null;
|
|
81
|
+
const entries = [...src.query].filter(([key]) => key !== "t" && key !== player.key).map(([key, value]) => [key, coerce(value)]);
|
|
53
82
|
const options = Object.fromEntries(entries);
|
|
54
83
|
const start = startOf(src.query);
|
|
55
84
|
if (start !== void 0) options.start = start;
|
|
56
85
|
if (nocookie) options.nocookie = true;
|
|
57
86
|
return withSize({
|
|
58
|
-
...
|
|
87
|
+
...player.found,
|
|
59
88
|
options
|
|
60
89
|
}, sizeOf(root));
|
|
61
90
|
},
|
|
@@ -68,23 +97,44 @@ const youtube = {
|
|
|
68
97
|
options: urlOptions(url, false)
|
|
69
98
|
};
|
|
70
99
|
}
|
|
71
|
-
const nocookie =
|
|
100
|
+
const nocookie = YOUTUBE_NOCOOKIE_HOSTS.has(url.host);
|
|
72
101
|
if (!nocookie && !YOUTUBE_HOSTS.has(url.host)) return null;
|
|
73
|
-
|
|
102
|
+
const options = urlOptions(url, nocookie);
|
|
103
|
+
if (underPath(url.path, "/embed")) {
|
|
104
|
+
const player = fromEmbed(url);
|
|
105
|
+
return player && {
|
|
106
|
+
...player.found,
|
|
107
|
+
options
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
if (nocookie) return null;
|
|
111
|
+
if (/^\/watch\/?$/.test(url.path)) {
|
|
74
112
|
const id = url.query.get("v");
|
|
75
113
|
return id !== void 0 && VIDEO_ID.test(id) ? {
|
|
76
114
|
...video(id),
|
|
77
|
-
options
|
|
115
|
+
options
|
|
78
116
|
} : null;
|
|
79
117
|
}
|
|
118
|
+
if (/^\/playlist\/?$/.test(url.path)) {
|
|
119
|
+
const list = playlist(url.query.get("list"));
|
|
120
|
+
return list && {
|
|
121
|
+
...list,
|
|
122
|
+
options
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
const [, channel] = CHANNEL_LIVE_PATH.exec(url.path) ?? [];
|
|
126
|
+
const stream = live(channel);
|
|
127
|
+
if (stream) return {
|
|
128
|
+
...stream,
|
|
129
|
+
options
|
|
130
|
+
};
|
|
80
131
|
const [, kind, id] = URL_PATHS.exec(url.path) ?? [];
|
|
81
132
|
if (kind === void 0 || id === void 0) return null;
|
|
82
|
-
if (nocookie && kind !== "embed") return null;
|
|
83
133
|
return {
|
|
84
134
|
...video(id, kind === "shorts"),
|
|
85
|
-
options
|
|
135
|
+
options
|
|
86
136
|
};
|
|
87
137
|
},
|
|
88
|
-
ownsFrame:
|
|
138
|
+
ownsFrame: youtubeFrame
|
|
89
139
|
};
|
|
90
140
|
export { youtube };
|
package/dist/parser/url.js
CHANGED
|
@@ -6,7 +6,7 @@ function parseUrl(input) {
|
|
|
6
6
|
if (!match) return null;
|
|
7
7
|
const [, host = "", path = "", search = "", fragment] = match;
|
|
8
8
|
const query = /* @__PURE__ */ new Map();
|
|
9
|
-
for (const pair of search.split("&")) {
|
|
9
|
+
for (const pair of search.replaceAll("&", "&").split("&")) {
|
|
10
10
|
if (pair === "") continue;
|
|
11
11
|
const eq = pair.indexOf("=");
|
|
12
12
|
const key = decodeComponent(eq === -1 ? pair : pair.slice(0, eq));
|