Added eslint rule: prefer single quotes when possible, prefer double to escaping

This commit is contained in:
snobu 2020-04-09 12:48:49 +03:00
parent 427b58d97d
commit a6bfd54bfd
4 changed files with 21 additions and 20 deletions

View file

@ -22,6 +22,7 @@
"rules": { "rules": {
"semi": [2, "always"], "semi": [2, "always"],
"no-unused-vars": "off", "no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "error" "@typescript-eslint/no-unused-vars": "error",
"quotes": [2, "single", { "avoidEscape": true }]
} }
} }

View file

@ -18,13 +18,13 @@ export async function getVideoMetadata(videoGuids: string[], session: Session):
} }
}); });
title = response.data["name"]; title = response.data['name'];
playbackUrl = response.data["playbackUrls"] playbackUrl = response.data['playbackUrls']
.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 }) => { return item["playbackUrl"]; })[0]; .map((item: { [x: string]: string }) => { return item['playbackUrl']; })[0];
posterImage = response.data["posterImage"]["medium"]["url"]; posterImage = response.data['posterImage']['medium']['url'];
metadata.push({ metadata.push({
title: title, title: title,

View file

@ -15,7 +15,7 @@ export class TokenCache {
return null; return null;
} }
let f = fs.readFileSync(tokenCacheFile, "utf8"); let f = fs.readFileSync(tokenCacheFile, 'utf8');
j = JSON.parse(f); j = JSON.parse(f);
interface Jwt { interface Jwt {
@ -25,7 +25,7 @@ export class TokenCache {
const decodedJwt: Jwt = jwtDecode(j.AccessToken); const decodedJwt: Jwt = jwtDecode(j.AccessToken);
let now = Math.floor(Date.now() / 1000); let now = Math.floor(Date.now() / 1000);
let exp = decodedJwt["exp"]; let exp = decodedJwt['exp'];
let timeLeft = exp - now; let timeLeft = exp - now;
let timeLeftInMinutes = Math.floor(timeLeft / 60); let timeLeftInMinutes = Math.floor(timeLeft / 60);
@ -48,7 +48,7 @@ export class TokenCache {
public Write(session: Session): void { public Write(session: Session): void {
let s = JSON.stringify(session, null, 4); let s = JSON.stringify(session, null, 4);
fs.writeFile(".token_cache", s, (err: any) => { fs.writeFile('.token_cache', s, (err: any) => {
if (err) { if (err) {
return console.error(err); return console.error(err);
} }

View file

@ -26,17 +26,17 @@ const argv = yargs.options({
username: { type: 'string', demandOption: false }, username: { type: 'string', demandOption: false },
outputDirectory: { type: 'string', alias: 'outputdirectory', default: 'videos' }, outputDirectory: { type: 'string', alias: 'outputdirectory', default: 'videos' },
format: { format: {
alias:"f", alias: 'f',
describe: `Expose youtube-dl --format option, for details see\n describe: `Expose youtube-dl --format option, for details see\n
https://github.com/ytdl-org/youtube-dl/blob/master/README.md#format-selection`, https://github.com/ytdl-org/youtube-dl/blob/master/README.md#format-selection`,
type:'string', type: 'string',
demandOption: false demandOption: false
}, },
simulate: { simulate: {
alias: "s", alias: 's',
describe: `If this is set to true no video will be downloaded and the script describe: `If this is set to true no video will be downloaded and the script
will log the video info (default: false)`, will log the video info (default: false)`,
type: "boolean", type: 'boolean',
default: false, default: false,
demandOption: false demandOption: false
}, },
@ -91,7 +91,7 @@ async function DoInteractiveLogin(username?: string): Promise<Session> {
console.log('Navigating to microsoftonline.com login page...'); console.log('Navigating to microsoftonline.com login page...');
// This breaks on slow connections, needs more reliable logic // This breaks on slow connections, needs more reliable logic
await page.goto('https://web.microsoftstream.com', { waitUntil: "networkidle2" }); await page.goto('https://web.microsoftstream.com', { waitUntil: 'networkidle2' });
await page.waitForSelector('input[type="email"]'); await page.waitForSelector('input[type="email"]');
if (username) { if (username) {
@ -108,7 +108,7 @@ async function DoInteractiveLogin(username?: string): Promise<Session> {
console.info('Got cookie. Consuming cookie...'); console.info('Got cookie. Consuming cookie...');
await sleep(4000); await sleep(4000);
console.info("Calling Microsoft Stream API..."); console.info('Calling Microsoft Stream API...');
let sessionInfo: any; let sessionInfo: any;
let session = await page.evaluate( let session = await page.evaluate(
@ -122,7 +122,7 @@ async function DoInteractiveLogin(username?: string): Promise<Session> {
); );
tokenCache.Write(session); tokenCache.Write(session);
console.info("Wrote access token to token cache."); console.info('Wrote access token to token cache.');
console.log(`ApiGatewayUri: ${session.ApiGatewayUri}`); console.log(`ApiGatewayUri: ${session.ApiGatewayUri}`);
console.log(`ApiGatewayVersion: ${session.ApiGatewayVersion}`); console.log(`ApiGatewayVersion: ${session.ApiGatewayVersion}`);
@ -144,7 +144,7 @@ function extractVideoGuid(videoUrls: string[]): string[] {
else else
urls = videoUrls as string[]; urls = videoUrls as string[];
let videoGuids: string[] = []; let videoGuids: string[] = [];
let guid: string | undefined = ""; let guid: string | undefined = '';
for (let url of urls) { for (let url of urls) {
console.log(url); console.log(url);
try { try {
@ -169,7 +169,7 @@ async function downloadVideo(videoUrls: string[], outputDirectory: string, sessi
console.log(videoUrls); console.log(videoUrls);
const videoGuids = extractVideoGuid(videoUrls); const videoGuids = extractVideoGuid(videoUrls);
console.log("Fetching title and HLS URL..."); console.log('Fetching title and HLS URL...');
let metadata: Metadata[] = await getVideoMetadata(videoGuids, session); let metadata: Metadata[] = await getVideoMetadata(videoGuids, session);
await Promise.all(metadata.map(async video => { await Promise.all(metadata.map(async video => {
video.title = sanitize(video.title); video.title = sanitize(video.title);
@ -179,13 +179,13 @@ async function downloadVideo(videoUrls: string[], outputDirectory: string, sessi
await drawThumbnail(video.posterImage, session.AccessToken); await drawThumbnail(video.posterImage, session.AccessToken);
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}/${video.title}.mp4" --add-header ` + ` --output "${outputDirectory}/${video.title}.mp4" --add-header ` +
`Authorization:"Bearer ${session.AccessToken}" "${video.playbackUrl}"`; `Authorization:"Bearer ${session.AccessToken}" "${video.playbackUrl}"`;
if (argv.simulate) { if (argv.simulate) {
youtubedlCmd = youtubedlCmd + " -s"; youtubedlCmd = youtubedlCmd + ' -s';
} }
execSync(youtubedlCmd, { stdio: 'inherit' }); execSync(youtubedlCmd, { stdio: 'inherit' });