Registry / serialization / js-video-url-parser

js-video-url-parser

JSON →
library0.5.1jsnpmunverified

js-video-url-parser is a versatile JavaScript and TypeScript library engineered to extract detailed information from URLs across a wide array of online video platforms, including YouTube, Vimeo, Twitch, Dailymotion, Facebook, TikTok, Loom, and many others. It offers a streamlined API to parse various video URLs into a structured `videoInfo` object, encapsulating data such as the video's provider, ID, media type, and any relevant URL parameters. Furthermore, the library supports the reverse operation, allowing developers to reconstruct valid video URLs from these `videoInfo` objects with customizable formatting. The current stable version is 0.5.1. The package maintains an active release cadence, frequently adding support for new providers and addressing reported issues, indicating ongoing development and maintenance. Its primary differentiators are its extensive list of supported video services and its bidirectional functionality for both parsing and generating video URLs.

npm install js-video-url-parser
INSTALL
IMPORT
SIG · JS-VIDEO-URL-PARSE
J
js-video-url-parser
serializationjavascriptv0.5.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

urlParser
import urlParser from 'js-video-url-parser';
import { urlParser } from 'js-video-url-parser';
This is the primary import for the parser, which includes all bundled provider plugins. It's a default export.
urlParser (base)
import urlParser from 'js-video-url-parser/lib/base';
import { urlParser } from 'js-video-url-parser/lib/base';
For tree-shaking or to only use specific providers, import the base parser and then individually import desired providers as side effects.
Provider module
import 'js-video-url-parser/lib/provider/youtube';
import { youtube } from 'js-video-url-parser/lib/provider/youtube';
Provider modules like this are imported for their side effects, registering themselves with the base parser. They do not export any symbols directly.

This quickstart demonstrates how to parse YouTube and Vimeo URLs to extract video details and how to reconstruct a YouTube URL with custom parameters.

import urlParser from 'js-video-url-parser'; // Parse a YouTube URL to extract video information const youtubeUrl = 'https://www.youtube.com/watch?v=HRb7B9fPhfA&t=1m40s&list=PL46F0A159EC02DF82'; const youtubeInfo = urlParser.parse(youtubeUrl); console.log('YouTube Info:', youtubeInfo); /* Output example: { provider: 'youtube', id: 'HRb7B9fPhfA', list: 'PL46F0A159EC02DF82', mediaType: 'video', params: { start: 100 } } */ // Parse a Vimeo URL const vimeoUrl = 'https://vimeo.com/97276391'; const vimeoInfo = urlParser.parse(vimeoUrl); console.log('Vimeo Info:', vimeoInfo); // Create a URL from a videoInfo object const createdUrl = urlParser.create({ videoInfo: { provider: 'youtube', id: 'dQw4w9WgXcQ', mediaType: 'video' }, format: 'long', params: { autoplay: 1 } }); console.log('Created YouTube URL:', createdUrl);
Debug
Known issues
breakingThe `create` function, as of version `0.4.0`, now returns `undefined` if essential data (such as `id` or `mediaType`) is missing from the provided `videoInfo` object. Previously, it might have returned an incomplete or invalid URL. Developers should ensure `videoInfo` objects are complete before calling `create`.
fix
Always validate the `videoInfo` object to contain required properties (`provider`, `id`, `mediaType`) before passing it to `urlParser.create()`. Implement checks for `undefined` return values.
affects: >=0.4.0
breakingVimeo thumbnail parsing was removed in version `0.4.2` due to inconsistencies where thumbnail IDs did not reliably match video IDs. This functionality is no longer available through the library, meaning consumers who relied on it for Vimeo thumbnail generation will need to implement an alternative solution.
fix
Discontinue use of the library's Vimeo thumbnail parsing. Implement a custom solution for Vimeo thumbnail retrieval, potentially using the Vimeo API or other external services directly.
affects: >=0.4.2
deprecatedThe `template` export was removed in version `0.5.0` as it was previously ignored by npm, indicating it was not intended for public consumption. While unlikely to affect many applications, developers specifically importing or relying on this internal export will find it no longer available.
fix
Remove any direct imports or references to the `template` export. It was an internal, non-functional export.
affects: >=0.5.0
Errors
Common errors & fixes
TypeError: urlParser.parse is not a function
This error often occurs when attempting to use a CommonJS `require()` statement to import a module that primarily uses ES module (`export default`) syntax, and then trying to access methods directly on the `module.exports` object without considering the `default` property.
fix
If using CommonJS, adjust your import to `const urlParser = require('js-video-url-parser').default;` to correctly access the default export. For ES Modules, use `import urlParser from 'js-video-url-parser';`.
Property 'parse' does not exist on type 'typeof import("/path/to/js-video-url-parser")'.
This TypeScript error can occur if you're using an older version of `js-video-url-parser` that did not ship with TypeScript type declarations (before `0.4.2`), or if your TypeScript configuration isn't correctly picking up the types.
fix
Ensure you are using `js-video-url-parser` version `0.4.2` or newer, which includes TypeScript declarations. If the problem persists, verify your `tsconfig.json` settings, especially `moduleResolution`, and ensure `node_modules/@types` is being correctly scanned, or install `@types/js-video-url-parser` if it exists (though not usually needed since types are bundled).
Upgrade
Version history
0.5.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
js-video-url-parser — npm install js-video-url-parser · libregistry