Skip to content

Commit 09103ca

Browse files
authored
Merge pull request #320 from DialmasterOrg/318-hardcoded-10s-timeout-in-video-validation-causes-invalid-url-errors
fix: increase video validation timeout from 10s to 60s
2 parents 66395f6 + d5d074c commit 09103ca

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

server/modules/__tests__/videoValidationModule.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ describe('VideoValidationModule', () => {
422422
const result = await videoValidationModule.fetchVideoMetadata(url);
423423

424424
expect(result).toEqual(mockMetadata);
425-
expect(ytDlpRunner.fetchMetadata).toHaveBeenCalledWith(url, 10000);
425+
expect(ytDlpRunner.fetchMetadata).toHaveBeenCalledWith(url, 60000);
426426
});
427427

428428
it('should log error and rethrow when fetch fails', async () => {

server/modules/videoValidationModule.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class VideoValidationModule {
7979
* @returns {Promise<Object>} - Video metadata
8080
*/
8181
async fetchVideoMetadata(url, options = {}) {
82-
const { timeoutMs = 10000 } = options;
82+
const { timeoutMs = 60000 } = options;
8383

8484
try {
8585
const metadata = await ytDlpRunner.fetchMetadata(url, timeoutMs);
@@ -238,7 +238,7 @@ class VideoValidationModule {
238238
}
239239

240240
logger.debug({ videoId }, 'Fetching metadata for video');
241-
const metadata = await this.fetchVideoMetadata(canonicalUrl, { timeoutMs: 10000 });
241+
const metadata = await this.fetchVideoMetadata(canonicalUrl, { timeoutMs: 60000 });
242242

243243
const isDuplicateVideo = await this.isDuplicate(videoId);
244244

server/modules/ytDlpRunner.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,23 @@ class YtDlpRunner {
119119
* @param {number} timeoutMs - Timeout in milliseconds
120120
* @returns {Promise<Object>} - Parsed JSON metadata
121121
*/
122-
async fetchMetadata(url, timeoutMs = 10000) {
122+
async fetchMetadata(url, timeoutMs = 60000) {
123123
const YtdlpCommandBuilder = require('./download/ytdlpCommandBuilder');
124-
const args = YtdlpCommandBuilder.buildMetadataFetchArgs(url);
124+
let args = YtdlpCommandBuilder.buildMetadataFetchArgs(url);
125+
126+
// When fetching metadata, we don't want to use --sleep-requests as we are only making a single request
127+
// So we remove it from the args and also remove the arg after it (number of seconds)
128+
args = args.filter((arg) => {
129+
if (arg.startsWith('--sleep-requests')) {
130+
// Strip the next argument as well
131+
const index = args.indexOf(arg);
132+
if (index !== -1 && index + 1 < args.length) {
133+
args.splice(index + 1, 1);
134+
}
135+
return false;
136+
}
137+
return true;
138+
});
125139

126140
try {
127141
const stdout = await this.run(args, { timeoutMs });

0 commit comments

Comments
 (0)