From c122241cc305bcea83562a455dcc6dda0b3a95e0 Mon Sep 17 00:00:00 2001 From: talmobi Date: Mon, 19 Aug 2024 21:32:19 +0300 Subject: [PATCH] feat: custom RETRY_INTERVAL in search query options --- src/index.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/index.js b/src/index.js index 3ba5332..ac5d3fc 100644 --- a/src/index.js +++ b/src/index.js @@ -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 @@ -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 ) @@ -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++) {