mirror of
https://github.com/snobu/destreamer.git
synced 2026-01-17 05:22:18 +00:00
Major code refactoring (#164)
* Added Chromium caching of identity provider cookies * Moved token expiry check in standalone method * Created refreshSession function * Session is now refreshed if the token expires * Linting fixes * Removed debug console.log() * Added CC support * Created function to prompt user for download parameters (interactive mode) * Fix data folder for puppeteer * Fixed multiple session error * Fix token expire time * Moved session refreshing to a more sensible place * Changed Metadata name to Video (to better reflect the data structure) * Complete CLI refactoring * Removed useless sleep function * Added outDir check from CLI * Complete input parsing refactoring (both inline and file) * Fixed and improved tests to work with the new input parsing * Moved and improved output path generation to videoUtils * Main code refactoring, added outpath to video type * Minor changes in spacing and type definition style * Updated readme after code refactoring * Fix if inputFile doesn't start with url on line 1 * Minor naming change * Use module 'winston' for logging * Created logge, changed all console.log and similar to use the logger * Added verbose logging, changed posterUrl property name on Video type * Moved GUID extraction to input parsing * Added support for group links * Fixed test after last input parsing update * Removed debug proces.exit() * Changed from desc to asc order for group videos * Updated test to reflect GUIDs output after parsing * Added couple of comments and restyled some imports * More readable verbose GUIDs logging * Removed unused errors * Temporary fix for timeout not working in ApiClient * Explicit class member accessibility * Defined array naming schema to be Array<T> * Defined type/interface schema to be type only * A LOT of type definitions
This commit is contained in:
89
test/test.ts
89
test/test.ts
@@ -1,59 +1,76 @@
|
||||
import { parseVideoUrls } from '../src/Utils';
|
||||
import { parseInputFile } from '../src/Utils';
|
||||
import puppeteer from 'puppeteer';
|
||||
import assert from 'assert';
|
||||
import tmp from 'tmp';
|
||||
import fs from 'fs';
|
||||
import { Session } from './Types';
|
||||
|
||||
let browser: any;
|
||||
let page: any;
|
||||
|
||||
describe('Puppeteer', () => {
|
||||
it('should grab GitHub page title', async () => {
|
||||
browser = await puppeteer.launch({
|
||||
const browser = await puppeteer.launch({
|
||||
headless: true,
|
||||
args: ['--disable-dev-shm-usage', '--fast-start', '--no-sandbox']
|
||||
});
|
||||
page = await browser.newPage();
|
||||
await page.goto("https://github.com/", { waitUntil: 'load' });
|
||||
|
||||
const page = await browser.newPage();
|
||||
await page.goto('https://github.com/', { waitUntil: 'load' });
|
||||
|
||||
let pageTitle = await page.title();
|
||||
assert.equal(true, pageTitle.includes('GitHub'));
|
||||
|
||||
await browser.close();
|
||||
}).timeout(25000); // yeah, this may take a while...
|
||||
}).timeout(30000); // yeah, this may take a while...
|
||||
});
|
||||
|
||||
describe('Destreamer', () => {
|
||||
it('should parse and sanitize URL list from file', () => {
|
||||
const testIn: string[] = [
|
||||
"https://web.microsoftstream.com/video/xxxxxxxx-zzzz-hhhh-rrrr-dddddddddddd",
|
||||
"https://web.microsoftstream.com/video/xxxxxxxx-zzzz-hhhh-rrrr-dddddddddddd?",
|
||||
"https://web.microsoftstream.com/video/xxxxxxxx-zzzz-hhhh-rrrr-dddddddddddd&",
|
||||
"",
|
||||
"https://web.microsoftstream.com/video/xxxxxxxx-zzzz-hhhh-rrrr-dddddddddddd?a=b&c",
|
||||
"https://web.microsoftstream.com/video/xxxxxxxx-zzzz-hhhh-rrrr-dddddddddddd?a",
|
||||
"https://web.microsoftstream.com/video/xxxxxxxx-zzzz-hhhh-rrrr-dddddddddd",
|
||||
"https://web.microsoftstream.com/video/xxxxxx-zzzz-hhhh-rrrr-dddddddddddd",
|
||||
""
|
||||
|
||||
describe('Destreamer parsing', () => {
|
||||
it('Input file to arrays of URLs and DIRs', async () => {
|
||||
const testSession: Session = {
|
||||
AccessToken: '',
|
||||
ApiGatewayUri: '',
|
||||
ApiGatewayVersion: ''
|
||||
};
|
||||
const testIn: Array<string> = [
|
||||
'https://web.microsoftstream.com/video/xxxxxxxx-aaaa-xxxx-xxxx-xxxxxxxxxxxx',
|
||||
'https://web.microsoftstream.com/video/xxxxxxxx-bbbb-xxxx-xxxx-xxxxxxxxxxxx?',
|
||||
' -dir = "luca"',
|
||||
'https://web.microsoftstream.com/video/xxxxxxxx-cccc-xxxx-xxxx-xxxxxxxxxxxx&',
|
||||
'',
|
||||
'https://web.microsoftstream.com/video/xxxxxxxx-dddd-xxxx-xxxx-xxxxxxxxxxxx?a=b&c',
|
||||
'https://web.microsoftstream.com/video/xxxxxxxx-eeee-xxxx-xxxx-xxxxxxxxxxxx?a',
|
||||
' -dir =\'checking/justToSee\'',
|
||||
'https://web.microsoftstream.com/video/xxxxxxxx-ffff-xxxx-xxxx-dddddddddd',
|
||||
'https://web.microsoftstream.com/video/xxxxxx-gggg-xxxx-xxxx-xxxxxxxxxxxx',
|
||||
''
|
||||
];
|
||||
const expectedOut: string[] = [
|
||||
"https://web.microsoftstream.com/video/xxxxxxxx-zzzz-hhhh-rrrr-dddddddddddd",
|
||||
"https://web.microsoftstream.com/video/xxxxxxxx-zzzz-hhhh-rrrr-dddddddddddd",
|
||||
"https://web.microsoftstream.com/video/xxxxxxxx-zzzz-hhhh-rrrr-dddddddddddd",
|
||||
"https://web.microsoftstream.com/video/xxxxxxxx-zzzz-hhhh-rrrr-dddddddddddd"
|
||||
const expectedGUIDsOut: Array<string> = [
|
||||
'xxxxxxxx-aaaa-xxxx-xxxx-xxxxxxxxxxxx',
|
||||
'xxxxxxxx-bbbb-xxxx-xxxx-xxxxxxxxxxxx',
|
||||
'xxxxxxxx-cccc-xxxx-xxxx-xxxxxxxxxxxx',
|
||||
'xxxxxxxx-dddd-xxxx-xxxx-xxxxxxxxxxxx',
|
||||
'xxxxxxxx-eeee-xxxx-xxxx-xxxxxxxxxxxx'
|
||||
];
|
||||
const expectedDirOut: Array<string> = [
|
||||
'videos',
|
||||
'luca',
|
||||
'videos',
|
||||
'videos',
|
||||
'videos'
|
||||
];
|
||||
const tmpFile = tmp.fileSync({ postfix: '.txt' });
|
||||
let testOut: string[];
|
||||
|
||||
fs.writeFileSync(tmpFile.fd, testIn.join('\r\n'));
|
||||
|
||||
testOut = parseVideoUrls([tmpFile.name])!;
|
||||
if (testOut.length !== expectedOut.length)
|
||||
assert.strictEqual(testOut, expectedOut, "URL list not sanitized");
|
||||
|
||||
for (let i=0, l=testOut.length; i<l; ++i) {
|
||||
if (testOut[i] !== expectedOut[i])
|
||||
assert.strictEqual(testOut[i], expectedOut[i], "URL not sanitized");
|
||||
const [testUrlOut , testDirOut]: Array<Array<string>> = await parseInputFile(tmpFile.name, 'videos', testSession);
|
||||
if (testUrlOut.length !== expectedGUIDsOut.length) {
|
||||
throw "Expected url list and test list don't have the same number of elements".red;
|
||||
}
|
||||
|
||||
assert.ok("sanitizeUrls ok");
|
||||
else if (testDirOut.length !== expectedDirOut.length) {
|
||||
throw "Expected dir list and test list don't have the same number of elements".red;
|
||||
}
|
||||
assert.deepStrictEqual(testUrlOut, expectedGUIDsOut,
|
||||
'Error in parsing the URLs, missmatch between test and expected'.red);
|
||||
assert.deepStrictEqual(testUrlOut, expectedGUIDsOut,
|
||||
'Error in parsing the DIRs, missmatch between test and expected'.red);
|
||||
assert.ok('Parsing of input file ok');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user