test-batch-large.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #!/usr/bin/env node
  2. /**
  3. * Test batch metadata with more URLs to show scaling benefit
  4. */
  5. const { spawn } = require('child_process');
  6. const path = require('path');
  7. // 10 test URLs
  8. const testUrls = [
  9. 'https://www.youtube.com/watch?v=jNQXAC9IVRw',
  10. 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
  11. 'https://www.youtube.com/watch?v=9bZkp7q19f0',
  12. 'https://www.youtube.com/watch?v=_OBlgSz8sSM',
  13. 'https://www.youtube.com/watch?v=kJQP7kiw5Fk',
  14. 'https://www.youtube.com/watch?v=uelHwf8o7_U',
  15. 'https://www.youtube.com/watch?v=OPf0YbXqDm0',
  16. 'https://www.youtube.com/watch?v=ZbZSe6N_BXs',
  17. 'https://www.youtube.com/watch?v=fJ9rUzIMcZQ',
  18. 'https://www.youtube.com/watch?v=L_jWHffIx5E'
  19. ];
  20. function getBinaryPath(name) {
  21. const ext = process.platform === 'win32' ? '.exe' : '';
  22. return path.join(__dirname, 'binaries', `${name}${ext}`);
  23. }
  24. function runCommand(command, args) {
  25. return new Promise((resolve, reject) => {
  26. const process = spawn(command, args);
  27. let output = '';
  28. let error = '';
  29. process.stdout.on('data', (data) => {
  30. output += data.toString();
  31. });
  32. process.stderr.on('data', (data) => {
  33. error += data.toString();
  34. });
  35. process.on('close', (code) => {
  36. if (code === 0) {
  37. resolve(output);
  38. } else {
  39. reject(new Error(error));
  40. }
  41. });
  42. });
  43. }
  44. async function testBatchMetadata(urls) {
  45. console.log(`\n🚀 Testing BATCH metadata extraction (${urls.length} URLs)...`);
  46. const ytDlpPath = getBinaryPath('yt-dlp');
  47. const startTime = Date.now();
  48. try {
  49. const args = [
  50. '--dump-json',
  51. '--no-warnings',
  52. '--skip-download',
  53. '--ignore-errors',
  54. '--extractor-args', 'youtube:skip=hls,dash',
  55. '--flat-playlist',
  56. ...urls
  57. ];
  58. const output = await runCommand(ytDlpPath, args);
  59. const lines = output.trim().split('\n');
  60. let successCount = 0;
  61. for (const line of lines) {
  62. if (!line.trim()) continue;
  63. try {
  64. JSON.parse(line);
  65. successCount++;
  66. } catch (error) {
  67. // Skip invalid lines
  68. }
  69. }
  70. const duration = Date.now() - startTime;
  71. const avgTime = duration / urls.length;
  72. console.log(` ✅ Fetched ${successCount}/${urls.length} videos`);
  73. console.log(` ⏱️ Total time: ${duration}ms`);
  74. console.log(` 📊 Average per video: ${avgTime.toFixed(1)}ms`);
  75. return { successCount, duration, avgTime };
  76. } catch (error) {
  77. console.error(' ❌ Batch fetch failed:', error.message);
  78. return null;
  79. }
  80. }
  81. async function main() {
  82. console.log('🧪 Batch Metadata Scaling Test');
  83. console.log('==============================\n');
  84. try {
  85. // Test with increasing number of URLs
  86. const testSizes = [4, 8, 10];
  87. for (const size of testSizes) {
  88. const urls = testUrls.slice(0, size);
  89. await testBatchMetadata(urls);
  90. }
  91. console.log('\n✅ Scaling test complete!');
  92. console.log('\n💡 Notice: Average time per video decreases as batch size increases!');
  93. console.log(' This is because we spawn fewer processes and leverage yt-dlp\'s');
  94. console.log(' internal connection pooling.');
  95. } catch (error) {
  96. console.error('❌ Test failed:', error);
  97. process.exit(1);
  98. }
  99. }
  100. main();