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 2.1.2 to 2.9.0

336

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: "AIzaSyDrKXRexz1LVUguEacndEgdgfxeEPhKTsA"
});
var SearchAlexVideos = function () {
this.alexVideos = new Object();
this.lastTenVideos();
};
SearchAlexVideos.prototype = {
lastTenVideos: function () {
moment.locale('fr');
youtube.search.list({
"part": "id,snippet",
"channelId": "UCtToNyHU2Fjxuh__ypkHiIQ",
"maxResults": 10,
"order": "date",
"type": "video"
}, function (err, response) {
if (err) {
this.alexVideos = {'Error': err};
}
if (response) {
response.data.items.forEach(function (p, n) {
var description = p.snippet.description;
var descriptionSplit = splitTxt(description);
p.snippet.description = descriptionSplit.chaine1;
p.snippet.description2 = descriptionSplit.chaine2;
this.alexVideos[n] = {'urlThumbnails': p.snippet.thumbnails.high.url,
'idVideo': p.id.videoId,
'description': p.snippet.description,
'description2': p.snippet.description2,
'date': moment(p.snippet.publishedAt).format('LL'),
'title': p.snippet.title};
}.bind(this));
}
}.bind(this));
}
};
var SearchThisVideo = function () {
this.videoParams = new Object();
};
SearchThisVideo.prototype = {
get: function (_idVideo, success, error) {
moment.locale('fr');
youtube.videos.list({
"part": "id,snippet,contentDetails",
"id": _idVideo,
"maxResults": 1
}, function (err, res) {
if (err) {
error(err);
}
if (res) {
success(res);
}
}.bind(this));
},
getVideoDetails: function (_idVideo) {
this.get(_idVideo,
function (res) {
moment.locale('fr');
res.data.items[0].snippet.publishedAt = moment(res.data.items[0].snippet.publishedAt).format('LL');
return res;
},
function (err) {
console.log(err);
return err;
});
},
goToVideoPage: function (_idVideo, cssFile, _res, _adr) {
this.get(_idVideo,
function (res) {
moment.locale('fr');
res.data.items[0].snippet.publishedAt = moment(res.data.items[0].snippet.publishedAt).format('LL');
var description = res.data.items[0].snippet.description;
var descriptionSplit = splitTxt(description);
res.data.items[0].snippet.description = descriptionSplit.chaine1;
res.data.items[0].snippet.description2 = descriptionSplit.chaine2;
this.params = {
css: cssFile,
videoData: res
};
_res.render(_adr, {
params: this.params
});
console.log(this.params.videoData.data.items[0].snippet);
},
function (err) {
console.log(err);
return err;
});
}
};
var {
google
} = require ('googleapis');
var moment = require ('moment');
var youtube = google.youtube ({
version: 'v3',
auth: "AIzaSyDrKXRexz1LVUguEacndEgdgfxeEPhKTsA"
});
module.exports = {
SearchThisVideo: SearchThisVideo,
SearchVideos: SearchAlexVideos
};
var videoFullInfos = new Object ();
var getVideosID = function () {
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 = function (_idVideo) {
return 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 (response);
}
})
})
};
var getVideoComments = function (_idVideo) {
return 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 (response);
}
})
})
};
var getAllVideosInfos = function () {
moment.locale ('fr');
getVideosID ().then (function (response) {
response.data.items.forEach (function (p, n) {
getVideoInfo (p.id.videoId).then (function (response) {
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);
}).catch (function (error) {
console.log ('getVideoInfo : ' + error);
});
getVideoComments (p.id.videoId).then (function (response) {
console.log ('nombre de commentaires : ' + response.data.pageInfo.totalResults);
if (response.data.pageInfo.totalResults > 0)
{
response.data.items.forEach (function (p, n) {
console.log ('id video commentée : ' + p.snippet.videoId);
console.log ('auteur du commentaire : ' + p.snippet.topLevelComment.snippet.authorDisplayName);
console.log ('commentaire : ' + p.snippet.topLevelComment.snippet.textOriginal);
console.log ('url avatar auteur : ' + p.snippet.topLevelComment.snippet.authorProfileImageUrl);
console.log ('date du commentaire : ' + moment (p.snippet.topLevelComment.snippet.publishedAt).format ('LL'));
})
}
}).catch (function (error) {
console.log ('comment ERROR : ' + error);
});
})
}).catch (function (error) {
console.log ('getVideoId ERROR : ' + error);
})
}
var SearchAllVideos = function () {
this.allVideos = new Object ( );
this.lastTenVideos ( );
};
SearchAllVideos.prototype = {
lastTenVideos: function ( ) {
moment.locale ('fr');
youtube.search.list ({
"part": "id,snippet",
"channelId": "UCtToNyHU2Fjxuh__ypkHiIQ",
"maxResults": 10,
"order": "date",
"type": "video"
}, function (err, response) {
if (err)
{
this.allVideos = {
'Error': err
};
}
if (response)
{
response.data.items.forEach (function (p, n) {
var description = p.snippet.description;
var descriptionSplit = splitTxt (description);
p.snippet.description = descriptionSplit.chaine1;
p.snippet.description2 = descriptionSplit.chaine2;
this.allVideos[n] = {
'urlThumbnails': p.snippet.thumbnails.high.url,
'idVideo': p.id.videoId,
'description': p.snippet.description,
'description2': p.snippet.description2,
'date': moment (p.snippet.publishedAt).format ('LL'),
'title': p.snippet.title
};
}.bind (this));
}
}.bind (this));
}
};
var SearchThisVideo = function ( ) {
this.videoParams = new Object ( );
};
SearchThisVideo.prototype = {
get: function (_idVideo, success, error) {
moment.locale ('fr');
youtube.videos.list ({
"part": "id,snippet,contentDetails",
"id": _idVideo,
"maxResults": 1
}, function (err, res) {
if (err)
{
error (err);
}
if (res)
{
success (res);
}
}.bind (this));
},
getVideoDetails: function (_idVideo) {
this.get (_idVideo,
function (res) {
moment.locale ('fr');
res.data.items[0].snippet.publishedAt = moment (res.data.items[0].snippet.publishedAt).format ('LL');
return res;
},
function (err) {
console.log (err);
return err;
});
},
goToVideoPage: function (_idVideo, cssFile, _res, _adr) {
this.get (_idVideo,
function (res) {
moment.locale ('fr');
res.data.items[0].snippet.publishedAt = moment (res.data.items[0].snippet.publishedAt).format ('LL');
var description = res.data.items[0].snippet.description;
var descriptionSplit = splitTxt (description);
res.data.items[0].snippet.description = descriptionSplit.chaine1;
res.data.items[0].snippet.description2 = descriptionSplit.chaine2;
this.params = {
css: cssFile,
videoData: res
};
_res.render (_adr, {
params: this.params
});
},
function (err) {
console.log (err);
return err;
});
}
};
module.exports = {
SearchThisVideo: SearchThisVideo,
SearchVideos: SearchAllVideos,
getAllVideosInfos: getAllVideosInfos
};
// autres écritures possible :

@@ -111,14 +219,18 @@

function splitTxt(_chaine) {
let lgTxt = _chaine.length;
let chaine1 = _chaine.slice(0, Math.max(Math.floor(lgTxt / 2), 300));
let chaine2 = _chaine.slice(Math.max(Math.floor(lgTxt / 2), 300));
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};
}
;
function splitTxt (_chaine) {
let lgTxt = _chaine.length;
let chaine1 = _chaine.slice (0, Math.max (Math.floor (lgTxt / 2), 300));
let chaine2 = _chaine.slice (Math.max (Math.floor (lgTxt / 2), 300));
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
};
}
;
{
"name": "@micmac/youtube",
"version": "2.1.2",
"version": "2.9.0",
"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