@micmac/youtube
Advanced tools
Comparing version 2.9.1 to 2.9.5
123
main.js
@@ -74,8 +74,27 @@ // fonction searchVideos retourne les 10 dernières videos de la chaine beerus | ||
var getAllVideosInfos = function () { | ||
var videoFullInfos = new Object (); | ||
var promiseInfo = new Object (); | ||
var promiseComment = new Object (); | ||
var nbOfVideo = 0; | ||
moment.locale ('fr'); | ||
return new Promise (function (resolve, reject) { | ||
var videoFullInfos = { | ||
video: [ | ||
{ | ||
id: '', | ||
title: '', | ||
date: '', | ||
description: '', | ||
thumbnail: '', | ||
tags: new Array (), | ||
comment: [ | ||
{ | ||
author: '', | ||
text: '', | ||
date: '', | ||
avatar: '' | ||
} | ||
] | ||
}, | ||
] | ||
} | ||
var promiseInfo = new Array (); | ||
var promiseComment = new Array (); | ||
var nbOfVideo = 0; | ||
moment.locale ('fr'); | ||
getVideosID ().catch (function (error) { | ||
@@ -90,39 +109,63 @@ console.log ('getVideosID ERROR : ' + error); | ||
}).then (function (response) { | ||
videoFullInfos[n].video.id = p.id.videoId; | ||
videoFullInfos[n].video.title = response.data.items[0].snippet.title; | ||
videoFullInfos[n].video.date = moment (response.data.items[0].snippet.publishedAt).format ('LL'); | ||
videoFullInfos[n].video.description = response.data.items[0].snippet.description; | ||
videoFullInfos[n].video.thumbnail = response.data.items[0].snippet.thumbnails.standard.url; | ||
videoFullInfos[n].video.tags = response.data.items[0].snippet.tags; | ||
console.log ('id video : ' + p.id.videoId); | ||
console.log ('titre de la video : ' + response.data.items[0].snippet.title); | ||
console.log ('date de publication : ' + moment (response.data.items[0].snippet.publishedAt).format ('LL')); | ||
console.log ('description : ' + response.data.items[0].snippet.description); | ||
console.log ('url vignette standard : '); | ||
console.log (response.data.items[0].snippet.thumbnails.standard.url); | ||
console.log ('tableau des tags :' + response.data.items[0].snippet.tags); | ||
videoFullInfos.video.push ({ | ||
id: p.id.videoId, | ||
title: response.data.items[0].snippet.title, | ||
date: moment (response.data.items[0].snippet.publishedAt).format ('LL'), | ||
description: response.data.items[0].snippet.description, | ||
thumbnail: response.data.items[0].snippet.thumbnails.standard.url, | ||
tags: response.data.items[0].snippet.tags, | ||
comments: [ | ||
{ | ||
author: '', | ||
text: '', | ||
avatar: '', | ||
date: '' | ||
}, | ||
] | ||
}); | ||
// console.log ('id video : ' + p.id.videoId); | ||
// console.log ('titre de la video : ' + response.data.items[0].snippet.title); | ||
// console.log ('date de publication : ' + moment (response.data.items[0].snippet.publishedAt).format ('LL')); | ||
// console.log ('description : ' + response.data.items[0].snippet.description); | ||
// console.log ('url vignette standard : '); | ||
// console.log (response.data.items[0].snippet.thumbnails.standard.url); | ||
// console.log ('tableau des tags :' + response.data.items[0].snippet.tags); | ||
}).then (function () { | ||
promiseComment[n] = getVideoComments (p.id.videoId).catch (function (error) { | ||
console.log ('comment ERROR : ' + error); | ||
}).then (function (response) { | ||
console.log ('nombre de commentaires : ' + response.data.pageInfo.totalResults); | ||
if (response.data.pageInfo.totalResults > 0) | ||
{ | ||
response.data.items.forEach (function (q, m) { | ||
videoFullInfos.video[n].comments.push ( | ||
{ | ||
author: q.snippet.topLevelComment.snippet.authorDisplayName, | ||
text: q.snippet.topLevelComment.snippet.textOriginal, | ||
avatar: q.snippet.topLevelComment.snippet.authorProfileImageUrl, | ||
date: moment (q.snippet.topLevelComment.snippet.publishedAt).format ('LL') | ||
}); | ||
// console.log ('id video commentée : ' + q.snippet.videoId); | ||
// console.log ('auteur du commentaire : ' + q.snippet.topLevelComment.snippet.authorDisplayName); | ||
// console.log ('commentaire : ' + q.snippet.topLevelComment.snippet.textOriginal); | ||
// console.log ('url avatar auteur : ' + q.snippet.topLevelComment.snippet.authorProfileImageUrl); | ||
// console.log ('date du commentaire : ' + moment (q.snippet.topLevelComment.snippet.publishedAt).format ('LL')); | ||
}); | ||
} | ||
}); | ||
}); | ||
promiseComment[n] = getVideoComments (p.id.videoId).catch (function (error) { | ||
console.log ('comment ERROR : ' + error); | ||
}).then (function (response) { | ||
console.log ('nombre de commentaires : ' + response.data.pageInfo.totalResults); | ||
if (response.data.pageInfo.totalResults > 0) | ||
{ | ||
response.data.items.forEach (function (q, m) { | ||
videoFullInfos[n].comments[m].author = q.snippet.topLevelComment.snippet.authorDisplayName; | ||
videoFullInfos[n].comments[m].text = q.snippet.topLevelComment.snippet.textOriginal; | ||
videoFullInfos[n].comments[m].avatar = q.snippet.topLevelComment.snippet.authorProfileImageUrl; | ||
videoFullInfos[n].comments[m].date = moment (q.snippet.topLevelComment.snippet.publishedAt).format ('LL'); | ||
console.log ('id video commentée : ' + q.snippet.videoId); | ||
console.log ('auteur du commentaire : ' + q.snippet.topLevelComment.snippet.authorDisplayName); | ||
console.log ('commentaire : ' + q.snippet.topLevelComment.snippet.textOriginal); | ||
console.log ('url avatar auteur : ' + q.snippet.topLevelComment.snippet.authorProfileImageUrl); | ||
console.log ('date du commentaire : ' + moment (q.snippet.topLevelComment.snippet.publishedAt).format ('LL')); | ||
}); | ||
} | ||
}); | ||
}); | ||
var allPromise =new Promise(); | ||
allPromise.all(promiseInfo,promiseComment).then(resolve(videoFullInfos)); | ||
}); | ||
Promise.all (promiseInfo, promiseComment).then (function () { | ||
resolve(videoFullInfos); | ||
}); | ||
}); | ||
}, function (error, response) { | ||
if (error) | ||
{ | ||
reject (error); | ||
} | ||
if (response) | ||
{ | ||
resolve (response); | ||
} | ||
}); | ||
@@ -129,0 +172,0 @@ }; |
{ | ||
"name": "@micmac/youtube", | ||
"version": "2.9.1", | ||
"version": "2.9.5", | ||
"description": "utilisation api youtube data", | ||
@@ -5,0 +5,0 @@ "main": "main.js", |
12033
290