@micmac/youtube
Advanced tools
Comparing version 4.0.622 to 4.1.0
80
main.js
// fonction searchVideos retourne les 10 dernières videos de la chaine beerus | ||
var { | ||
} = require('googleapis'); | ||
var { google } = require('googleapis'); | ||
var moment = require('moment'); | ||
@@ -12,3 +10,3 @@ var youtube = google.youtube({ | ||
function getVideosID() { | ||
function getVideosID(_nbOfVideo) { | ||
return new Promise(function (resolve, reject) { | ||
@@ -19,3 +17,3 @@ moment.locale('fr'); | ||
"channelId": "UCtToNyHU2Fjxuh__ypkHiIQ", | ||
"maxResults": 10, | ||
"maxResults": _nbOfVideo, | ||
"order": "date", | ||
@@ -87,5 +85,7 @@ "type": "video" | ||
}; | ||
var getAllVideos = async function () { | ||
var getAllVideos = async function (_theme, _nbOfVideo) { | ||
const theme = _theme; | ||
moment.locale('fr'); | ||
var result = await getVideosID().catch(function (errorGetVideosID) { | ||
var result = await getVideosID(_nbOfVideo).catch(function (errorGetVideosID) { | ||
console.log('errorGetVideosID : ' + errorGetVideosID); | ||
@@ -109,14 +109,6 @@ }).then(function (dataListVideo) { | ||
tags: videoData.data.data.items[0].snippet.tags, | ||
comments: new Array() | ||
comments: new Array(), | ||
urlThumbMed: videoData.data.data.items[0].snippet.thumbnails.medium.url, | ||
urlThumbStand: videoData.data.data.items[0].snippet.thumbnails.medium.url | ||
}; | ||
const options1 = { | ||
url: videoData.data.data.items[0].snippet.thumbnails.medium.url, | ||
dest: './public/assets/img/thumbnails/medium/thumb'+p.id.videoId+'.jpg' | ||
} | ||
downloadIMG(options1); | ||
const options2 = { | ||
url: videoData.data.data.items[0].snippet.thumbnails.standard.url, | ||
dest: './public/assets/img/thumbnails/standard/thumb'+p.id.videoId+'.jpg' | ||
} | ||
downloadIMG(options2); | ||
// console.log ('resultDataBuffer : '); | ||
@@ -181,2 +173,3 @@ // console.log (resultDataBuffer); | ||
// console.log (result); | ||
recordThumb(result, theme); | ||
return result; | ||
@@ -186,3 +179,3 @@ } | ||
module.exports = { | ||
getAllVideos: getAllVideos | ||
getAllVideos: getAllVideos, | ||
}; | ||
@@ -215,15 +208,44 @@ // autres écritures possible : | ||
try { | ||
const { filename, image } = await download.image(_options) | ||
console.log(filename) // => /path/to/dest/image.jpg | ||
const { filename, image } = await download.image(_options) | ||
console.log(filename) // => /path/to/dest/image.jpg | ||
} catch (e) { | ||
console.error(e) | ||
console.error('erreur !!' + e); | ||
} | ||
}; | ||
async function asyncForEach (array, callback) { | ||
}; | ||
async function asyncForEach(array, callback) { | ||
for (let index = 0; | ||
index < array.length; | ||
index ++) | ||
{ | ||
await callback (array[index], index, array); | ||
} | ||
index < array.length; | ||
index++) { | ||
await callback(array[index], index, array); | ||
} | ||
} | ||
function recordThumb(_video, _theme) { | ||
var noTheme = 0; | ||
var matchThisVideo = false; | ||
var match = new Array(); | ||
_theme.map(thisTheme => { | ||
match[noTheme] = 0; | ||
_video.forEach(function ( thisVideo, key){ | ||
matchThisVideo = false; | ||
thisVideo.tags.map(thisTag => { | ||
if (thisTag.toLowerCase() == thisTheme.toLowerCase() && !matchThisVideo) { | ||
thisVideo.theme=thisTheme; | ||
const options1 = { | ||
url: thisVideo.urlThumbMed, | ||
dest: 'public/materials/thumbnails/medium/' + thisTheme + '/video' + match[noTheme] + '.jpg' | ||
} | ||
downloadIMG(options1); | ||
const options2 = { | ||
url: thisVideo.urlThumbStand, | ||
dest: 'public/materials/thumbnails/standard/' + thisTheme + '/video' + match[noTheme] + '.jpg' | ||
} | ||
downloadIMG(options2); | ||
match[noTheme]++; | ||
matchThisVideo = true; | ||
} | ||
}) | ||
}) | ||
noTheme++; | ||
}) | ||
} |
{ | ||
"name": "@micmac/youtube", | ||
"version": "4.0.622", | ||
"version": "4.1.0", | ||
"description": "utilisation api youtube data", | ||
@@ -5,0 +5,0 @@ "main": "main.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9541
236