This repository has been archived by the owner on May 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from lemonde/HUIT-700-published-time
feat(provider) Récupère la date de publication d'une video
- Loading branch information
Showing
22 changed files
with
1,714 additions
and
1,392 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,16 @@ | ||
{ | ||
"presets": ["es2015"], | ||
"plugins": ["transform-object-rest-spread"] | ||
"presets": [ | ||
[ | ||
"@babel/preset-env", | ||
{ | ||
"modules": "commonjs", | ||
"loose": true, | ||
"forceAllTransforms": true, | ||
"targets": { | ||
"node": "current" | ||
} | ||
} | ||
] | ||
], | ||
"plugins": ["@babel/plugin-proposal-object-rest-spread"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,71 @@ | ||
'use strict'; | ||
"use strict"; | ||
|
||
var _ = require('lodash'); | ||
var fetch = require('../fetch'); | ||
|
||
var fetch = require('../fetch'); | ||
/** | ||
* Dailymotion api endpoints | ||
*/ | ||
|
||
|
||
var fetchVideo = _.memoize(function (url) { | ||
return fetch(url, { headers: provider.headers }).then(function (res) { | ||
return fetch(url, { | ||
headers: provider.headers | ||
}).then(function (res) { | ||
return res.json(); | ||
}); | ||
}); | ||
|
||
var getUrl = function getUrl(videoId) { | ||
return '//www.dailymotion.com/embed/video/' + videoId; | ||
return "//www.dailymotion.com/embed/video/" + videoId; | ||
}; | ||
|
||
var provider = { | ||
name: 'dailymotion', | ||
label: 'Dailymotion', | ||
headers: {}, | ||
videoIdExtractRegExps: [ | ||
// NOTE : behind the _ in the id, everything is discarded by dailymotion | ||
videoIdExtractRegExps: [// NOTE : behind the _ in the id, everything is discarded by dailymotion | ||
// standard url | ||
// ex. http://www.dailymotion.com/video/x22i6cm_la-guerre-a-gaza-en-5-minutes_news | ||
/^(?:https?:)?\/\/(?:www\.)?dailymotion\.com\/video\/([^?_&#]+)/i, | ||
// standard url with extra path | ||
/^(?:https?:)?\/\/(?:www\.)?dailymotion\.com\/video\/([^?_&#]+)/i, // standard url with extra path | ||
// ex. http://www.dailymotion.com/toto/video/x22i6cm_la-guerre-a-gaza-en-5-minutes_news | ||
/^(?:https?:)?\/\/(?:www\.)?dailymotion\.com\/(?:[^_&#]+)\/video\/([^?_&#]+)/i, | ||
// short url | ||
/^(?:https?:)?\/\/(?:www\.)?dailymotion\.com\/(?:[^_&#]+)\/video\/([^?_&#]+)/i, // short url | ||
// ex. http://dai.ly/x22i6cm | ||
/^(?:https?:)?\/\/dai\.ly\/([^?_&#]+)/i], | ||
|
||
getThumbnailUrl: function getThumbnailUrl(videoId) { | ||
return new Promise(function (resolve) { | ||
return resolve('//www.dailymotion.com/thumbnail/video/' + videoId); | ||
return resolve("//www.dailymotion.com/thumbnail/video/" + videoId); | ||
}); | ||
}, | ||
|
||
getTitle: function getTitle(videoId) { | ||
return fetchVideo('https://api.dailymotion.com/video/' + videoId + '?fields=title').then(function (result) { | ||
return fetchVideo("https://api.dailymotion.com/video/" + videoId + "?fields=title").then(function (result) { | ||
return _.get(result, 'title'); | ||
}); | ||
}, | ||
|
||
getDescription: function getDescription(videoId) { | ||
return fetchVideo('https://api.dailymotion.com/video/' + videoId + '?fields=description').then(function (result) { | ||
return fetchVideo("https://api.dailymotion.com/video/" + videoId + "?fields=description").then(function (result) { | ||
return _.get(result, 'description'); | ||
}); | ||
}, | ||
|
||
getDuration: function getDuration(videoId) { | ||
return fetchVideo('https://api.dailymotion.com/video/' + videoId + '?fields=duration').then(function (result) { | ||
return fetchVideo("https://api.dailymotion.com/video/" + videoId + "?fields=duration").then(function (result) { | ||
return _.get(result, 'duration'); | ||
}); | ||
}, | ||
|
||
getPublishedDate: function getPublishedDate(videoId) { | ||
return fetchVideo("https://api.dailymotion.com/video/" + videoId + "?fields=created_time").then(function (result) { | ||
return _.get(result, 'created_time'); | ||
}); | ||
}, | ||
getPlayerUrl: function getPlayerUrl(videoId) { | ||
return new Promise(function (resolve) { | ||
return resolve(getUrl(videoId)); | ||
}); | ||
}, | ||
|
||
getEmbedCode: function getEmbedCode(videoId) { | ||
return new Promise(function (resolve) { | ||
return resolve(_.compact(['<iframe src="' + getUrl(videoId) + '"', 'frameborder="0"', _.get(provider, 'embed.width') ? 'width="' + provider.embed.width + '"' : null, _.get(provider, 'embed.height') ? 'height="' + provider.embed.height + '"' : null, '></iframe>']).join(' ')); | ||
return resolve(_.compact(["<iframe src=\"" + getUrl(videoId) + "\"", 'frameborder="0"', _.get(provider, 'embed.width') ? "width=\"" + provider.embed.width + "\"" : null, _.get(provider, 'embed.height') ? "height=\"" + provider.embed.height + "\"" : null, '></iframe>']).join(' ')); | ||
}); | ||
} | ||
}; | ||
|
||
module.exports = provider; |
Oops, something went wrong.