youtube-comment-api
Advanced tools
Comparing version 2.0.0 to 2.0.1
var debug = require('debug')('comment-api'); | ||
var request = require('./request'); | ||
var config = require('./config'); | ||
var initializeSession = require('./youtube-session'); | ||
var fixEscapeSequences = require('./fix-escape-sequences'); | ||
var YT_AJAX_URL = 'https://www.youtube.com/comment_ajax?action_load_comments=1&order_by_time=True&filter='; | ||
var MAX_ATTEMPTS = 3; | ||
var numAttempts; | ||
var MAX_RETRIES; | ||
var numRetries; | ||
@@ -14,3 +14,4 @@ module.exports = function (videoID, pageToken) { | ||
} | ||
numAttempts = 0; | ||
MAX_RETRIES = config().fetchRetries; | ||
numRetries = 0; | ||
return fetch(videoID, pageToken); | ||
@@ -29,3 +30,5 @@ }; | ||
}).then(function (form) { | ||
return request.post(YT_AJAX_URL + videoID, form); | ||
return request.post( | ||
'https://www.youtube.com/comment_ajax?action_load_comments=1&order_by_time=True&filter=' + videoID, | ||
form); | ||
}).then(function (responseText) { | ||
@@ -48,4 +51,4 @@ if (!responseText) { | ||
debug('fetch failed: %s', error.message); | ||
if (numAttempts++ < MAX_ATTEMPTS) { | ||
debug('Retry %d of %d', numAttempts, MAX_ATTEMPTS); | ||
if (numRetries++ < MAX_RETRIES) { | ||
debug('Retry %d of %d', numRetries, MAX_RETRIES); | ||
return fetch(videoID, pageToken); | ||
@@ -52,0 +55,0 @@ } |
@@ -19,2 +19,3 @@ var _ = require('lodash'); | ||
includeVideoInfo: true, | ||
fetchRetries: 3, | ||
sessionTimeout: 60 * 30, // 30 minutes | ||
@@ -21,0 +22,0 @@ cacheDuration: 60 * 30, // 30 minutes |
var debug = require('debug')('replies-api'); | ||
var config = require('./config'); | ||
var request = require('./request'); | ||
@@ -6,5 +7,4 @@ var initializeSession = require('./youtube-session'); | ||
var YT_AJAX_REPLY_URL = 'https://www.youtube.com/comment_ajax?action_load_replies=1&order_by_time=True&tab=inbox'; | ||
var MAX_ATTEMPTS = 3; | ||
var numAttempts; | ||
var MAX_RETRIES = 3; | ||
var numRetries; | ||
@@ -18,3 +18,4 @@ module.exports = function (videoID, commentID) { | ||
} | ||
numAttempts = 0; | ||
MAX_RETRIES = config().fetchRetries; | ||
numRetries = 0; | ||
return fetch(videoID, commentID); | ||
@@ -31,3 +32,5 @@ }; | ||
}).then(function (params) { | ||
return request.post(YT_AJAX_REPLY_URL, params); | ||
return request.post( | ||
'https://www.youtube.com/comment_ajax?action_load_replies=1&order_by_time=True&tab=inbox', | ||
params); | ||
}).then(function (responseText) { | ||
@@ -48,4 +51,4 @@ if (!responseText) { | ||
if (error.status && error.status !== 200) { | ||
if (numAttempts++ < MAX_ATTEMPTS) { | ||
debug('Retry %d of %d', numAttempts, MAX_ATTEMPTS); | ||
if (numRetries++ < MAX_RETRIES) { | ||
debug('Retry %d of %d', numRetries, MAX_RETRIES); | ||
return fetch(videoID, commentID); | ||
@@ -52,0 +55,0 @@ } |
{ | ||
"name": "youtube-comment-api", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "Youtube comment API", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -72,9 +72,10 @@ # Youtube Comment API | ||
``` | ||
{ | ||
var fetchCommentPage = require('youtube-comment-api')({ | ||
includeReplies: true, | ||
includeVideoInfo: true, | ||
fetchRetries: 3, | ||
sessionTimeout: 60 * 30, // 30 minutes | ||
cacheDuration: 60 * 30, // 30 minutes | ||
cacheInterval: 60 * 5 // 5 minutes | ||
} | ||
}); | ||
``` | ||
@@ -86,5 +87,6 @@ | ||
| includeVideoInfo | Fetch meta information about video (default: true) | | ||
| sessionTimeout | Number of seconds after which the acquired session token is disgarded and a new one is requested. (default: 30 mins) | | ||
| cacheDuration | Number of seconds after which cached video meta info will be disgarded (default: 30 mins) | | ||
| cacheInterval | Length of the interval in seconds at which the video meta info cache entries are checked and disgarded if expired. (default 5 mins) | | ||
| fetchRetries | The number of retries if a fetch fails (default: 3) | | ||
| sessionTimeout | Number of seconds after which the acquired session token is discarded and a new one is requested. (default: 30 mins) | | ||
| cacheDuration | Number of seconds after which cached video meta info will be discarded (default: 30 mins) | | ||
| cacheInterval | Length of the interval in seconds at which the video meta info cache entries are checked and discarded if expired. (default 5 mins) | | ||
@@ -91,0 +93,0 @@ |
@@ -20,2 +20,3 @@ var expect = require('chai').expect; | ||
includeVideoInfo: true, | ||
fetchRetries: 3, | ||
sessionTimeout: 60 * 30, | ||
@@ -33,2 +34,3 @@ cacheDuration: 60 * 30, | ||
includeVideoInfo: true, | ||
fetchRetries: 3, | ||
sessionTimeout: 60 * 60, | ||
@@ -43,3 +45,3 @@ cacheDuration: 60 * 30, | ||
config({sessionTimeout: 60 * 90}); | ||
config({cacheDuration: 60 * 90, includeReplies: true, includeVideoInfo: false}); | ||
config({cacheDuration: 60 * 90, includeReplies: true, includeVideoInfo: false, fetchRetries: 4}); | ||
@@ -49,2 +51,3 @@ expect(config()).to.deep.equal({ | ||
includeVideoInfo: false, | ||
fetchRetries: 4, | ||
sessionTimeout: 60 * 90, | ||
@@ -61,2 +64,3 @@ cacheDuration: 60 * 90, | ||
includeVideoInfo: true, | ||
fetchRetries: 3, | ||
sessionTimeout: 60 * 90, | ||
@@ -69,2 +73,3 @@ cacheDuration: 60 * 90 | ||
includeVideoInfo: true, | ||
fetchRetries: 3, | ||
sessionTimeout: 60 * 90, | ||
@@ -71,0 +76,0 @@ cacheDuration: 60 * 90, |
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
194478
975
123