1
0
mirror of https://github.com/snobu/destreamer.git synced 2026-01-17 05:22:18 +00:00

Enfore semicolon via eslint rules, some code cleanup

This commit is contained in:
snobu
2020-03-30 14:01:47 +03:00
parent dc400110ac
commit 5de6d1b8e6
5 changed files with 1118 additions and 144 deletions

View File

@@ -20,5 +20,6 @@
"@typescript-eslint" "@typescript-eslint"
], ],
"rules": { "rules": {
"semi": [2, "always"]
} }
} }

3
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,3 @@
{
"eslint.enable": true
}

View File

@@ -4,11 +4,10 @@ import { terminal as term } from 'terminal-kit';
import fs from 'fs'; import fs from 'fs';
import path from 'path'; import path from 'path';
import { BrowserTests } from './BrowserTests'; import { BrowserTests } from './BrowserTests';
import yargs from 'yargs' import yargs from 'yargs';
import sanitize from 'sanitize-filename' import sanitize from 'sanitize-filename';
import axios from 'axios'; import axios from 'axios';
/** /**
* exitCode 25 = cannot split videoID from videUrl * exitCode 25 = cannot split videoID from videUrl
* exitCode 27 = no hlsUrl in the API response * exitCode 27 = no hlsUrl in the API response
@@ -48,14 +47,12 @@ const argv = yargs.options({
if (argv.simulate){ if (argv.simulate){
console.info('Video URLs: %s', argv.videoUrls); console.info('Video URLs: %s', argv.videoUrls);
console.info('Username: %s', argv.username); console.info('Username: %s', argv.username);
term.blue("There will be no video downloaded, it's only a simulation \n") term.blue("There will be no video downloaded, it's only a simulation\n");
console.log("\n")
} else { } else {
console.info('Video URLs: %s', argv.videoUrls); console.info('Video URLs: %s', argv.videoUrls);
console.info('Username: %s', argv.username); console.info('Username: %s', argv.username);
console.info('Output Directory: %s', argv.outputDirectory); console.info('Output Directory: %s', argv.outputDirectory);
console.info('Video/Audio Quality: %s', argv.format); console.info('Video/Audio Quality: %s', argv.format);
console.log("\n")
} }
@@ -111,7 +108,8 @@ async function rentVideoForLater(videoUrls: string[], outputDirectory: string, u
await sleep(1500); await sleep(1500);
for (let videoUrl of videoUrls) { for (let videoUrl of videoUrls) {
let videoID = videoUrl.split('/').pop() ?? (console.error("Couldn't split the videoID, wrong url"), process.exit(25)) let videoID = videoUrl.split('/').pop() ??
(console.error("Couldn't split the videoID, wrong url"), process.exit(25));
// changed waitUntil value to load (page completly loaded) // changed waitUntil value to load (page completly loaded)
await page.goto(videoUrl, { waitUntil: 'load' }); await page.goto(videoUrl, { waitUntil: 'load' });
@@ -133,38 +131,39 @@ async function rentVideoForLater(videoUrls: string[], outputDirectory: string, u
AccessToken: sessionInfo.AccessToken, AccessToken: sessionInfo.AccessToken,
ApiGatewayUri: sessionInfo.ApiGatewayUri, ApiGatewayUri: sessionInfo.ApiGatewayUri,
ApiGatewayVersion: sessionInfo.ApiGatewayVersion ApiGatewayVersion: sessionInfo.ApiGatewayVersion
} };
} }
); );
console.log(`ApiGatewayUri: ${session.ApiGatewayUri}`); console.log(`ApiGatewayUri: ${session.ApiGatewayUri}`);
console.log(`ApiGatewayVersion: ${session.ApiGatewayVersion}`); console.log(`ApiGatewayVersion: ${session.ApiGatewayVersion}`);
console.log("Fetching title and HLS URL...") console.log("Fetching title and HLS URL...");
var [title, hlsUrl] = await getVideoInfo(videoID, session); var [title, hlsUrl] = await getVideoInfo(videoID, session);
title = (sanitize(title) == "") ? title = (sanitize(title) == "") ?
`Video${videoUrls.indexOf(videoUrl)}` : `Video${videoUrls.indexOf(videoUrl)}` :
sanitize(title) sanitize(title);
term.blue("Video title is: "); term.blue("Video title is: ");
console.log(`${title} \n`); console.log(`${title} \n`);
console.log('Spawning youtube-dl with cookie and HLS URL...'); console.log('Spawning youtube-dl with cookie and HLS URL...');
const format = argv.format ? `-f "${argv.format}"` : "" const format = argv.format ? `-f "${argv.format}"` : "";
var youtubedlCmd = 'youtube-dl --no-call-home --no-warnings ' + format + var youtubedlCmd = 'youtube-dl --no-call-home --no-warnings ' + format +
` --output "${outputDirectory}/${title}.mp4" --add-header ` + ` --output "${outputDirectory}/${title}.mp4" --add-header ` +
`Cookie:"${cookie}" "${hlsUrl}"` `Cookie:"${cookie}" "${hlsUrl}"`;
if (argv.simulate) if (argv.simulate) {
youtubedlCmd = youtubedlCmd + " -s" youtubedlCmd = youtubedlCmd + " -s";
}
if (argv.verbose) { if (argv.verbose) {
console.log(`\n\n[VERBOSE] Invoking youtube-dl:\n${youtubedlCmd}\n\n`); console.log(`\n\n[VERBOSE] Invoking youtube-dl:\n${youtubedlCmd}\n\n`);
} }
var result = execSync(youtubedlCmd, { stdio: 'inherit' }); execSync(youtubedlCmd, { stdio: 'inherit' });
} }
console.log("At this point Chrome's job is done, shutting it down..."); console.log("At this point Chrome's job is done, shutting it down...");
@@ -221,12 +220,12 @@ async function getVideoInfo(videoID: string, session: any) {
console.error(`[VERBOSE] ${error}`); console.error(`[VERBOSE] ${error}`);
} }
process.exit(29); process.exit(29);
}) });
title = await content.then(data => { title = await content.then(data => {
return data["name"]; return data["name"];
}) });
hlsUrl = await content.then(data => { hlsUrl = await content.then(data => {
if (argv.verbose) { if (argv.verbose) {
@@ -238,7 +237,7 @@ async function getVideoInfo(videoID: string, session: any) {
.filter((item: { [x: string]: string; }) => .filter((item: { [x: string]: string; }) =>
item["mimeType"] == "application/vnd.apple.mpegurl") item["mimeType"] == "application/vnd.apple.mpegurl")
.map((item: { [x: string]: string }) => .map((item: { [x: string]: string }) =>
{ return item["playbackUrl"] })[0]; { return item["playbackUrl"]; })[0];
} }
catch (e) { catch (e) {
console.error(`Error fetching HLS URL: ${e}.\n playbackUrl is ${playbackUrl}`); console.error(`Error fetching HLS URL: ${e}.\n playbackUrl is ${playbackUrl}`);
@@ -246,7 +245,7 @@ async function getVideoInfo(videoID: string, session: any) {
} }
return playbackUrl; return playbackUrl;
}) });
return [title, hlsUrl]; return [title, hlsUrl];
} }

1216
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -19,7 +19,10 @@
"devDependencies": { "devDependencies": {
"@types/puppeteer": "^1.20.0", "@types/puppeteer": "^1.20.0",
"@types/terminal-kit": "^1.28.1", "@types/terminal-kit": "^1.28.1",
"@types/yargs": "^15.0.3" "@types/yargs": "^15.0.3",
"@typescript-eslint/eslint-plugin": "^2.25.0",
"@typescript-eslint/parser": "^2.25.0",
"eslint": "^6.8.0"
}, },
"dependencies": { "dependencies": {
"axios": "^0.19.2", "axios": "^0.19.2",