youtube-comment-api
Advanced tools
Comparing version 2.0.1 to 2.0.2
@@ -1,10 +0,5 @@ | ||
var cheerio = require('cheerio'); | ||
var Promise = require('native-promise-only'); | ||
var debug = require('debug')('video-info'); | ||
var _ = require('lodash'); | ||
var request = require('./request'); | ||
var fetchYoutubeVideoInfo = require('youtube-info'); | ||
var config = require('./config'); | ||
var YT_COMMENTS_URL = 'https://www.youtube.com/all_comments?v='; | ||
var cache = {}; | ||
@@ -17,34 +12,17 @@ | ||
} else { | ||
debug('Fetching video info'); | ||
return request.get(YT_COMMENTS_URL + videoID).then(function (responseText) { | ||
if(!responseText) { | ||
throw new Error('Fetching video info failed. Emtpy response.'); | ||
return fetchYoutubeVideoInfo(videoID).then(function (youtubeVideoInfo) { | ||
var info = { | ||
videoCommentCount: youtubeVideoInfo.commentCount, | ||
videoTitle: youtubeVideoInfo.title, | ||
videoThumbnail: youtubeVideoInfo.thumbnailUrl | ||
} | ||
var $ = cheerio.load(responseText.trim()); | ||
var videoTitle = $('.yt > a').text(); | ||
videoTitle = videoTitle ? videoTitle.trim() : null; | ||
debug('Fetched video title %s', videoTitle); | ||
var commentCount = 0; | ||
var m = /\(([\d,]+)\)$/gi.exec($('.all-comments').text().trim()); | ||
if (m && m[1]) { | ||
commentCount = parseInt(m[1].replace(',', ''), 10); | ||
} | ||
debug('Fetched comment count %d', commentCount); | ||
var videoInfo = { | ||
videoCommentCount: commentCount, | ||
videoTitle: videoTitle, | ||
videoThumbnail: 'http://img.youtube.com/vi/' + videoID + '/0.jpg' | ||
} | ||
// cache the video info | ||
debug('Caching video info for %d seconds', config().cacheDuration); | ||
cache[videoID] = { | ||
videoInfo: videoInfo, | ||
videoInfo: info, | ||
expires: Date.now() + (config().cacheDuration * 1000) | ||
}; | ||
return videoInfo; | ||
return info; | ||
}); | ||
@@ -51,0 +29,0 @@ } |
{ | ||
"name": "youtube-comment-api", | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"description": "Youtube comment API", | ||
@@ -34,3 +34,4 @@ "main": "index.js", | ||
"native-promise-only": "^0.8.1", | ||
"request-promise": "^0.4.3" | ||
"request-promise": "^0.4.3", | ||
"youtube-info": "^1.1.0" | ||
}, | ||
@@ -37,0 +38,0 @@ "devDependencies": { |
193751
6
957
+ Addedyoutube-info@^1.1.0
+ Addedajv@4.11.8(transitive)
+ Addedassert-plus@0.2.0(transitive)
+ Addedaws-sign2@0.6.0(transitive)
+ Addedbluebird@3.7.2(transitive)
+ Addedboom@2.10.1(transitive)
+ Addedcall-bind@1.0.8(transitive)
+ Addedcall-bind-apply-helpers@1.0.2(transitive)
+ Addedcall-bound@1.0.3(transitive)
+ Addedco@4.6.0(transitive)
+ Addedcryptiles@2.0.5(transitive)
+ Addeddefine-data-property@1.1.4(transitive)
+ Addeddunder-proto@1.0.1(transitive)
+ Addedes-define-property@1.0.1(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedes-object-atoms@1.1.1(transitive)
+ Addedform-data@2.1.4(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-intrinsic@1.2.7(transitive)
+ Addedget-proto@1.0.1(transitive)
+ Addedgopd@1.2.0(transitive)
+ Addedhar-schema@1.0.5(transitive)
+ Addedhar-validator@4.2.1(transitive)
+ Addedhas-property-descriptors@1.0.2(transitive)
+ Addedhas-symbols@1.1.0(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedhawk@3.1.3(transitive)
+ Addedhoek@2.16.3(transitive)
+ Addedhttp-signature@1.1.1(transitive)
+ Addedisarray@2.0.5(transitive)
+ Addedjson-stable-stringify@1.2.1(transitive)
+ Addedjsonify@0.0.1(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedlodash.isfunction@3.0.9(transitive)
+ Addedmath-intrinsics@1.1.0(transitive)
+ Addedoauth-sign@0.8.2(transitive)
+ Addedobject-keys@1.1.1(transitive)
+ Addedperformance-now@0.2.0(transitive)
+ Addedpunycode@1.4.1(transitive)
+ Addedqs@6.4.1(transitive)
+ Addedrequest@2.81.0(transitive)
+ Addedrequest-promise@4.2.6(transitive)
+ Addedrequest-promise-core@1.1.4(transitive)
+ Addedset-function-length@1.2.2(transitive)
+ Addedsntp@1.0.9(transitive)
+ Addedstealthy-require@1.1.1(transitive)
+ Addedstringstream@0.0.6(transitive)
+ Addedtough-cookie@2.3.4(transitive)
+ Addedyoutube-info@1.3.2(transitive)