Skip to content

Commit

Permalink
feat: custom RETRY_INTERVAL in search query options
Browse files Browse the repository at this point in the history
  • Loading branch information
talmobi committed Aug 19, 2024
1 parent 31c5740 commit c122241
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ function search ( query, callback )

function callback_with_retry ( err, data ) {
if ( err ) {
if ( _options._attempts > MAX_RETRY_ATTEMPTS ) {
if ( _options._attempts > ( _options.MAX_RETRY_ATTEMPTS || MAX_RETRY_ATTEMPTS ) ) {
return callback( err, data )
} else {
// retry
Expand All @@ -145,7 +145,7 @@ function search ( query, callback )
debug( ' === ' )

const n = _options._attempts
const wait_ms = Math.pow( 2, n - 1 ) * RETRY_INTERVAL
const wait_ms = Math.pow( 2, n - 1 ) * (_options.RETRY_INTERVAL || RETRY_INTERVAL)

setTimeout( function () {
search( retryOptions, callback )
Expand Down Expand Up @@ -1072,7 +1072,12 @@ function _parseVideoInitialData ( responseText, callback )
// genre/category information seems to be lost completely
if (!video.description || !video.timestamp || !video.seconds || !video.views) {
setTimeout(function () {
search( `${video.videoId}`, function (err, r) {
search( {
query: `${video.videoId}`,
options: {
RETRY_INTERVAL: 1000
},
}, function (err, r) {
if (err) return callback(err)
if (!r.videos) return callback( null, video )
for (let i = 0; i < r.videos.length; i++) {
Expand Down

0 comments on commit c122241

Please sign in to comment.