Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@micmac/youtube

Package Overview
Dependencies
Maintainers
1
Versions
121
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@micmac/youtube - npm Package Compare versions

Comparing version 4.0.0 to 4.0.1

367

main.js
// fonction searchVideos retourne les 10 dernières videos de la chaine beerus
var {
google
} = require ('googleapis');
var moment = require ('moment');
var youtube = google.youtube ({
version: 'v3',
auth: process.env.APIKEY
});
var {
google
} = require ('googleapis');
var moment = require ('moment');
var youtube = google.youtube ({
version: 'v3',
auth: process.env.APIKEY
});
function getVideosID () {
return new Promise (function (resolve, reject) {
moment.locale ('fr');
youtube.search.list ({
"part": "id,snippet",
"channelId": "UCtToNyHU2Fjxuh__ypkHiIQ",
"maxResults": 10,
"order": "date",
"type": "video"
}, function (error, response) {
if (error)
{
reject (error);
}
if (response)
{
resolve (response);
}
});
});
}
;
function getVideosID () {
return new Promise (function (resolve, reject) {
moment.locale ('fr');
youtube.search.list ({
"part": "id,snippet",
"channelId": "UCtToNyHU2Fjxuh__ypkHiIQ",
"maxResults": 10,
"order": "date",
"type": "video"
}, function (error, response) {
if (error)
{
reject (error);
}
if (response)
{
resolve (response);
}
});
});
}
;
var getVideoInfo = async function (_idVideo, _noVideo) {
var videoPromise = new Promise (function (resolve, reject) {
moment.locale ('fr');
youtube.videos.list ({
"part": "id,snippet,contentDetails",
"id": _idVideo,
"maxResults": 1
}, function (error, response) {
if (error)
{
reject (error);
}
if (response)
{
resolve ({
data: response,
noVideo: _noVideo
});
}
});
});
var result = await videoPromise.then (function (data) {
return data;
});
return result;
};
var getVideoInfo = async function (_idVideo, _noVideo) {
var videoPromise = new Promise (function (resolve, reject) {
moment.locale ('fr');
youtube.videos.list ({
"part": "id,snippet,contentDetails",
"id": _idVideo,
"maxResults": 1
}, function (error, response) {
if (error)
{
reject (error);
}
if (response)
{
resolve ({
data: response,
noVideo: _noVideo
});
}
});
});
var result = await videoPromise.then (function (data) {
return data;
});
return result;
};
var getVideoComments = async function (_idVideo, _noVideo) {
var commentPromise = new Promise (function (resolve, reject) {
moment.locale ('fr');
youtube.commentThreads.list ({
"part": "id,snippet",
"maxResults": 10,
"order": "relevance",
"videoId": _idVideo
}, function (error, response) {
if (error)
{
reject (error);
}
if (response)
{
resolve ({
data: response,
noVideo: _noVideo
});
}
});
});
var result = await commentPromise.then (function (data) {
var getVideoComments = async function (_idVideo, _noVideo) {
var commentPromise = new Promise (function (resolve, reject) {
moment.locale ('fr');
youtube.commentThreads.list ({
"part": "id,snippet",
"maxResults": 10,
"order": "relevance",
"videoId": _idVideo
}, function (error, response) {
if (error)
{
reject (error);
}
if (response)
{
resolve ({
data: response,
noVideo: _noVideo
});
}
});
});
var result = await commentPromise.then (function (data) {
// console.log ('comment :');
// console.log(data);
return data;
});
return result;
};
var getAllVideos = async function () {
moment.locale ('fr');
var result = await getVideosID ().catch (function (errorGetVideosID) {
console.log ('errorGetVideosID : ' + errorGetVideosID);
}).then (function (dataListVideo) {
return data;
});
return result;
};
var getAllVideos = async function () {
moment.locale ('fr');
var result = await getVideosID ().catch (function (errorGetVideosID) {
console.log ('errorGetVideosID : ' + errorGetVideosID);
}).then (function (dataListVideo) {
// console.log ('dataListVideo : ');
// console.log (dataListVideo);
var nbOfVideo = dataListVideo.data.pageInfo.totalResults;
var resultData = new Array ();
var resultComment = new Array ();
console.log ('nombre de videos : ' + nbOfVideo);
var resultForEach = asyncForEach (dataListVideo.data.items, async function (p, n) {
resultData[n] = await getVideoInfo (p.id.videoId, n).then (function (videoData) {
let description = splitTxt (videoData.data.data.items[0].snippet.description, 100);
let resultDataBuffer = {
id: p.id.videoId,
title: videoData.data.data.items[0].snippet.title,
date: moment (videoData.data.data.items[0].snippet.publishedAt).format ('LL'),
description1: videoData.data.data.items[0].snippet.description,
description2: description.chaine1,
thumbnail: videoData.data.data.items[0].snippet.thumbnails.standard.url,
tags: videoData.data.data.items[0].snippet.tags,
comments: new Array ()
};
var nbOfVideo = dataListVideo.data.pageInfo.totalResults;
var resultData = new Array ();
var resultComment = new Array ();
console.log ('nombre de videos : ' + nbOfVideo);
var resultForEach = asyncForEach (dataListVideo.data.items, async function (p, n) {
resultData[n] = await getVideoInfo (p.id.videoId, n).then (function (videoData) {
let description = splitTxt (videoData.data.data.items[0].snippet.description, 100);
let resultDataBuffer = {
id: p.id.videoId,
title: videoData.data.data.items[0].snippet.title,
date: moment (videoData.data.data.items[0].snippet.publishedAt).format ('LL'),
description1: videoData.data.data.items[0].snippet.description,
description2: description.chaine1,
thumbnail: videoData.data.data.items[0].snippet.thumbnails.medium.url,
poster: videoData.data.data.items[0].snippet.thumbnails.standard.url,
tags: videoData.data.data.items[0].snippet.tags,
comments: new Array ()
};
// console.log ('resultDataBuffer : ');
// console.log (resultDataBuffer);
return resultDataBuffer;
});
return resultDataBuffer;
});
// console.log ('resultData[n] : ');
// console.log (resultData[n]);
var authorizedComment = true;
resultComment[n] = await getVideoComments (p.id.videoId, n)
.catch (function (e) {
var authorizedComment = true;
resultComment[n] = await getVideoComments (p.id.videoId, n)
.catch (function (e) {
// console.log ('error comment' + e);
// console.log ('error video ' + n);
authorizedComment = false;
return [
{
author: '',
text: '',
avatar: '',
date: ''
}
];
})
.then (function (responseComments) {
if (authorizedComment && responseComments.data.data.items.length > 0)
{
var resultCommentBuffer = new Array ();
responseComments.data.data.items.forEach (function (q, m) {
resultCommentBuffer[m] = {
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')
};
});
authorizedComment = false;
return [
{
author: '',
text: '',
avatar: '',
date: ''
}
];
})
.then (function (responseComments) {
if (authorizedComment && responseComments.data.data.items.length > 0)
{
var resultCommentBuffer = new Array ();
responseComments.data.data.items.forEach (function (q, m) {
resultCommentBuffer[m] = {
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 ('resultCommentBuffer :');
// console.log (resultCommentBuffer);
return resultCommentBuffer;
}
else
{
return resultCommentBuffer;
}
else
{
// console.log ('pas de commentaire pour cette video');
return [
{
author: '',
text: '',
avatar: '',
date: ''
}
];
}
});
resultData[n].comments = resultComment[n];
}).then (function () {
return [
{
author: '',
text: '',
avatar: '',
date: ''
}
];
}
});
resultData[n].comments = resultComment[n];
}).then (function () {
// console.log ('resultData : ');
// console.log (resultData);
return resultData;
});
return resultForEach;
});
return resultData;
});
return resultForEach;
});
// console.log ('RESULTAT');
// console.log ('------------------------------');
// console.log (result);
return result;
}
;
module.exports = {
getAllVideos: getAllVideos
};
return result;
}
;
module.exports = {
getAllVideos: getAllVideos
};
// autres écritures possible :

@@ -189,26 +190,26 @@

function splitTxt (_chaine, _middle) {
let lgTxt = _chaine.length;
let chaine1 = _chaine.slice (0, Math.max (Math.floor (lgTxt / 2), _middle));
let chaine2 = _chaine.slice (Math.max (Math.floor (lgTxt / 2), _middle));
let lastSpacePos = chaine1.lastIndexOf (' ');
if (lgTxt !== chaine1.length)
{
let pieceOfChaine = chaine1.slice (lastSpacePos);
chaine1 = chaine1.slice (0, lastSpacePos);
chaine2 = pieceOfChaine + chaine2;
}
return {
chaine1: chaine1,
chaine2: chaine2
};
}
;
async function asyncForEach (array, callback) {
for (let index = 0;
index < array.length;
index ++)
{
await callback (array[index], index, array);
}
}
function splitTxt (_chaine, _middle) {
let lgTxt = _chaine.length;
let chaine1 = _chaine.slice (0, Math.max (Math.floor (lgTxt / 2), _middle));
let chaine2 = _chaine.slice (Math.max (Math.floor (lgTxt / 2), _middle));
let lastSpacePos = chaine1.lastIndexOf (' ');
if (lgTxt !== chaine1.length)
{
let pieceOfChaine = chaine1.slice (lastSpacePos);
chaine1 = chaine1.slice (0, lastSpacePos);
chaine2 = pieceOfChaine + chaine2;
}
return {
chaine1: chaine1,
chaine2: chaine2
};
}
;
async function asyncForEach (array, callback) {
for (let index = 0;
index < array.length;
index ++)
{
await callback (array[index], index, array);
}
}
{
"name": "@micmac/youtube",
"version": "4.0.0",
"version": "4.0.1",
"description": "utilisation api youtube data",

@@ -5,0 +5,0 @@ "main": "main.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc