@ndanglan/url-preview v2.5.0
get-preview-data
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.
Installation
Install the package via npm:
npm install get-preview-dataUsage
Importing the Module
const { getPreviewData } = require("get-preview-data");Example: Fetch Metadata from a URL
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.");
}
})();Output
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": {}
}
}API Reference
getPreviewData(url, userAgent)
Fetches and parses preview data from the specified URL.
Parameters:
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.
Returns:
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, includingitemInfoandshareMeta.
Features
- 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.
Development
Clone the Repository
git clone https://github.com/your-username/get-preview-data.git
cd get-preview-dataInstall Dependencies
npm installRun Tests
npm testContributing
Contributions are welcome! Please open an issue or submit a pull request to propose changes or improvements.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Acknowledgments
10 months ago
10 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago