@sockethub/platform-metadata 1.0.1-alpha.18 → 1.0.1-alpha.19
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/dist/index.js +122 -20
- package/dist/index.js.map +5 -5
- package/dist/resolvers.d.ts +45 -2
- package/package.json +5 -5
package/dist/resolvers.d.ts
CHANGED
|
@@ -4,13 +4,14 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Some large platforms return a generic banner image (X/Twitter), serve
|
|
6
6
|
* their Open Graph data only to recognized embed crawlers (Reddit), or
|
|
7
|
-
* hide post media behind a login (Facebook)
|
|
8
|
-
* strategies:
|
|
7
|
+
* hide post media behind a login (Facebook):
|
|
9
8
|
*
|
|
10
9
|
* - X/Twitter → FxTwitter's JSON API (api.fxtwitter.com), built for embed
|
|
11
10
|
* previews, returns the tweet text plus direct photo/video URLs.
|
|
12
11
|
* - Reddit → the regular scrape works, but only when presented with an
|
|
13
12
|
* embed-crawler user agent (see COMPAT_USER_AGENT in index.ts).
|
|
13
|
+
* - Facebook → same crawler-UA gating as Reddit, plus its video titles
|
|
14
|
+
* arrive polluted with localized engagement stats that need stripping.
|
|
14
15
|
*
|
|
15
16
|
* These are pure URL matchers/mappers — the platform decides what to do
|
|
16
17
|
* with the resolution (call a JSON API vs. pick a scrape user agent).
|
|
@@ -36,6 +37,22 @@ export interface YouTubeOEmbed {
|
|
|
36
37
|
export declare function parseYouTubeOEmbed(value: unknown): YouTubeOEmbed | null;
|
|
37
38
|
/** Map a validated YouTube oEmbed thumbnail to the platform image shape. */
|
|
38
39
|
export declare function youtubeOEmbedImage(embed?: YouTubeOEmbed): PageObject["image"] | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* True for Facebook URLs (including fb.watch short links). Facebook serves
|
|
42
|
+
* an unrecognized scraper a login interstitial instead of the post, but
|
|
43
|
+
* serves recognized link-preview crawlers the post's Open Graph data —
|
|
44
|
+
* title, caption, and the video/photo thumbnail — so these URLs scrape
|
|
45
|
+
* with COMPAT_USER_AGENT (see index.ts), like Reddit.
|
|
46
|
+
*/
|
|
47
|
+
export declare function isFacebookUrl(url: string): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Remove the engagement-stats segment Facebook prepends to video titles:
|
|
50
|
+
* "2.2M views · 21K reactions | <video title> | <author>". The stats are
|
|
51
|
+
* localized to the *scraping server's* geo-IP language, so match their
|
|
52
|
+
* shape — a leading pipe-delimited segment containing a digit and the "·"
|
|
53
|
+
* separator — rather than any particular wording.
|
|
54
|
+
*/
|
|
55
|
+
export declare function stripFacebookEngagement(title: string | undefined): string | undefined;
|
|
39
56
|
/**
|
|
40
57
|
* True for Reddit URLs (including redd.it short links). Reddit serves its
|
|
41
58
|
* Open Graph tags — with the post's real preview image — only to
|
|
@@ -47,16 +64,42 @@ export declare function isRedditUrl(url: string): boolean;
|
|
|
47
64
|
export declare function resolveRedditEmbed(url: string): string | null;
|
|
48
65
|
/** Map a canonical Reddit post URL to old.reddit.com's public JSON endpoint. */
|
|
49
66
|
export declare function resolveRedditJson(url: string): string | null;
|
|
67
|
+
/**
|
|
68
|
+
* Unwrap Reddit's media-viewer URL (`reddit.com/media?url=<image>`) to the
|
|
69
|
+
* image it displays. Reddit serves neither post JSON nor oEmbed for these
|
|
70
|
+
* links (its oEmbed endpoint returns HTTP 400), but the target image is
|
|
71
|
+
* embedded in the link itself, so no network request is needed at all.
|
|
72
|
+
*/
|
|
73
|
+
export declare function resolveRedditMedia(url: string): string | null;
|
|
50
74
|
export interface RedditPost {
|
|
51
75
|
title: string;
|
|
52
76
|
selftext?: string;
|
|
53
77
|
url?: string;
|
|
54
78
|
url_overridden_by_dest?: string;
|
|
79
|
+
secure_media?: {
|
|
80
|
+
reddit_video?: {
|
|
81
|
+
fallback_url?: string;
|
|
82
|
+
width?: number;
|
|
83
|
+
height?: number;
|
|
84
|
+
duration?: number;
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
preview?: {
|
|
88
|
+
images?: Array<{
|
|
89
|
+
source?: {
|
|
90
|
+
url?: string;
|
|
91
|
+
width?: number;
|
|
92
|
+
height?: number;
|
|
93
|
+
};
|
|
94
|
+
}>;
|
|
95
|
+
};
|
|
55
96
|
}
|
|
56
97
|
/** Validate and extract the post object from Reddit's listing response. */
|
|
57
98
|
export declare function parseRedditPost(value: unknown): RedditPost | null;
|
|
58
99
|
/** Select only a direct Reddit-hosted image belonging to the post. */
|
|
59
100
|
export declare function redditPostImage(post: RedditPost): PageObject["image"];
|
|
101
|
+
/** Map Reddit's hosted-video payload to the common page video shape. */
|
|
102
|
+
export declare function redditPostVideo(post: RedditPost): PageObject["video"];
|
|
60
103
|
/** Subset of Reddit's oEmbed response used for link previews. */
|
|
61
104
|
export interface RedditOEmbed {
|
|
62
105
|
title?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sockethub/platform-metadata",
|
|
3
|
-
"version": "1.0.1-alpha.
|
|
3
|
+
"version": "1.0.1-alpha.19",
|
|
4
4
|
"description": "Fetch metadata from a given URL",
|
|
5
5
|
"author": "Nick Jennings <nick@silverbucket.net>",
|
|
6
6
|
"license": "LGPL-3.0+",
|
|
@@ -42,16 +42,16 @@
|
|
|
42
42
|
"clean:deps": "rm -rf node_modules"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@sockethub/util": "^1.0.0-alpha.
|
|
45
|
+
"@sockethub/util": "^1.0.0-alpha.12",
|
|
46
46
|
"open-graph-scraper": "^6.11.0",
|
|
47
47
|
"undici": "^7.16.0"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@sockethub/schemas": "^3.0.0-alpha.
|
|
50
|
+
"@sockethub/schemas": "^3.0.0-alpha.24"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
|
-
"@sockethub/server": "^5.0.0-alpha.
|
|
53
|
+
"@sockethub/server": "^5.0.0-alpha.24"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "5b55535c7f1df5b7959585179d31e7cb654d4084",
|
|
56
56
|
"types": "./dist/index.d.ts"
|
|
57
57
|
}
|