irl-test.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. var assert = require('assert');
  2. var https = require('https');
  3. var nock = require('nock');
  4. var ytdl = require('..');
  5. var videos = {
  6. 'Regular video': 'http://www.youtube.com/watch?v=mgOS64BF2eU',
  7. 'VEVO': 'http://www.youtube.com/watch?v=qQ31INpjXX0',
  8. 'VEVO 2': 'http://www.youtube.com/watch?v=pJk0p-98Xzc',
  9. 'Age restricted': 'https://www.youtube.com/watch?v=otfd2UTrP_Q',
  10. };
  11. describe('Try downloading videos without mocking', function() {
  12. before(function() {
  13. nock.restore();
  14. ytdl.cache = null;
  15. });
  16. for (var desc in videos) {
  17. var video = videos[desc];
  18. describe(desc, function() {
  19. it('Request status code is not 403 Forbidden', function(done) {
  20. ytdl.getInfo(video, {
  21. downloadURL: true,
  22. debug: false,
  23. }, function(err, info) {
  24. if (err) return done(err);
  25. var url = info.formats[0].url;
  26. var req = https.get(url);
  27. req.on('response', function(res) {
  28. assert.notEqual(res.statusCode, 403);
  29. req.abort();
  30. done();
  31. });
  32. req.on('error', done);
  33. });
  34. });
  35. });
  36. }
  37. });