You can install it with yarn: yarn --pure-lockfile
It's a video provider, which expose some basics data extracted from famous video platforms.
This lib could be used natively on server side (node) and on client side, with a client package manager as npm, webpack, ...
Basic usage :
npm install --save universal-video-provider
or
yarn add universal-video-provider
const videoProvider = require('universal-video-provider');
const provider = videoProvider.getProviderFromUrl('http://www.youtube.com/v/ky6CRSBcf98');
// provider is an object which contains data extraction methods
provider.getTitle()
.then(title => console.log(title))
.catch(err => console.error(err));
provider.getDescription()
.then(title => console.log(title))
.catch(err => console.error(err));
...
provider.getVideoFromUrl('http://www.youtube.com/v/ky6CRSBcf98')
then(video => console.log(video))
.catch(err => console.error(err));
// video is an object which contains all the extracted data
Run with npm and jspm. Not tested with others package managers.
youtube, dailymotion, ina, digiteka
For youtube
, you have to extend the current provider with an apiKey :
videoProvider.extendProvider('youtube', { apiKey: 'yourKey' });
For digiteka
, you have to extend the current provider with credentials :
videoProvider.extendProvider('digiteka', {
// id of the site lemonde.fr on digiteka
mdtk: '123456',
mainCatalog: '5dmpl',
// When playing a video, this indicates that the video is played
// in a back-office (to avoid ads, and not count it as a view)
zoneId: 34,
});
Digiteka provider has a search
method to require in utlimedia catalog.
Params :
- pattern [required]
- pageToken (youtube only)
- order (youtube only)
Youtube provider has a search
method to search within youtube library. It returns an Object with 2 keys, one for the token for the next request, the second holds a videos collection matching the criteria:
// "converge" is your search
const searcher = () => videoProvider.getProviderFromName('youtube').search(encodeURIComponent('converge'))
searcher().then(data => console.log(data))
// data is an object which contains all the extracted data
{ nextPageToken: 'CAUQAA',
videos:
[ { title: 'Converge - "A Single Tear"',
description: 'Listen to the full album: http://bit.ly/2ypxqC7\n"A Single Tear" by Converge from the album The Dusk In Us',
thumbnailUrl: 'https://i.ytimg.com/vi/DKqOp2YHfhI/maxresdefault.jpg',
playerUrl: '//www.youtube.com/watch?v=DKqOp2YHfhI',
duration: '04:06',
pusblishedDate: '2017-09-25T19:05:29.000Z',
metadata: { embedCode: '//www.youtube.com/embed/DKqOp2YHfhI' },
provider: 'youtube',
providerVideoId: 'DKqOp2YHfhI' },
{ title: 'Converge - "Precipice / All We Love We Leave Behind"',
description: '"Precipice / All We Love We Leave Behind" by Converge',
thumbnailUrl: 'https://i.ytimg.com/vi/akG2cFldO6I/maxresdefault.jpg',
playerUrl: '//www.youtube.com/watch?v=akG2cFldO6I',
duration: '06:17',
publishedDate: '2017-09-25T19:05:29.000Z',
metadata: { embedCode: '//www.youtube.com/embed/akG2cFldO6I' },
provider: 'youtube',
providerVideoId: 'akG2cFldO6I'
}
]
}
Get a specific provider from an url.
Return:
provider Object
const provider = videoProvider.getProviderFromUrl(
'http://www.youtube.com/v/ky6CRSBcf98'
);
Get a video from an url.
Return: video object
provider.getVideoFromUrl('http://www.youtube.com/v/ky6CRSBcf98');
then(video => console.log(video)).catch(err => console.error(err));
// video is an object which contains all the extracted data
Get a video from a provider and a video id.
Return: video object
const youtubeProvider = videoProvider.getProviderFromUrl(
'http://www.youtube.com/v/ky6CRSBcf98'
);
provider.getVideoFromId(youtubeProvider, 'ky6CRSBcf98');
then(video => console.log(video)).catch(err => console.error(err));
// video is an object which contains all the extracted data
Extract video id from an url, with a specific provider.
Return: String
const provider = videoProvider.getProviderFromUrl(
'http://www.youtube.com/v/ky6CRSBcf98'
);
const videoId = videoProvider.extractVideoId(
provider,
'http://www.youtube.com/v/ky6CRSBcf98'
);
// 'ky6CRSBcf98'
Get a specific provider by his name
Return:
provider Object
videoProvider.getProviderByName('dailymotion');
Get a list of supported provider
Return: [String]
videoProvider.getSupportedProviders();
// ['dailymotion', 'ina', 'youtube', 'digiteka']
Extend a current provider with new constants or methods.
Params: provider name (String), new fields (Object)
videoProvider.extendProvider('vimeo', {
apiKey: 'myKey',
search: terms =>
fetch(`vimeoUrl/search/?terms=${terms}?apiKey=${this.apiKey}`),
});
Extend all providers with new constants or methods.
Params: new fields (Object)
videoProvider.extendProviders({ header: { 'Cache-Control': 'no-cache' } });
Get the thumbnail url of the video.
Params: video id
Returns: String
provider
.getThumbnailUrl(videoId)
.then(thumbnailUrl => console.log(thumbnailUrl))
.catch(err => console.error(err));
Get the title of the video.
Params: video id
Returns: String
provider
.getTitle(videoId)
.then(title => console.log(title))
.catch(err => console.error(err));
Get the description of the video.
Params: video id
Returns: String
provider
.getDescription(videoId)
.then(description => console.log(description))
.catch(err => console.error(err));
Get the duration of the video.
Params: video id
Returns: String
provider
.getDuration(videoId)
.then(duration => console.log(duration))
.catch(err => console.error(err));
Get the publication date of the video.
Params: video id
Returns: date
provider
.getPublishedDate(videoId)
.then(publishedDate => console.log(publishedDate))
.catch(err => console.error(err));
Get the player url of the video.
Params: video id
Returns: String
provider
.getPlayerUrl(videoId)
.then(playerUrl => console.log(playerUrl))
.catch(err => console.error(err));
Since js-release
is included in the project, you can make a release with it:
See the changelog: yarn release changelog
make the release: yarn release add <patch|minor|major>
This will transpile the sources (yarn build
) before creating a new release.
You can add issue, and create pull request. https://github.com/lemonde/universal-video-provider/blob/master/.github/CONTRIBUTING.md