social-embeds 0.9.2 → 0.9.3
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/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 +10 -4
- package/dist/parser/platforms/applemusic.js +4 -30
- package/dist/parser/platforms/applepodcasts.js +4 -29
- package/dist/parser/platforms/bluesky.js +4 -38
- package/dist/parser/platforms/dailymotion.js +4 -44
- package/dist/parser/platforms/facebook.js +5 -115
- package/dist/parser/platforms/flickr.js +5 -98
- package/dist/parser/platforms/giphy.js +4 -35
- package/dist/parser/platforms/imgur.js +4 -73
- package/dist/parser/platforms/instagram.js +4 -40
- package/dist/parser/platforms/kick.js +4 -45
- package/dist/parser/platforms/linkedin.js +4 -28
- package/dist/parser/platforms/pinterest.js +4 -29
- package/dist/parser/platforms/reddit.js +3 -40
- package/dist/parser/platforms/rumble.js +3 -29
- package/dist/parser/platforms/snapchat.js +3 -57
- package/dist/parser/platforms/soundcloud.js +4 -84
- package/dist/parser/platforms/spotify.js +4 -36
- package/dist/parser/platforms/strava.js +3 -28
- package/dist/parser/platforms/streamable.js +3 -56
- package/dist/parser/platforms/telegram.js +3 -31
- package/dist/parser/platforms/tenor.js +5 -32
- package/dist/parser/platforms/threads.js +4 -33
- package/dist/parser/platforms/tiktok.js +4 -22
- package/dist/parser/platforms/truthsocial.js +3 -31
- package/dist/parser/platforms/tumblr.js +3 -48
- package/dist/parser/platforms/twitch.js +4 -87
- package/dist/parser/platforms/vimeo.js +4 -68
- package/dist/parser/platforms/x.js +6 -46
- package/dist/parser/platforms/youtube.js +5 -120
- package/package.json +1 -1
|
@@ -1,30 +1,9 @@
|
|
|
1
1
|
import { sizeOf, unwrapRatio, withSize } from "../platform.js";
|
|
2
2
|
import { parseUrl } from "../url.js";
|
|
3
|
-
import { GIPHY_PAGE_HOSTS
|
|
3
|
+
import { GIPHY_PAGE_HOSTS } from "../frames.js";
|
|
4
|
+
import { EMBED_PATH, PAGE_PATH, gif, giphyMatcher } from "../matchers/giphy.js";
|
|
4
5
|
// src/parser/platforms/giphy.ts
|
|
5
|
-
const ID = "([A-Za-z0-9]{6,40})";
|
|
6
|
-
const PAGE_PATH = new RegExp(`^/(?:gifs|stickers)/(?:[A-Za-z0-9-]{0,200}-)?${ID}/?$`);
|
|
7
|
-
const EMBED_PATH = new RegExp(`^/embed/${ID}/?$`);
|
|
8
|
-
const MEDIA_HOST = /^(?:media\d?|i)\.giphy\.com$/;
|
|
9
|
-
const FILE_TYPE = "\\.(?:gif|webp|mp4)";
|
|
10
|
-
const MEDIA_PATH = new RegExp(`^/media/(?:v1\\.[A-Za-z0-9_-]{1,500}/)?${ID}/[A-Za-z0-9_-]{1,40}${FILE_TYPE}$`);
|
|
11
|
-
const SHORT_MEDIA_PATH = new RegExp(`^/${ID}${FILE_TYPE}$`);
|
|
12
6
|
const WRAPPER = /^width:\s*100%;\s*height:\s*0;\s*padding-bottom:\s*(\d{1,3}(?:\.\d{1,4})?)%;\s*position:\s*relative;?$/;
|
|
13
|
-
function gif(id) {
|
|
14
|
-
return {
|
|
15
|
-
platform: "giphy",
|
|
16
|
-
kind: "video",
|
|
17
|
-
url: `https://giphy.com/gifs/${id}`,
|
|
18
|
-
id,
|
|
19
|
-
variant: "iframe"
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
function idOf(url) {
|
|
23
|
-
if (!url) return void 0;
|
|
24
|
-
if (GIPHY_PAGE_HOSTS.has(url.host)) return (PAGE_PATH.exec(url.path) ?? EMBED_PATH.exec(url.path))?.[1];
|
|
25
|
-
if (!MEDIA_HOST.test(url.host)) return void 0;
|
|
26
|
-
return (MEDIA_PATH.exec(url.path) ?? (url.host === "i.giphy.com" ? SHORT_MEDIA_PATH.exec(url.path) : null))?.[1];
|
|
27
|
-
}
|
|
28
7
|
function fromIframe(iframe) {
|
|
29
8
|
if (iframe.tag !== "iframe") return null;
|
|
30
9
|
const src = parseUrl(iframe.attrs.get("src") ?? "");
|
|
@@ -43,9 +22,7 @@ function isCredit(element, embed) {
|
|
|
43
22
|
return more.length === 0 && text?.type === "text" && text.raw.trim() === "via GIPHY";
|
|
44
23
|
}
|
|
45
24
|
const giphy = {
|
|
46
|
-
|
|
47
|
-
name: "Giphy",
|
|
48
|
-
shapes: ["video iframe"],
|
|
25
|
+
...giphyMatcher,
|
|
49
26
|
parse(root) {
|
|
50
27
|
const wrapped = unwrapRatio(root, WRAPPER);
|
|
51
28
|
const iframe = wrapped?.iframe ?? root;
|
|
@@ -57,14 +34,6 @@ const giphy = {
|
|
|
57
34
|
}, wrapped?.size ?? sizeOf(iframe));
|
|
58
35
|
},
|
|
59
36
|
isOwnScript: () => false,
|
|
60
|
-
isOwnExtra: isCredit
|
|
61
|
-
match(url) {
|
|
62
|
-
const id = idOf(url);
|
|
63
|
-
return id === void 0 ? null : {
|
|
64
|
-
...gif(id),
|
|
65
|
-
options: {}
|
|
66
|
-
};
|
|
67
|
-
},
|
|
68
|
-
ownsFrame: giphyFrame
|
|
37
|
+
isOwnExtra: isCredit
|
|
69
38
|
};
|
|
70
39
|
export { giphy };
|
|
@@ -1,67 +1,8 @@
|
|
|
1
|
-
import { hasClass, rebuild
|
|
1
|
+
import { hasClass, rebuild } from "../html.js";
|
|
2
|
+
import { FALLBACK, HASH, image, imgurMatcher, post } from "../matchers/imgur.js";
|
|
2
3
|
// src/parser/platforms/imgur.ts
|
|
3
|
-
const HOSTS = /* @__PURE__ */ new Set([
|
|
4
|
-
"imgur.com",
|
|
5
|
-
"www.imgur.com",
|
|
6
|
-
"m.imgur.com"
|
|
7
|
-
]);
|
|
8
|
-
const HASH = "([A-Za-z0-9]{5,7})";
|
|
9
4
|
const DATA_ID = new RegExp(`^(a/)?${HASH}$`);
|
|
10
|
-
const ALBUM_PATH = new RegExp(`^/a/${HASH}/?$`);
|
|
11
|
-
const GALLERY_PATH = new RegExp(`^/gallery/(?:[A-Za-z0-9-]{1,200}-)?${HASH}/?$`);
|
|
12
|
-
const IMAGE_PATH = new RegExp(`^/${HASH}/?$`);
|
|
13
|
-
const FILE_PATH = new RegExp(`^/${HASH}\\.(?:jpe?g|png|gif|gifv|mp4|webp)$`);
|
|
14
5
|
const SCRIPT = /^(?:https?:)?\/\/s\.imgur\.com\/min\/embed\.js$/;
|
|
15
|
-
const NOT_IMAGES = /* @__PURE__ */ new Set([
|
|
16
|
-
"about",
|
|
17
|
-
"apps",
|
|
18
|
-
"blog",
|
|
19
|
-
"help",
|
|
20
|
-
"jobs",
|
|
21
|
-
"login",
|
|
22
|
-
"press",
|
|
23
|
-
"privacy",
|
|
24
|
-
"random",
|
|
25
|
-
"search",
|
|
26
|
-
"signin",
|
|
27
|
-
"signup",
|
|
28
|
-
"terms",
|
|
29
|
-
"tools",
|
|
30
|
-
"upload",
|
|
31
|
-
"account",
|
|
32
|
-
"contact",
|
|
33
|
-
"emerald",
|
|
34
|
-
"explore",
|
|
35
|
-
"gallery",
|
|
36
|
-
"hot",
|
|
37
|
-
"new",
|
|
38
|
-
"rules",
|
|
39
|
-
"user"
|
|
40
|
-
]);
|
|
41
|
-
const FALLBACK = /* @__PURE__ */ new Map([["a", [{
|
|
42
|
-
name: "href",
|
|
43
|
-
value: /^https:\/\/(?:www\.)?imgur\.com\//
|
|
44
|
-
}]]]);
|
|
45
|
-
function post(id) {
|
|
46
|
-
return {
|
|
47
|
-
platform: "imgur",
|
|
48
|
-
kind: "post",
|
|
49
|
-
url: `https://imgur.com/${id}`,
|
|
50
|
-
id,
|
|
51
|
-
variant: "iframe"
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
function image(hash) {
|
|
55
|
-
return hash === void 0 || NOT_IMAGES.has(hash.toLowerCase()) ? void 0 : hash;
|
|
56
|
-
}
|
|
57
|
-
function idOf(url) {
|
|
58
|
-
if (!url) return void 0;
|
|
59
|
-
if (url.host === "i.imgur.com") return image(FILE_PATH.exec(url.path)?.[1]);
|
|
60
|
-
if (!HOSTS.has(url.host)) return void 0;
|
|
61
|
-
const album = (ALBUM_PATH.exec(url.path) ?? GALLERY_PATH.exec(url.path))?.[1];
|
|
62
|
-
if (album !== void 0) return `a/${album}`;
|
|
63
|
-
return image(IMAGE_PATH.exec(url.path)?.[1]);
|
|
64
|
-
}
|
|
65
6
|
function withScheme(nodes) {
|
|
66
7
|
return nodes.map((node) => {
|
|
67
8
|
if (node.type !== "element") return node;
|
|
@@ -79,10 +20,7 @@ function falseOption(root, attribute) {
|
|
|
79
20
|
return root.attrs.get(attribute) === "false";
|
|
80
21
|
}
|
|
81
22
|
const imgur = {
|
|
82
|
-
|
|
83
|
-
name: "Imgur",
|
|
84
|
-
shapes: ["post iframe"],
|
|
85
|
-
trustsFallback: (html) => rebuildsAs(html, FALLBACK),
|
|
23
|
+
...imgurMatcher,
|
|
86
24
|
parse(root) {
|
|
87
25
|
if (root.tag !== "blockquote" || !hasClass(root, "imgur-embed-pub")) return null;
|
|
88
26
|
const id = root.attrs.get("data-id") ?? "";
|
|
@@ -97,13 +35,6 @@ const imgur = {
|
|
|
97
35
|
fallbackHtml: rebuild(withScheme(root.children), FALLBACK)
|
|
98
36
|
};
|
|
99
37
|
},
|
|
100
|
-
isOwnScript: (src) => SCRIPT.test(src)
|
|
101
|
-
match(url) {
|
|
102
|
-
const id = idOf(url);
|
|
103
|
-
return id === void 0 ? null : {
|
|
104
|
-
...post(id),
|
|
105
|
-
options: {}
|
|
106
|
-
};
|
|
107
|
-
}
|
|
38
|
+
isOwnScript: (src) => SCRIPT.test(src)
|
|
108
39
|
};
|
|
109
40
|
export { imgur };
|
|
@@ -1,39 +1,10 @@
|
|
|
1
|
-
import { descendants, hasClass, rebuild
|
|
1
|
+
import { descendants, hasClass, rebuild } from "../html.js";
|
|
2
2
|
import { coerce, parseUrl } from "../url.js";
|
|
3
|
+
import { FALLBACK, instagramMatcher, post } from "../matchers/instagram.js";
|
|
3
4
|
// src/parser/platforms/instagram.ts
|
|
4
|
-
const HOSTS = /* @__PURE__ */ new Set(["instagram.com", "www.instagram.com"]);
|
|
5
|
-
const POST_PATH = /^\/(?:([A-Za-z0-9._]{1,30})\/)?(p|reel|reels|tv)\/([A-Za-z0-9_-]{1,64})\/?$/;
|
|
6
|
-
const TYPES = /* @__PURE__ */ new Set([
|
|
7
|
-
"p",
|
|
8
|
-
"reel",
|
|
9
|
-
"reels",
|
|
10
|
-
"tv"
|
|
11
|
-
]);
|
|
12
|
-
const USER_POST_TYPES = /* @__PURE__ */ new Set(["p", "reel"]);
|
|
13
5
|
const SCRIPT = /^(?:https?:)?\/\/www\.instagram\.com\/embed\.js$/;
|
|
14
|
-
const FALLBACK = /* @__PURE__ */ new Map([
|
|
15
|
-
["div", []],
|
|
16
|
-
["a", ["href"]],
|
|
17
|
-
["p", []]
|
|
18
|
-
]);
|
|
19
|
-
function post(url) {
|
|
20
|
-
if (!url || !HOSTS.has(url.host)) return null;
|
|
21
|
-
const [, user, type, code] = POST_PATH.exec(url.path) ?? [];
|
|
22
|
-
if (type === void 0 || code === void 0) return null;
|
|
23
|
-
if (user !== void 0 && (TYPES.has(user) || !USER_POST_TYPES.has(type))) return null;
|
|
24
|
-
return {
|
|
25
|
-
platform: "instagram",
|
|
26
|
-
kind: "post",
|
|
27
|
-
url: `https://www.instagram.com/${type === "reels" ? "reel" : type}/${code}/`,
|
|
28
|
-
id: code,
|
|
29
|
-
variant: "sdk"
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
6
|
const instagram = {
|
|
33
|
-
|
|
34
|
-
name: "Instagram",
|
|
35
|
-
shapes: ["post sdk"],
|
|
36
|
-
trustsFallback: (html) => rebuildsAs(html, FALLBACK),
|
|
7
|
+
...instagramMatcher,
|
|
37
8
|
parse(root) {
|
|
38
9
|
if (root.tag !== "blockquote" || !hasClass(root, "instagram-media")) return null;
|
|
39
10
|
const permalink = root.attrs.get("data-instgrm-permalink");
|
|
@@ -49,13 +20,6 @@ const instagram = {
|
|
|
49
20
|
fallbackHtml: rebuild(root.children, FALLBACK)
|
|
50
21
|
};
|
|
51
22
|
},
|
|
52
|
-
isOwnScript: (src) => SCRIPT.test(src)
|
|
53
|
-
match(url) {
|
|
54
|
-
const found = post(url);
|
|
55
|
-
return found && {
|
|
56
|
-
...found,
|
|
57
|
-
options: {}
|
|
58
|
-
};
|
|
59
|
-
}
|
|
23
|
+
isOwnScript: (src) => SCRIPT.test(src)
|
|
60
24
|
};
|
|
61
25
|
export { instagram };
|
|
@@ -1,44 +1,11 @@
|
|
|
1
1
|
import { sizeOf, withSize } from "../platform.js";
|
|
2
2
|
import { coerce, parseUrl } from "../url.js";
|
|
3
|
-
import { KICK_PLAYER_HOSTS
|
|
3
|
+
import { KICK_PLAYER_HOSTS } from "../frames.js";
|
|
4
|
+
import { channel, kickMatcher } from "../matchers/kick.js";
|
|
4
5
|
// src/parser/platforms/kick.ts
|
|
5
|
-
const PAGE_HOSTS = /* @__PURE__ */ new Set(["kick.com", "www.kick.com"]);
|
|
6
|
-
const CHANNEL = /^\/([A-Za-z0-9_-]{1,32})\/?$/;
|
|
7
|
-
const NOT_CHANNELS = /* @__PURE__ */ new Set([
|
|
8
|
-
"browse",
|
|
9
|
-
"categories",
|
|
10
|
-
"category",
|
|
11
|
-
"clips",
|
|
12
|
-
"video",
|
|
13
|
-
"videos",
|
|
14
|
-
"following",
|
|
15
|
-
"search",
|
|
16
|
-
"settings",
|
|
17
|
-
"dashboard",
|
|
18
|
-
"subscriptions",
|
|
19
|
-
"privacy-policy",
|
|
20
|
-
"terms-of-service",
|
|
21
|
-
"community-guidelines",
|
|
22
|
-
"help"
|
|
23
|
-
]);
|
|
24
6
|
const KEPT = /* @__PURE__ */ new Set(["autoplay", "muted"]);
|
|
25
|
-
function channel(url, hosts) {
|
|
26
|
-
if (!url || !hosts.has(url.host)) return null;
|
|
27
|
-
const [, name] = CHANNEL.exec(url.path) ?? [];
|
|
28
|
-
if (name === void 0 || NOT_CHANNELS.has(name.toLowerCase())) return null;
|
|
29
|
-
const id = name.toLowerCase();
|
|
30
|
-
return {
|
|
31
|
-
platform: "kick",
|
|
32
|
-
kind: "video",
|
|
33
|
-
url: `https://kick.com/${id}`,
|
|
34
|
-
id,
|
|
35
|
-
variant: "iframe"
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
7
|
const kick = {
|
|
39
|
-
|
|
40
|
-
name: "Kick",
|
|
41
|
-
shapes: ["video iframe"],
|
|
8
|
+
...kickMatcher,
|
|
42
9
|
parse(root) {
|
|
43
10
|
if (root.tag !== "iframe") return null;
|
|
44
11
|
const src = parseUrl(root.attrs.get("src") ?? "");
|
|
@@ -50,14 +17,6 @@ const kick = {
|
|
|
50
17
|
options
|
|
51
18
|
}, sizeOf(root));
|
|
52
19
|
},
|
|
53
|
-
isOwnScript: () => false
|
|
54
|
-
match(url) {
|
|
55
|
-
const found = channel(url, PAGE_HOSTS) ?? channel(url, KICK_PLAYER_HOSTS);
|
|
56
|
-
return found && {
|
|
57
|
-
...found,
|
|
58
|
-
options: {}
|
|
59
|
-
};
|
|
60
|
-
},
|
|
61
|
-
ownsFrame: kickFrame
|
|
20
|
+
isOwnScript: () => false
|
|
62
21
|
};
|
|
63
22
|
export { kick };
|
|
@@ -1,28 +1,11 @@
|
|
|
1
1
|
import { sizeOf, withSize } from "../platform.js";
|
|
2
2
|
import { coerce, parseUrl } from "../url.js";
|
|
3
|
-
import
|
|
3
|
+
import "../frames.js";
|
|
4
|
+
import { URN, linkedinMatcher, post } from "../matchers/linkedin.js";
|
|
4
5
|
// src/parser/platforms/linkedin.ts
|
|
5
|
-
const HOST = /^(?:www\.|[a-z]{2}\.)?linkedin\.com$/;
|
|
6
|
-
const URN = "(activity|share|ugcPost):(\\d{19})";
|
|
7
|
-
const UPDATE_PATH = new RegExp(`^(?:/embed)?/feed/update/urn:li:${URN}/?$`);
|
|
8
|
-
const POSTS_PATH = new RegExp(`^/posts/[^/]{1,300}-(activity|share|ugcPost)-(\\d{19})-[A-Za-z0-9_-]{1,8}/?$`);
|
|
9
6
|
const EMBED_PATH = new RegExp(`^/embed/feed/update/urn:li:${URN}$`);
|
|
10
|
-
function post(type, id, options = {}) {
|
|
11
|
-
const urn = `urn:li:${type}:${id}`;
|
|
12
|
-
return {
|
|
13
|
-
platform: "linkedin",
|
|
14
|
-
kind: "post",
|
|
15
|
-
url: `https://www.linkedin.com/feed/update/${urn}/`,
|
|
16
|
-
id: urn,
|
|
17
|
-
variant: "iframe",
|
|
18
|
-
options
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
const decodeColons = (path) => path.replace(/%3A/gi, ":");
|
|
22
7
|
const linkedin = {
|
|
23
|
-
|
|
24
|
-
name: "LinkedIn",
|
|
25
|
-
shapes: ["post iframe"],
|
|
8
|
+
...linkedinMatcher,
|
|
26
9
|
parse(root) {
|
|
27
10
|
if (root.tag !== "iframe") return null;
|
|
28
11
|
const src = parseUrl(root.attrs.get("src") ?? "");
|
|
@@ -32,13 +15,6 @@ const linkedin = {
|
|
|
32
15
|
const options = Object.fromEntries([...src.query].map(([key, value]) => [key, coerce(value)]));
|
|
33
16
|
return withSize(post(type, id, options), sizeOf(root));
|
|
34
17
|
},
|
|
35
|
-
isOwnScript: () => false
|
|
36
|
-
match(url) {
|
|
37
|
-
if (!HOST.test(url.host)) return null;
|
|
38
|
-
const path = decodeColons(url.path);
|
|
39
|
-
const [, type, id] = UPDATE_PATH.exec(path) ?? POSTS_PATH.exec(path) ?? [];
|
|
40
|
-
return type === void 0 || id === void 0 ? null : post(type, id);
|
|
41
|
-
},
|
|
42
|
-
ownsFrame: linkedinFrame
|
|
18
|
+
isOwnScript: () => false
|
|
43
19
|
};
|
|
44
20
|
export { linkedin };
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { attributeOptions } from "../platform.js";
|
|
2
2
|
import { coerce, parseUrl } from "../url.js";
|
|
3
|
-
import
|
|
3
|
+
import "../frames.js";
|
|
4
|
+
import { pin, pinOf, pinterestMatcher } from "../matchers/pinterest.js";
|
|
4
5
|
// src/parser/platforms/pinterest.ts
|
|
5
|
-
const HOST = /^(?:(?:www|[a-z]{2})\.)?pinterest\.(?:[a-z]{2,3}|co\.[a-z]{2}|com\.[a-z]{2})$/;
|
|
6
|
-
const PIN_PATH = /^\/pin\/(?:[A-Za-z0-9-]{0,200}--)?(\d{1,25})\/?$/;
|
|
7
6
|
const PIN_ID = /^\d{1,25}$/;
|
|
8
7
|
const SCRIPT = /^(?:https?:)?\/\/assets\.pinterest\.com\/js\/pinit(?:_main)?\.js$/;
|
|
9
8
|
const OPTION_ATTRIBUTES = [
|
|
@@ -11,24 +10,8 @@ const OPTION_ATTRIBUTES = [
|
|
|
11
10
|
["data-pin-lang", "lang"],
|
|
12
11
|
["data-pin-terse", "terse"]
|
|
13
12
|
];
|
|
14
|
-
function pin(id) {
|
|
15
|
-
return {
|
|
16
|
-
platform: "pinterest",
|
|
17
|
-
kind: "post",
|
|
18
|
-
url: `https://www.pinterest.com/pin/${id}/`,
|
|
19
|
-
id,
|
|
20
|
-
variant: "sdk"
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
function pinOf(url) {
|
|
24
|
-
if (!url || !HOST.test(url.host)) return null;
|
|
25
|
-
const [, id] = PIN_PATH.exec(url.path) ?? [];
|
|
26
|
-
return id === void 0 ? null : pin(id);
|
|
27
|
-
}
|
|
28
13
|
const pinterest = {
|
|
29
|
-
|
|
30
|
-
name: "Pinterest",
|
|
31
|
-
shapes: ["post sdk"],
|
|
14
|
+
...pinterestMatcher,
|
|
32
15
|
parse(root) {
|
|
33
16
|
if (root.tag === "a") {
|
|
34
17
|
if (root.attrs.get("data-pin-do") !== "embedPin") return null;
|
|
@@ -48,14 +31,6 @@ const pinterest = {
|
|
|
48
31
|
options: {}
|
|
49
32
|
} : null;
|
|
50
33
|
},
|
|
51
|
-
isOwnScript: (src) => SCRIPT.test(src)
|
|
52
|
-
match(url) {
|
|
53
|
-
const found = pinOf(url);
|
|
54
|
-
return found && {
|
|
55
|
-
...found,
|
|
56
|
-
options: {}
|
|
57
|
-
};
|
|
58
|
-
},
|
|
59
|
-
ownsFrame: pinterestFrame
|
|
34
|
+
isOwnScript: (src) => SCRIPT.test(src)
|
|
60
35
|
};
|
|
61
36
|
export { pinterest };
|
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
import { descendants, hasClass } from "../html.js";
|
|
2
2
|
import { attributeOptions, withSize } from "../platform.js";
|
|
3
3
|
import { coerce, parseUrl, pixels } from "../url.js";
|
|
4
|
+
import { post, redditMatcher } from "../matchers/reddit.js";
|
|
4
5
|
// src/parser/platforms/reddit.ts
|
|
5
|
-
const HOSTS = /* @__PURE__ */ new Set([
|
|
6
|
-
"reddit.com",
|
|
7
|
-
"www.reddit.com",
|
|
8
|
-
"old.reddit.com",
|
|
9
|
-
"new.reddit.com"
|
|
10
|
-
]);
|
|
11
|
-
const POST_PATH = /^\/r\/([A-Za-z0-9_]{2,21})\/comments\/([a-z0-9]{1,12})(?:\/([^/]{1,300}))?(?:\/([a-z0-9]{1,16}))?\/?$/;
|
|
12
6
|
const SCRIPT = /^(?:https?:)?\/\/embed\.reddit\.com\/widgets\.js$/;
|
|
13
7
|
const CARD_SCRIPT = /^(?:https?:)?\/\/embed\.redditmedia\.com\/widgets\/platform\.js$/;
|
|
14
8
|
const OPTION_ATTRIBUTES = [
|
|
@@ -23,32 +17,8 @@ const OPTION_ATTRIBUTES = [
|
|
|
23
17
|
"showusername",
|
|
24
18
|
"snippet"
|
|
25
19
|
].map((name) => [`data-embed-${name}`, name]);
|
|
26
|
-
function post(url) {
|
|
27
|
-
if (!url || !HOSTS.has(url.host)) return null;
|
|
28
|
-
const [, sub, postId, slug, commentId] = POST_PATH.exec(url.path) ?? [];
|
|
29
|
-
if (sub === void 0 || postId === void 0) return null;
|
|
30
|
-
const base = {
|
|
31
|
-
platform: "reddit",
|
|
32
|
-
kind: "post",
|
|
33
|
-
variant: "iframe"
|
|
34
|
-
};
|
|
35
|
-
const postUrl = `https://www.reddit.com/r/${sub}/comments/${postId}/`;
|
|
36
|
-
if (commentId === void 0) return {
|
|
37
|
-
...base,
|
|
38
|
-
url: postUrl,
|
|
39
|
-
id: postId
|
|
40
|
-
};
|
|
41
|
-
if (slug === void 0) return null;
|
|
42
|
-
return {
|
|
43
|
-
...base,
|
|
44
|
-
url: `${postUrl}comment/${commentId}/`,
|
|
45
|
-
id: commentId
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
20
|
const reddit = {
|
|
49
|
-
|
|
50
|
-
name: "Reddit",
|
|
51
|
-
shapes: ["post iframe"],
|
|
21
|
+
...redditMatcher,
|
|
52
22
|
parse(root) {
|
|
53
23
|
if (root.tag !== "blockquote" || !(hasClass(root, "reddit-embed-bq") || hasClass(root, "reddit-card"))) return null;
|
|
54
24
|
const found = descendants(root.children).map((element) => element.tag === "a" ? post(parseUrl(element.attrs.get("href") ?? "")) : null).find((embed) => embed !== null);
|
|
@@ -59,13 +29,6 @@ const reddit = {
|
|
|
59
29
|
options: attributeOptions(root, OPTION_ATTRIBUTES, coerce)
|
|
60
30
|
}, height === void 0 ? void 0 : { height });
|
|
61
31
|
},
|
|
62
|
-
isOwnScript: (src) => SCRIPT.test(src) || CARD_SCRIPT.test(src)
|
|
63
|
-
match(url) {
|
|
64
|
-
const found = post(url);
|
|
65
|
-
return found && {
|
|
66
|
-
...found,
|
|
67
|
-
options: {}
|
|
68
|
-
};
|
|
69
|
-
}
|
|
32
|
+
isOwnScript: (src) => SCRIPT.test(src) || CARD_SCRIPT.test(src)
|
|
70
33
|
};
|
|
71
34
|
export { reddit };
|
|
@@ -1,27 +1,9 @@
|
|
|
1
|
-
import { rumbleNeedsLookup } from "../lookup.js";
|
|
2
1
|
import { sizeOf, withSize } from "../platform.js";
|
|
3
2
|
import { coerce, parseUrl } from "../url.js";
|
|
4
|
-
import {
|
|
3
|
+
import { idOf, rumbleMatcher, video } from "../matchers/rumble.js";
|
|
5
4
|
// src/parser/platforms/rumble.ts
|
|
6
|
-
const PATH = /^\/embed\/(v[a-z0-9]{1,12})\/?$/;
|
|
7
|
-
const HOSTS = /* @__PURE__ */ new Set(["rumble.com", "www.rumble.com"]);
|
|
8
|
-
function video(id) {
|
|
9
|
-
return {
|
|
10
|
-
platform: "rumble",
|
|
11
|
-
kind: "video",
|
|
12
|
-
url: `https://rumble.com/embed/${id}/`,
|
|
13
|
-
id,
|
|
14
|
-
variant: "iframe"
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
function idOf(url, hosts) {
|
|
18
|
-
return url && hosts.has(url.host) ? PATH.exec(url.path)?.[1] : void 0;
|
|
19
|
-
}
|
|
20
5
|
const rumble = {
|
|
21
|
-
|
|
22
|
-
name: "Rumble",
|
|
23
|
-
shapes: ["video iframe"],
|
|
24
|
-
needsLookup: rumbleNeedsLookup,
|
|
6
|
+
...rumbleMatcher,
|
|
25
7
|
parse(root) {
|
|
26
8
|
if (root.tag !== "iframe") return null;
|
|
27
9
|
const src = parseUrl(root.attrs.get("src") ?? "");
|
|
@@ -35,14 +17,6 @@ const rumble = {
|
|
|
35
17
|
options
|
|
36
18
|
}, sizeOf(root));
|
|
37
19
|
},
|
|
38
|
-
isOwnScript: () => false
|
|
39
|
-
match(url) {
|
|
40
|
-
const id = idOf(url, HOSTS);
|
|
41
|
-
return id === void 0 ? null : {
|
|
42
|
-
...video(id),
|
|
43
|
-
options: {}
|
|
44
|
-
};
|
|
45
|
-
},
|
|
46
|
-
ownsFrame: rumbleFrame
|
|
20
|
+
isOwnScript: () => false
|
|
47
21
|
};
|
|
48
22
|
export { rumble };
|
|
@@ -1,58 +1,11 @@
|
|
|
1
1
|
import { descendants, hasClass } from "../html.js";
|
|
2
2
|
import { withSize } from "../platform.js";
|
|
3
3
|
import { parseUrl, pixels } from "../url.js";
|
|
4
|
+
import { content, snapchatMatcher } from "../matchers/snapchat.js";
|
|
4
5
|
// src/parser/platforms/snapchat.ts
|
|
5
|
-
const HOSTS = /* @__PURE__ */ new Set(["snapchat.com", "www.snapchat.com"]);
|
|
6
|
-
const USER = "([A-Za-z][A-Za-z0-9._-]{1,29})";
|
|
7
|
-
const SPOTLIGHT = new RegExp(`^(?:/@${USER})?/spotlight/([A-Za-z0-9_-]{20,120})$`);
|
|
8
|
-
const PROFILE = new RegExp(`^/(?:@|add/)${USER}$`);
|
|
9
|
-
const LENS = /^\/lens\/([0-9a-f]{32}|\d{1,20})$/;
|
|
10
|
-
const HIGHLIGHT = new RegExp(`^/@${USER}/highlight/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$`);
|
|
11
6
|
const SCRIPT = /^(?:https?:)?\/\/www\.snapchat\.com\/embed\.js$/;
|
|
12
|
-
function content(url) {
|
|
13
|
-
if (!url || !HOSTS.has(url.host)) return null;
|
|
14
|
-
const path = url.path.replace(/\/$/, "");
|
|
15
|
-
const base = {
|
|
16
|
-
platform: "snapchat",
|
|
17
|
-
variant: "iframe"
|
|
18
|
-
};
|
|
19
|
-
const [, spotlightUser, spotlightId] = SPOTLIGHT.exec(path) ?? [];
|
|
20
|
-
if (spotlightId !== void 0) {
|
|
21
|
-
const prefix = spotlightUser === void 0 ? "" : `/@${spotlightUser}`;
|
|
22
|
-
return {
|
|
23
|
-
...base,
|
|
24
|
-
kind: "video",
|
|
25
|
-
url: `https://www.snapchat.com${prefix}/spotlight/${spotlightId}`,
|
|
26
|
-
id: spotlightId
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
const [, user] = PROFILE.exec(path) ?? [];
|
|
30
|
-
if (user !== void 0) return {
|
|
31
|
-
...base,
|
|
32
|
-
kind: "post",
|
|
33
|
-
url: `https://www.snapchat.com/@${user}`,
|
|
34
|
-
id: user
|
|
35
|
-
};
|
|
36
|
-
const [, lens] = LENS.exec(path) ?? [];
|
|
37
|
-
if (lens !== void 0) return {
|
|
38
|
-
...base,
|
|
39
|
-
kind: "post",
|
|
40
|
-
url: `https://www.snapchat.com/lens/${lens}`,
|
|
41
|
-
id: lens
|
|
42
|
-
};
|
|
43
|
-
const [, owner, highlight] = HIGHLIGHT.exec(path) ?? [];
|
|
44
|
-
if (owner !== void 0 && highlight !== void 0) return {
|
|
45
|
-
...base,
|
|
46
|
-
kind: "post",
|
|
47
|
-
url: `https://www.snapchat.com/@${owner}/highlight/${highlight}`,
|
|
48
|
-
id: highlight
|
|
49
|
-
};
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
7
|
const snapchat = {
|
|
53
|
-
|
|
54
|
-
name: "Snapchat",
|
|
55
|
-
shapes: ["post iframe", "video iframe"],
|
|
8
|
+
...snapchatMatcher,
|
|
56
9
|
parse(root) {
|
|
57
10
|
if (root.tag !== "blockquote" || !hasClass(root, "snapchat-embed")) return null;
|
|
58
11
|
const embedUrl = parseUrl(root.attrs.get("data-snapchat-embed-url") ?? "");
|
|
@@ -77,13 +30,6 @@ const snapchat = {
|
|
|
77
30
|
height
|
|
78
31
|
});
|
|
79
32
|
},
|
|
80
|
-
isOwnScript: (src) => SCRIPT.test(src)
|
|
81
|
-
match(url) {
|
|
82
|
-
const found = content(url);
|
|
83
|
-
return found && {
|
|
84
|
-
...found,
|
|
85
|
-
options: {}
|
|
86
|
-
};
|
|
87
|
-
}
|
|
33
|
+
isOwnScript: (src) => SCRIPT.test(src)
|
|
88
34
|
};
|
|
89
35
|
export { snapchat };
|
|
@@ -1,78 +1,8 @@
|
|
|
1
1
|
import { sizeOf, withSize } from "../platform.js";
|
|
2
2
|
import { coerce, parseUrl } from "../url.js";
|
|
3
|
-
import
|
|
3
|
+
import "../frames.js";
|
|
4
|
+
import { PAGE_HOSTS, SECRET_TOKEN, fromApi, soundcloudMatcher } from "../matchers/soundcloud.js";
|
|
4
5
|
// src/parser/platforms/soundcloud.ts
|
|
5
|
-
const PAGE_HOSTS = /* @__PURE__ */ new Set([
|
|
6
|
-
"soundcloud.com",
|
|
7
|
-
"www.soundcloud.com",
|
|
8
|
-
"m.soundcloud.com"
|
|
9
|
-
]);
|
|
10
|
-
const API_PATH = /^\/(tracks|playlists|users)\/(?:soundcloud%3A(?:tracks|playlists|users)%3A)?(\d{1,15})\/?$/i;
|
|
11
|
-
const NAME = "[a-z0-9_-]{1,64}";
|
|
12
|
-
const SECRET = "s-[A-Za-z0-9]{1,32}";
|
|
13
|
-
const PERMALINK = new RegExp(`^/(${NAME})(?:/(sets/${NAME}|${NAME})(?:/(${SECRET}))?)?/?$`, "i");
|
|
14
|
-
const NOT_USERS = /* @__PURE__ */ new Set([
|
|
15
|
-
"discover",
|
|
16
|
-
"search",
|
|
17
|
-
"stream",
|
|
18
|
-
"feed",
|
|
19
|
-
"you",
|
|
20
|
-
"upload",
|
|
21
|
-
"charts",
|
|
22
|
-
"pages",
|
|
23
|
-
"settings",
|
|
24
|
-
"messages",
|
|
25
|
-
"notifications",
|
|
26
|
-
"people",
|
|
27
|
-
"stations",
|
|
28
|
-
"library",
|
|
29
|
-
"terms-of-use",
|
|
30
|
-
"signin"
|
|
31
|
-
]);
|
|
32
|
-
const NOT_SOUNDS = /* @__PURE__ */ new Set([
|
|
33
|
-
"likes",
|
|
34
|
-
"tracks",
|
|
35
|
-
"sets",
|
|
36
|
-
"albums",
|
|
37
|
-
"reposts",
|
|
38
|
-
"popular-tracks",
|
|
39
|
-
"followers",
|
|
40
|
-
"following",
|
|
41
|
-
"comments",
|
|
42
|
-
"spotlight",
|
|
43
|
-
"toptracks"
|
|
44
|
-
]);
|
|
45
|
-
const SECRET_TOKEN = new RegExp(`^${SECRET}$`);
|
|
46
|
-
function sound(url, id) {
|
|
47
|
-
return {
|
|
48
|
-
platform: "soundcloud",
|
|
49
|
-
kind: "post",
|
|
50
|
-
url,
|
|
51
|
-
id,
|
|
52
|
-
variant: "iframe"
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
function fromApi(url) {
|
|
56
|
-
if (url?.host !== "api.soundcloud.com") return null;
|
|
57
|
-
const [, type, id] = API_PATH.exec(url.path) ?? [];
|
|
58
|
-
if (type === void 0 || id === void 0) return null;
|
|
59
|
-
const token = url.query.get("secret_token");
|
|
60
|
-
if (token !== void 0 && !SECRET_TOKEN.test(token)) return null;
|
|
61
|
-
const secret = token === void 0 ? "" : `?secret_token=${token}`;
|
|
62
|
-
return sound(`https://api.soundcloud.com/${type.toLowerCase()}/${id}${secret}`, id);
|
|
63
|
-
}
|
|
64
|
-
function fromPage(url) {
|
|
65
|
-
if (!PAGE_HOSTS.has(url.host)) return null;
|
|
66
|
-
const [, user, second, secret] = PERMALINK.exec(url.path) ?? [];
|
|
67
|
-
if (user === void 0 || NOT_USERS.has(user.toLowerCase())) return null;
|
|
68
|
-
if (second !== void 0 && NOT_SOUNDS.has(second.toLowerCase())) return null;
|
|
69
|
-
const path = [
|
|
70
|
-
user,
|
|
71
|
-
second,
|
|
72
|
-
secret
|
|
73
|
-
].filter(Boolean).join("/");
|
|
74
|
-
return sound(`https://soundcloud.com/${path}`, path);
|
|
75
|
-
}
|
|
76
6
|
const LINK_ATTRIBUTES = /* @__PURE__ */ new Set([
|
|
77
7
|
"href",
|
|
78
8
|
"title",
|
|
@@ -92,9 +22,7 @@ function isCredit(element) {
|
|
|
92
22
|
return rest.length === 0 && isCreditLink(artist) && separator?.type === "text" && /^\s*·\s*$/.test(separator.raw) && isCreditLink(sound);
|
|
93
23
|
}
|
|
94
24
|
const soundcloud = {
|
|
95
|
-
|
|
96
|
-
name: "SoundCloud",
|
|
97
|
-
shapes: ["post iframe"],
|
|
25
|
+
...soundcloudMatcher,
|
|
98
26
|
parse(root) {
|
|
99
27
|
if (root.tag !== "iframe") return null;
|
|
100
28
|
const src = parseUrl(root.attrs.get("src") ?? "");
|
|
@@ -117,14 +45,6 @@ const soundcloud = {
|
|
|
117
45
|
}, height === void 0 ? void 0 : { height });
|
|
118
46
|
},
|
|
119
47
|
isOwnScript: () => false,
|
|
120
|
-
isOwnExtra: isCredit
|
|
121
|
-
match(url) {
|
|
122
|
-
const found = fromApi(url) ?? fromPage(url);
|
|
123
|
-
return found && {
|
|
124
|
-
...found,
|
|
125
|
-
options: {}
|
|
126
|
-
};
|
|
127
|
-
},
|
|
128
|
-
ownsFrame: soundcloudFrame
|
|
48
|
+
isOwnExtra: isCredit
|
|
129
49
|
};
|
|
130
50
|
export { soundcloud };
|