A utility to fetch and parse preview data from social media and other websites. Supports fetching metadata such as title, description, images, site name, and additional data for TikTok videos.
Install the package via npm:
npm install get-preview-data
const { getPreviewData } = require("get-preview-data");
const url = "https://www.tiktok.com/@username/video/123456789";
(async () => {
const previewData = await getPreviewData(url);
if (previewData) {
console.log("Preview Data:", previewData);
} else {
console.error("Failed to fetch preview data.");
}
})();
The function returns an object with the following structure:
{
"title": "Video Title",
"description": "Video Description",
"image": "https://example.com/image.jpg",
"siteName": "TikTok",
"url": "https://www.tiktok.com/@username/video/123456789",
"data": {
"itemInfo": {},
"shareMeta": {}
}
}
Fetches and parses preview data from the specified URL.
-
url
(string, required): The URL to fetch. -
userAgent
(string, optional): A custom User-Agent string to be sent with the request. Defaults to a modern browser User-Agent if not provided.
An object containing:
-
title
(string): The title of the page or video. -
description
(string): The description of the page or video. -
image
(string): The URL of an image associated with the page. -
siteName
(string): The name of the website. -
url
(string): The URL of the page (may be updated if redirected). -
data
(object): Additional data specific to TikTok pages, includingitemInfo
andshareMeta
.
- Supports fetching metadata for TikTok, Instagram, Facebook, Threads, and other websites.
- Uses Puppeteer for rendering dynamic content on Meta (Facebook, Instagram, Threads) URLs.
- Extracts OpenGraph, Twitter Card, and Zalo metadata.
- Provides additional data parsing for TikTok videos.
git clone https://github.com/your-username/get-preview-data.git
cd get-preview-data
npm install
npm test
Contributions are welcome! Please open an issue or submit a pull request to propose changes or improvements.
This project is licensed under the MIT License. See the LICENSE file for details.