jsVideoUrlParser
A javascript parser to extract informations like provider, video id, start time from video urls
Currently supports
- YouTube
- Vimeo
- Twitch
- Dailymotion
grunt
$ grunt$ grunt build$ grunt test$ grunt dist #build and test specific plugins $ grunt --youtube=1 --vimeo=1$ grunt build --youtube=1 --vimeo=1$ grunt test --youtube=1 --vimeo=1$ grunt dist --youtube=1 --vimeo=1
=1 since gruntjs/grunt#908
bower
bower install js-video-url-parser
npm
npm install js-video-url-parser
Usage
Node
urlParser = require('js-video-url-parser');
Parsing
Parsing a url will return a videoInfo object with all the information
> urlParser mediaType: 'video' id: 'HRb7B9fPhfA' provider: 'youtube' > urlParser mediaType: 'video' id: '97276391' provider: 'vimeo' > urlParser mediaType: 'stream' channel: 'tsm_wildturtle' provider: 'twitch' > urlParser mediaType: 'video' id: 'x1e2b95' provider: 'dailymotion'
Any url but the id parameter will be saved in the params object
> urlParser provider: 'youtube' id: 'yQaAGmHNn9s' list: 'PL46F0A159EC02DF82' mediaType: 'video' params: start: 100 list: 'PL46F0A159EC02DF82' index: '25'
URL Creation
The VideoInfo objects can be turned back into a 'short'
, 'embed'
or 'long'
url where 'long'
is the default.
Embedded links will be protocol relative.
> urlParser'https://youtu.be/HRb7B9fPhfA'> urlParser'https://www.youtube.com/watch?v=HRb7B9fPhfA'> urlParser'//youtube.com/embed/HRb7B9fPhfA' > urlParser'https://vimeo.com/97276391'> urlParser'//player.vimeo.com/video/97276391' > urlParser'https://twitch.tv/tsm_wildturtle'> urlParser'//www.twitch.tv/tsm_wildturtle/embed' > urlParser'https://dai.ly/x1e2b95'> urlParser'https://www.dailymotion.com/video/x1e2b95'> urlParser'//www.dailymotion.com/embed/video/x1e2b95'
Url parameters can be added by adding a params object
> urlParser'https://youtube.com/watch?foo=bar&index=25&list=PL46F0A159EC02DF82&v=yQaAGmHNn9s#t=100'
To the reuse the params in the videoInfo object without having to save it in a temp variable use the keyword 'internal'
as params
> urlParser'https://youtube.com/watch?foo=bar&index=25&list=PL46F0A159EC02DF82&v=yQaAGmHNn9s#t=100'> urlParser'//youtube.com/embed/yQaAGmHNn9s?foo=bar&index=25&list=PL46F0A159EC02DF82&start=100'
Plugins
YouTube
It can extract the id from shortened, mobile and feed urls.
> urlParser;> urlParser;> urlParser;> urlParser; mediaType: 'video' id: 'HRb7B9fPhfA' provider: 'youtube'
Also supports the start time parameter and playlist urls.
> urlParser;> urlParser; mediaType: 'playlist' list: 'PL46F0A159EC02DF82' provider: 'youtube' params: list: 'PL46F0A159EC02DF82' > urlParser; mediaType: 'video' id: 'yQaAGmHNn9s' list: 'PL46F0A159EC02DF82' provider: 'youtube' params: list: 'PL46F0A159EC02DF82' > urlParser;> urlParser;> urlParser;> urlParser;> urlParser; mediaType: 'video' id: 'HRb7B9fPhfA' provider: 'youtube' params: start: 30 > urlParser; mediaType: 'video' id: 'yQaAGmHNn9s' list: 'PL46F0A159EC02DF82' provider: 'youtube' params: start: 100 list: 'PL46F0A159EC02DF82'
Vimeo
Supports urls from channels, albums, groups and frames.
> urlParser;> urlParser; id: '97276391' mediaType: 'video' provider: 'vimeo' > urlParser; id: '96186586' mediaType: 'video' provider: 'vimeo' > urlParser; id: '97688625' mediaType: 'video' provider: 'vimeo' > urlParser; id: '24069938' mediaType: 'video' provider: 'vimeo'
Twitch
Supports embedded, stream and video urls
> urlParser;> urlParser;> urlParser; mediaType: 'stream' channel: 'tsm_wildturtle' provider: 'twitch' > urlParser; mediaType: 'video' id: '2724914' idPrefix: 'c' channel: 'tsm_wildturtle' provider: 'twitch'
Dailymotion
Supports embedded and shortened urls.
> urlParser;> urlParser;> urlParser;> urlParser; mediaType: 'video' id: 'x1e2b95' provider: 'dailymotion' > urlParser;> urlParser;> urlParser; mediaType: 'video' id: 'x1e2b95' provider: 'dailymotion' params: start: 10