@sockethub/platform-metadata 1.0.1-alpha.17 → 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.
@@ -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). Two of those have working
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).
@@ -23,6 +24,35 @@
23
24
  * Handles `/<user>/status/<id>` and the `/i/web/status/<id>` share form.
24
25
  */
25
26
  export declare function resolveTwitterStatus(url: string): string | null;
27
+ /** Resolve supported YouTube video URLs to the official oEmbed endpoint. */
28
+ export declare function resolveYouTubeOEmbed(url: string): string | null;
29
+ export interface YouTubeOEmbed {
30
+ title: string;
31
+ provider_name?: string;
32
+ thumbnail_url: string;
33
+ thumbnail_width?: number;
34
+ thumbnail_height?: number;
35
+ }
36
+ /** Validate the subset of YouTube's external oEmbed payload we consume. */
37
+ export declare function parseYouTubeOEmbed(value: unknown): YouTubeOEmbed | null;
38
+ /** Map a validated YouTube oEmbed thumbnail to the platform image shape. */
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;
26
56
  /**
27
57
  * True for Reddit URLs (including redd.it short links). Reddit serves its
28
58
  * Open Graph tags — with the post's real preview image — only to
@@ -34,16 +64,42 @@ export declare function isRedditUrl(url: string): boolean;
34
64
  export declare function resolveRedditEmbed(url: string): string | null;
35
65
  /** Map a canonical Reddit post URL to old.reddit.com's public JSON endpoint. */
36
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;
37
74
  export interface RedditPost {
38
75
  title: string;
39
76
  selftext?: string;
40
77
  url?: string;
41
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
+ };
42
96
  }
43
97
  /** Validate and extract the post object from Reddit's listing response. */
44
98
  export declare function parseRedditPost(value: unknown): RedditPost | null;
45
99
  /** Select only a direct Reddit-hosted image belonging to the post. */
46
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"];
47
103
  /** Subset of Reddit's oEmbed response used for link previews. */
48
104
  export interface RedditOEmbed {
49
105
  title?: string;
@@ -94,6 +150,23 @@ export interface FxTwitterStatus {
94
150
  duration?: number;
95
151
  }>;
96
152
  };
153
+ article?: {
154
+ title?: string;
155
+ preview_text?: string;
156
+ cover_media?: {
157
+ media_info?: {
158
+ original_img_url?: string;
159
+ original_img_width?: number;
160
+ original_img_height?: number;
161
+ };
162
+ };
163
+ content?: {
164
+ blocks?: Array<{
165
+ text?: string;
166
+ type?: string;
167
+ }>;
168
+ };
169
+ };
97
170
  };
98
171
  }
99
172
  /** The `object` payload shape the metadata platform responds with. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sockethub/platform-metadata",
3
- "version": "1.0.1-alpha.17",
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.10",
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.22"
50
+ "@sockethub/schemas": "^3.0.0-alpha.24"
51
51
  },
52
52
  "peerDependencies": {
53
- "@sockethub/server": "^5.0.0-alpha.22"
53
+ "@sockethub/server": "^5.0.0-alpha.24"
54
54
  },
55
- "gitHead": "643a19160301186e428add63a79ae42ee26e8844",
55
+ "gitHead": "5b55535c7f1df5b7959585179d31e7cb654d4084",
56
56
  "types": "./dist/index.d.ts"
57
57
  }