From 65fb75ef449ea6b2dd46a92fe73eacbff7a65c37 Mon Sep 17 00:00:00 2001 From: Kiko Beats Date: Fri, 25 Jan 2019 13:40:35 -0500 Subject: [PATCH] test: update snapshots --- test/getInfo.js | 259 ++++++++++++++++++++++++++--------------------- test/playlist.js | 215 +++++++++++++++++++++------------------ 2 files changed, 260 insertions(+), 214 deletions(-) diff --git a/test/getInfo.js b/test/getInfo.js index 05a5506..af41562 100644 --- a/test/getInfo.js +++ b/test/getInfo.js @@ -1,127 +1,154 @@ -var vows = require('vows'); -var ytdl = require('..'); -var assert = require('assert'); +var vows = require('vows') +var ytdl = require('..') +var assert = require('assert') -vows.describe('getInfo').addBatch({ - 'from a youtube video': { - 'topic': function () { - 'use strict'; - var video = 'http://www.youtube.com/watch?v=90AiXO1pAiA'; - ytdl.getInfo(video, ['-f', '18/43/36'], this.callback); - }, +vows + .describe('getInfo') + .addBatch({ + 'from a youtube video': { + topic: function () { + 'use strict' + var video = 'http://www.youtube.com/watch?v=90AiXO1pAiA' + ytdl.getInfo(video, ['-f', '18/43/36'], this.callback) + }, - 'info returned': function (err, info) { - 'use strict'; + 'info returned': function (err, info) { + 'use strict' - assert.isNull(err); - assert.isObject(info); - assert.equal(info.id, '90AiXO1pAiA'); - assert.equal(info.format_id, '18'); - assert.equal(info.title, 'lol'); - assert.isString(info.url); - assert.isString(info.thumbnail); - assert.equal(info.description, - 'Ridley High School\'s real American Bad ASS,A true Delco Savage. ' + - 'Filmed in 2003 before Youtube was invented. ' + - 'This is also the original I find it hilarious that there are copycat videos!'); - assert.equal(info._filename, 'lol-90AiXO1pAiA.mp4'); - assert.equal(info.format, '18 - 480x360 (medium)'); - assert.equal(info._duration_raw, 11); - assert.equal(info._duration_hms, '00:00:11'); - assert.equal(info.duration, '11'); - assert.equal(info.width, 480); - assert.equal(info.height, 360); - assert.isArray(info.formats); - } - }, - 'from a youtube playlist': { - 'topic': function () { - 'use strict'; - var pl = 'https://www.youtube.com/playlist?list=PLEFA9E9D96CB7F807'; - ytdl.getInfo(pl, this.callback); + assert.isNull(err) + assert.isObject(info) + assert.equal(info.id, '90AiXO1pAiA') + assert.equal(info.format_id, '18') + assert.equal(info.title, 'lol') + assert.isString(info.url) + assert.isString(info.thumbnail) + assert.equal( + info.description, + "Ridley High School's real American Bad ASS,A true Delco Savage. " + + 'Filmed in 2003 before Youtube was invented. ' + + 'This is also the original I find it hilarious that there are copycat videos!' + ) + assert.equal(info._filename, 'lol-90AiXO1pAiA.mp4') + assert.equal(info.format, '18 - 480x360 (medium)') + assert.equal(info._duration_raw, 11) + assert.equal(info._duration_hms, '00:00:11') + assert.equal(info.duration, '11') + assert.equal(info.width, 480) + assert.equal(info.height, 360) + assert.isArray(info.formats) + } }, + 'from a youtube playlist': { + topic: function () { + 'use strict' + var pl = 'https://www.youtube.com/playlist?list=PLEFA9E9D96CB7F807' + ytdl.getInfo(pl, this.callback) + }, - 'info returned': function (err, info) { - 'use strict'; - assert.isNull(err); - assert.isArray(info); - assert.ok(info.length); - info.forEach(function (videoInfo) { - assert.isString(videoInfo.url); - }); - } - }, - 'from a twitch video': { - 'topic': function () { - 'use strict'; - var video = 'https://clips.twitch.tv/RelentlessOptimisticPterodactylRitzMitz'; - ytdl.getInfo(video, ['--no-warnings'], this.callback); + 'info returned': function (err, info) { + 'use strict' + assert.isNull(err) + assert.isArray(info) + assert.ok(info.length) + info.forEach(function (videoInfo) { + assert.isString(videoInfo.url) + }) + } }, + 'from a twitch video': { + topic: function () { + 'use strict' + var video = + 'https://clips.twitch.tv/RelentlessOptimisticPterodactylRitzMitz' + ytdl.getInfo(video, ['--no-warnings'], this.callback) + }, - 'info returned': function (err, info) { - 'use strict'; - assert.isNull(err); - assert.isObject(info); - assert.equal(info.id, '131170216'); - assert.equal(info.format_id, '1080'); - assert.equal(info.title, 'Worlds 2017 Play-In: Rampage vs. 1907 Fenerbahçe Espor'); - assert.isString(info.url); - assert.isString(info.thumbnail); - assert.equal(info.fulltitle, 'Worlds 2017 Play-In: Rampage vs. 1907 Fenerbahçe Espor'); - assert.equal(info._filename, 'Worlds 2017 Play-In - Rampage vs. 1907 Fenerbahçe Espor-131170216.mp4'); - assert.equal(info.format, '1080 - 1080p'); - assert.equal(info.height, 1080); - assert.equal(info._duration_raw, 29.75); - assert.equal(info._duration_hms, '00:00:29.750'); - assert.equal(info.duration, '29.75'); - assert.isArray(info.formats); - } - }, - - 'from multiple videos': { - 'topic': function () { - 'use strict'; - var youtube = 'http://www.youtube.com/watch?v=90AiXO1pAiA'; - var twitch = 'https://clips.twitch.tv/RelentlessOptimisticPterodactylRitzMitz'; - ytdl.getInfo([youtube, twitch], ['--no-warnings'], this.callback); + 'info returned': function (err, info) { + 'use strict' + assert.isNull(err) + assert.isObject(info) + assert.equal(info.id, '131170216') + assert.equal(info.format_id, '1080') + assert.equal( + info.title, + 'Worlds 2017 Play-In: Rampage vs. 1907 Fenerbahçe Espor' + ) + assert.isString(info.url) + assert.isString(info.thumbnail) + assert.equal( + info.fulltitle, + 'Worlds 2017 Play-In: Rampage vs. 1907 Fenerbahçe Espor' + ) + assert.equal( + info._filename, + 'Worlds 2017 Play-In - Rampage vs. 1907 Fenerbahçe Espor-131170216.mp4' + ) + assert.equal(info.format, '1080 - 1080p') + assert.equal(info.height, 1080) + assert.equal(info._duration_raw, 29.75) + assert.equal(info._duration_hms, '00:00:29.750') + assert.equal(info.duration, '29.75') + assert.isArray(info.formats) + } }, - 'info returned': function (err, info) { - 'use strict'; - assert.isNull(err); - assert.isArray(info); - assert.equal(info.length, 2); + 'from multiple videos': { + topic: function () { + 'use strict' + var youtube = 'http://www.youtube.com/watch?v=90AiXO1pAiA' + var twitch = + 'https://clips.twitch.tv/RelentlessOptimisticPterodactylRitzMitz' + ytdl.getInfo([youtube, twitch], ['--no-warnings'], this.callback) + }, + + 'info returned': function (err, info) { + 'use strict' + assert.isNull(err) + assert.isArray(info) + assert.equal(info.length, 2) - assert.equal(info[0].id, '90AiXO1pAiA'); - assert.equal(info[0].format_id, '43'); - assert.equal(info[0].title, 'lol'); - assert.isString(info[0].url); - assert.isString(info[0].thumbnail); - assert.equal(info[0].description, - 'Ridley High School\'s real American Bad ASS,A true Delco Savage. ' + - 'Filmed in 2003 before Youtube was invented. ' + - 'This is also the original I find it hilarious that there are copycat videos!'); - assert.equal(info[0]._filename, 'lol-90AiXO1pAiA.webm'); - assert.equal(info[0].format, '43 - 640x360 (medium)'); - assert.equal(info[0]._duration_raw, 11); - assert.equal(info[0]._duration_hms, '00:00:11'); - assert.equal(info[0].duration, '11'); - assert.equal(info[0].width, 640); - assert.equal(info[0].height, 360); - assert.isArray(info[0].formats); - assert.equal(info[1].id, '131170216'); - assert.equal(info[1].format_id, '1080'); - assert.equal(info[1].title, 'Worlds 2017 Play-In: Rampage vs. 1907 Fenerbahçe Espor'); - assert.isString(info[1].url); - assert.isString(info[1].thumbnail); - assert.equal(info[1].fulltitle, 'Worlds 2017 Play-In: Rampage vs. 1907 Fenerbahçe Espor'); - assert.equal(info[1]._filename, 'Worlds 2017 Play-In - Rampage vs. 1907 Fenerbahçe Espor-131170216.mp4'); - assert.equal(info[1].format, '1080 - 1080p'); - assert.equal(info[1].height, 1080); - assert.equal(info[1]._duration_raw, 29.75); - assert.equal(info[1]._duration_hms, '00:00:29.750'); - assert.equal(info[1].duration, '29.75'); - assert.isArray(info[1].formats); + assert.equal(info[0].id, '90AiXO1pAiA') + assert.equal(info[0].format_id, '18') + assert.equal(info[0].title, 'lol') + assert.isString(info[0].url) + assert.isString(info[0].thumbnail) + assert.equal( + info[0].description, + "Ridley High School's real American Bad ASS,A true Delco Savage. " + + 'Filmed in 2003 before Youtube was invented. ' + + 'This is also the original I find it hilarious that there are copycat videos!' + ) + assert.equal(info[0]._filename, 'lol-90AiXO1pAiA.mp4') + assert.equal(info[0].width, 480) + assert.equal(info[0].height, 360) + assert.equal(info[0].format, '18 - 480x360 (medium)') + assert.equal(info[0]._duration_raw, 11) + assert.equal(info[0]._duration_hms, '00:00:11') + assert.equal(info[0].duration, '11') + assert.isArray(info[0].formats) + assert.equal(info[1].id, '131170216') + assert.equal(info[1].format_id, '1080') + assert.equal( + info[1].title, + 'Worlds 2017 Play-In: Rampage vs. 1907 Fenerbahçe Espor' + ) + assert.isString(info[1].url) + assert.isString(info[1].thumbnail) + assert.equal( + info[1].fulltitle, + 'Worlds 2017 Play-In: Rampage vs. 1907 Fenerbahçe Espor' + ) + assert.equal( + info[1]._filename, + 'Worlds 2017 Play-In - Rampage vs. 1907 Fenerbahçe Espor-131170216.mp4' + ) + assert.equal(info[1].format, '1080 - 1080p') + assert.equal(info[1].height, 1080) + assert.equal(info[1]._duration_raw, 29.75) + assert.equal(info[1]._duration_hms, '00:00:29.750') + assert.equal(info[1].duration, '29.75') + assert.isArray(info[1].formats) + } } - } -}).export(module); + }) + .export(module) diff --git a/test/playlist.js b/test/playlist.js index 77ecfeb..0227ca8 100644 --- a/test/playlist.js +++ b/test/playlist.js @@ -1,104 +1,123 @@ -var vows = require('vows'); -var ytdl = require('..'); -var fs = require('fs'); -var path = require('path'); -var assert = require('assert'); -var video1 = 'https://www.youtube.com/playlist?list=PLEFA9E9D96CB7F807'; - -vows.describe('download playlist').addBatch({ - 'from a youtube playlist': { - 'topic': function () { - 'use strict'; - - var cb = this.callback; - var details = []; - var count = 0; - - function playlist(url) { - var dl = ytdl(url); - - dl.on('error', cb); - - dl.on('info', function (info) { - var pos = 0; - var progress; - - dl.on('data', function (data) { - pos += data.length; - progress = pos / info.size; - }); - - dl.on('end', function () { - details.push({ progress: progress, data: info }); - count = count + 1; - if (count === 2) { return cb(null, details); } - }); - - dl.on('next', playlist); - - var filepath = path.join(__dirname, info._filename); - dl.pipe(fs.createWriteStream(filepath)); - }); - } - - playlist(video1); - - }, - 'data returned': function (err, data) { - 'use strict'; - if (err) { throw err; } - assert.equal(data.length, 2); - assert.isArray(data); - assert.isObject(data[0]); - assert.isObject(data[1]); - }, - 'files downloaded': function (err, data) { - 'use strict'; - if (err) { throw err; } - assert.equal(data[0].progress, 1); - assert.equal(data[0].data._filename, 'Amy Castle - The Original Cuppycake Video-12Z6pWhM6TA.webm'); - assert.equal(data[1].progress, 1); - assert.equal(data[1].data._filename, 'LA REGAÑADA DEL MILENIO.wmv-SITuxqDUjPI.webm'); - - function fileExists(data) { - var filepath = path.join(__dirname, data._filename); - var exists = fs.existsSync(filepath); - - if (exists) { - // Delete file after each test. - fs.unlinkSync(filepath); - } else { - assert.isTrue(exists); +var vows = require('vows') +var ytdl = require('..') +var fs = require('fs') +var path = require('path') +var assert = require('assert') +var video1 = 'https://www.youtube.com/playlist?list=PLEFA9E9D96CB7F807' + +vows + .describe('download playlist') + .addBatch({ + 'from a youtube playlist': { + topic: function () { + 'use strict' + + var cb = this.callback + var details = [] + var count = 0 + + function playlist (url) { + var dl = ytdl(url) + + dl.on('error', cb) + + dl.on('info', function (info) { + var pos = 0 + var progress + + dl.on('data', function (data) { + pos += data.length + progress = pos / info.size + }) + + dl.on('end', function () { + details.push({ progress: progress, data: info }) + count = count + 1 + if (count === 2) { + return cb(null, details) + } + }) + + dl.on('next', playlist) + + var filepath = path.join(__dirname, info._filename) + dl.pipe(fs.createWriteStream(filepath)) + }) } - } - - fileExists(data[0].data); - fileExists(data[1].data); - - } - }, - 'thumbnails of a playlist': { - topic: function () { - 'use strict'; - ytdl.getThumbs(video1, { cwd: __dirname }, this.callback); - }, - 'data returned': function (err, files) { - 'use strict'; - if (err) { throw err; } + playlist(video1) + }, + 'data returned': function (err, data) { + 'use strict' + if (err) { + throw err + } + assert.equal(data.length, 2) + assert.isArray(data) + assert.isObject(data[0]) + assert.isObject(data[1]) + }, + 'files downloaded': function (err, data) { + 'use strict' + if (err) { + throw err + } + assert.equal(data[0].progress, 1) + assert.equal( + data[0].data._filename, + 'Amy Castle - The Original Cuppycake Video-12Z6pWhM6TA.webm' + ) + assert.equal(data[1].progress, 1) + assert.equal( + data[1].data._filename, + 'LA REGAÑADA DEL MILENIO.wmv-SITuxqDUjPI.mp4' + ) + + function fileExists (data) { + var filepath = path.join(__dirname, data._filename) + var exists = fs.existsSync(filepath) + + if (exists) { + // Delete file after each test. + fs.unlinkSync(filepath) + } else { + assert.isTrue(exists) + } + } - assert.equal(files[0], 'Amy Castle - The Original Cuppycake Video-12Z6pWhM6TA.jpg'); - assert.equal(files[1], 'LA REGAÑADA DEL MILENIO.wmv-SITuxqDUjPI.jpg'); + fileExists(data[0].data) + fileExists(data[1].data) + } }, + 'thumbnails of a playlist': { + topic: function () { + 'use strict' + ytdl.getThumbs(video1, { cwd: __dirname }, this.callback) + }, + + 'data returned': function (err, files) { + 'use strict' + if (err) { + throw err + } - 'thumbnails were downloaded': function (err, files) { - 'use strict'; - if (err) { throw err; } - assert.isTrue(fs.existsSync(path.join(__dirname, files[0]))); - assert.isTrue(fs.existsSync(path.join(__dirname, files[1]))); - fs.unlinkSync(path.join(__dirname, files[0])); - fs.unlinkSync(path.join(__dirname, files[1])); + assert.equal( + files[0], + 'Amy Castle - The Original Cuppycake Video-12Z6pWhM6TA.jpg' + ) + assert.equal(files[1], 'LA REGAÑADA DEL MILENIO.wmv-SITuxqDUjPI.jpg') + }, + + 'thumbnails were downloaded': function (err, files) { + 'use strict' + if (err) { + throw err + } + assert.isTrue(fs.existsSync(path.join(__dirname, files[0]))) + assert.isTrue(fs.existsSync(path.join(__dirname, files[1]))) + fs.unlinkSync(path.join(__dirname, files[0])) + fs.unlinkSync(path.join(__dirname, files[1])) + } } - - } -}).export(module); + }) + .export(module)