@sockethub/platform-metadata 1.0.1-beta.2 → 1.0.1-beta.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 +4 -0
- package/dist/index.js +72 -11
- package/dist/index.js.map +4 -4
- package/dist/resolvers.d.ts +21 -0
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -124,6 +124,10 @@ so those URLs are resolved through preview services built for this purpose:
|
|
|
124
124
|
datacenter address. Full media still requires authentication. Facebook
|
|
125
125
|
publishes no site name, so `actor.name` and `object.name` fall back to
|
|
126
126
|
`Facebook`.
|
|
127
|
+
* **Amazon product URLs** (storefronts such as `amazon.de` and `amazon.com`,
|
|
128
|
+
plus `amzn.to`/`a.co` short links) are scraped with WhatsApp's link-preview
|
|
129
|
+
user agent. Amazon answers other crawlers with a captcha or a generic
|
|
130
|
+
"Amazon" share card instead of the product's title and image.
|
|
127
131
|
* **Facebook engagement prefixes**: video titles and image alt text often
|
|
128
132
|
start with a localized view or reaction count, such as
|
|
129
133
|
`2.2M views · 21K reactions | …` or `347K views | …`. When the prefix is
|
package/dist/index.js
CHANGED
|
@@ -70777,7 +70777,7 @@ var import_undici3 = __toESM(require_undici(), 1);
|
|
|
70777
70777
|
// package.json
|
|
70778
70778
|
var package_default = {
|
|
70779
70779
|
name: "@sockethub/platform-metadata",
|
|
70780
|
-
version: "1.0.1-beta.
|
|
70780
|
+
version: "1.0.1-beta.4",
|
|
70781
70781
|
description: "Fetch metadata from a given URL",
|
|
70782
70782
|
author: "Nick Jennings <nick@silverbucket.net>",
|
|
70783
70783
|
license: "LGPL-3.0+",
|
|
@@ -70819,17 +70819,17 @@ var package_default = {
|
|
|
70819
70819
|
"clean:deps": "rm -rf node_modules"
|
|
70820
70820
|
},
|
|
70821
70821
|
dependencies: {
|
|
70822
|
-
"@sockethub/util": "^1.0.0-beta.
|
|
70822
|
+
"@sockethub/util": "^1.0.0-beta.4",
|
|
70823
70823
|
"open-graph-scraper": "^6.11.0",
|
|
70824
70824
|
undici: "^7.30.0"
|
|
70825
70825
|
},
|
|
70826
70826
|
devDependencies: {
|
|
70827
|
-
"@sockethub/schemas": "^3.0.0-beta.
|
|
70827
|
+
"@sockethub/schemas": "^3.0.0-beta.4"
|
|
70828
70828
|
},
|
|
70829
70829
|
peerDependencies: {
|
|
70830
|
-
"@sockethub/server": "^5.0.0-beta.
|
|
70830
|
+
"@sockethub/server": "^5.0.0-beta.4"
|
|
70831
70831
|
},
|
|
70832
|
-
gitHead: "
|
|
70832
|
+
gitHead: "639c296a7332f192a1b3f7e86ef6603b5b67bbaa",
|
|
70833
70833
|
types: "./dist/index.d.ts"
|
|
70834
70834
|
};
|
|
70835
70835
|
|
|
@@ -71074,6 +71074,44 @@ function isFacebookUrl(url) {
|
|
|
71074
71074
|
const host = parsed.hostname.toLowerCase();
|
|
71075
71075
|
return FACEBOOK_HOSTS.has(host) || host === "fb.watch";
|
|
71076
71076
|
}
|
|
71077
|
+
var AMAZON_STORE_TLDS = new Set([
|
|
71078
|
+
"com",
|
|
71079
|
+
"ca",
|
|
71080
|
+
"com.mx",
|
|
71081
|
+
"com.br",
|
|
71082
|
+
"co.uk",
|
|
71083
|
+
"de",
|
|
71084
|
+
"fr",
|
|
71085
|
+
"it",
|
|
71086
|
+
"es",
|
|
71087
|
+
"nl",
|
|
71088
|
+
"se",
|
|
71089
|
+
"pl",
|
|
71090
|
+
"com.be",
|
|
71091
|
+
"com.tr",
|
|
71092
|
+
"ie",
|
|
71093
|
+
"ae",
|
|
71094
|
+
"sa",
|
|
71095
|
+
"eg",
|
|
71096
|
+
"in",
|
|
71097
|
+
"co.jp",
|
|
71098
|
+
"sg",
|
|
71099
|
+
"com.au",
|
|
71100
|
+
"co.za"
|
|
71101
|
+
]);
|
|
71102
|
+
var AMAZON_SHORT_HOSTS = new Set(["amzn.to", "amzn.eu", "amzn.asia", "a.co"]);
|
|
71103
|
+
function isAmazonUrl(url) {
|
|
71104
|
+
let parsed;
|
|
71105
|
+
try {
|
|
71106
|
+
parsed = new URL(url);
|
|
71107
|
+
} catch {
|
|
71108
|
+
return false;
|
|
71109
|
+
}
|
|
71110
|
+
const host = parsed.hostname.toLowerCase().replace(/^www\./, "");
|
|
71111
|
+
if (AMAZON_SHORT_HOSTS.has(host))
|
|
71112
|
+
return true;
|
|
71113
|
+
return host.startsWith("amazon.") && AMAZON_STORE_TLDS.has(host.slice(7));
|
|
71114
|
+
}
|
|
71077
71115
|
function stripFacebookEngagement(title) {
|
|
71078
71116
|
const bar = title?.indexOf("|") ?? -1;
|
|
71079
71117
|
if (title === undefined || bar === -1) {
|
|
@@ -71189,7 +71227,26 @@ function redditPostImage(post) {
|
|
|
71189
71227
|
}
|
|
71190
71228
|
];
|
|
71191
71229
|
}
|
|
71192
|
-
return;
|
|
71230
|
+
return redditGalleryImages(post);
|
|
71231
|
+
}
|
|
71232
|
+
function redditGalleryImages(post) {
|
|
71233
|
+
const items = post.gallery_data?.items;
|
|
71234
|
+
if (!Array.isArray(items))
|
|
71235
|
+
return;
|
|
71236
|
+
const images = [];
|
|
71237
|
+
for (const item of items) {
|
|
71238
|
+
const id = item?.media_id;
|
|
71239
|
+
const source = typeof id === "string" ? post.media_metadata?.[id]?.s : undefined;
|
|
71240
|
+
const url = redditMediaUrl(source?.u ?? source?.gif, new Set(["i.redd.it", "preview.redd.it"]));
|
|
71241
|
+
if (url) {
|
|
71242
|
+
images.push({
|
|
71243
|
+
url,
|
|
71244
|
+
width: finiteNonNegative(source?.x),
|
|
71245
|
+
height: finiteNonNegative(source?.y)
|
|
71246
|
+
});
|
|
71247
|
+
}
|
|
71248
|
+
}
|
|
71249
|
+
return images.length ? images : undefined;
|
|
71193
71250
|
}
|
|
71194
71251
|
function redditPostVideo(post) {
|
|
71195
71252
|
const video = post.secure_media?.reddit_video;
|
|
@@ -71425,13 +71482,15 @@ var PlatformMetadataSchema = {
|
|
|
71425
71482
|
// src/index.ts
|
|
71426
71483
|
var DEFAULT_USER_AGENT = `Mozilla/5.0 (compatible; SockethubBot/${package_default.version}; +https://sockethub.org)`;
|
|
71427
71484
|
var COMPAT_USER_AGENT = "Mozilla/5.0 (compatible; Discordbot/2.0; +https://discordapp.com)";
|
|
71485
|
+
var AMAZON_USER_AGENT = "WhatsApp/2.23.20.0 A";
|
|
71486
|
+
var AMAZON_SCRAPE_TIMEOUT_MS = 1e4;
|
|
71428
71487
|
var TWEET_API_TIMEOUT_MS = 1e4;
|
|
71429
71488
|
var REDDIT_OEMBED_URL = "https://www.reddit.com/oembed";
|
|
71430
71489
|
var REDDIT_OEMBED_TIMEOUT_MS = 4000;
|
|
71431
71490
|
var YOUTUBE_OEMBED_TIMEOUT_MS = 4000;
|
|
71432
71491
|
var FACEBOOK_EMBED_TIMEOUT_MS = 4000;
|
|
71433
71492
|
var SCRAPE_TIMEOUT_MS = 5000;
|
|
71434
|
-
var REDDIT_JSON_TIMEOUT_MS =
|
|
71493
|
+
var REDDIT_JSON_TIMEOUT_MS = 5000;
|
|
71435
71494
|
var REDDIT_JSON_MAX_BYTES = 1e6;
|
|
71436
71495
|
var DIRECT_IMAGE_PROBE_TIMEOUT_MS = 5000;
|
|
71437
71496
|
var FACEBOOK_TRACKING_PARAMS = ["_fb_noscript", "fbclid", "mibextid"];
|
|
@@ -71793,13 +71852,15 @@ class Metadata {
|
|
|
71793
71852
|
scrape(job, cb, redditEmbed, scrapeUrl = job.actor.id, youtubeEmbed) {
|
|
71794
71853
|
const youtubeVideo = Boolean(resolveYouTubeOEmbed(job.actor.id));
|
|
71795
71854
|
const useCompatUserAgent = isRedditUrl(job.actor.id) || isFacebookUrl(job.actor.id) || youtubeVideo;
|
|
71796
|
-
const
|
|
71855
|
+
const amazon = isAmazonUrl(job.actor.id);
|
|
71856
|
+
const scrapeTimeoutMs = amazon ? AMAZON_SCRAPE_TIMEOUT_MS : SCRAPE_TIMEOUT_MS;
|
|
71857
|
+
const userAgent = amazon ? AMAZON_USER_AGENT : useCompatUserAgent ? this.compatUserAgent() : this.userAgent();
|
|
71797
71858
|
const dispatcher = this.getDispatcher();
|
|
71798
71859
|
let youtubeDescription;
|
|
71799
71860
|
this.log.debug(`scrape started for ${job.actor.id} via ${scrapeUrl}`);
|
|
71800
71861
|
const options = {
|
|
71801
71862
|
url: scrapeUrl,
|
|
71802
|
-
timeout:
|
|
71863
|
+
timeout: scrapeTimeoutMs / 1000,
|
|
71803
71864
|
urlValidatorSettings: {
|
|
71804
71865
|
allow_fragments: true,
|
|
71805
71866
|
allow_protocol_relative_urls: false,
|
|
@@ -71833,7 +71894,7 @@ class Metadata {
|
|
|
71833
71894
|
}
|
|
71834
71895
|
return import_open_graph_scraper.default({ html });
|
|
71835
71896
|
}) : import_open_graph_scraper.default(options);
|
|
71836
|
-
withDeadline(scrape,
|
|
71897
|
+
withDeadline(scrape, scrapeTimeoutMs).then(async (data) => {
|
|
71837
71898
|
let { result } = data;
|
|
71838
71899
|
this.log.debug(`scrape completed for ${job.actor.id}`);
|
|
71839
71900
|
const reddit = isRedditUrl(job.actor.id);
|
|
@@ -71950,4 +72011,4 @@ export {
|
|
|
71950
72011
|
withDeadline
|
|
71951
72012
|
};
|
|
71952
72013
|
|
|
71953
|
-
//# debugId=
|
|
72014
|
+
//# debugId=391BA00E724CA7D764756E2164756E21
|