Added eslint rule: prefer single quotes when possible, prefer double to escaping
This commit is contained in:
parent
427b58d97d
commit
a6bfd54bfd
4 changed files with 21 additions and 20 deletions
|
@ -22,6 +22,7 @@
|
|||
"rules": {
|
||||
"semi": [2, "always"],
|
||||
"no-unused-vars": "off",
|
||||
"@typescript-eslint/no-unused-vars": "error"
|
||||
"@typescript-eslint/no-unused-vars": "error",
|
||||
"quotes": [2, "single", { "avoidEscape": true }]
|
||||
}
|
||||
}
|
10
Metadata.ts
10
Metadata.ts
|
@ -18,13 +18,13 @@ export async function getVideoMetadata(videoGuids: string[], session: Session):
|
|||
}
|
||||
});
|
||||
|
||||
title = response.data["name"];
|
||||
playbackUrl = response.data["playbackUrls"]
|
||||
title = response.data['name'];
|
||||
playbackUrl = response.data['playbackUrls']
|
||||
.filter((item: { [x: string]: string; }) =>
|
||||
item["mimeType"] == "application/vnd.apple.mpegurl")
|
||||
.map((item: { [x: string]: string }) => { return item["playbackUrl"]; })[0];
|
||||
item['mimeType'] == 'application/vnd.apple.mpegurl')
|
||||
.map((item: { [x: string]: string }) => { return item['playbackUrl']; })[0];
|
||||
|
||||
posterImage = response.data["posterImage"]["medium"]["url"];
|
||||
posterImage = response.data['posterImage']['medium']['url'];
|
||||
|
||||
metadata.push({
|
||||
title: title,
|
||||
|
|
|
@ -15,7 +15,7 @@ export class TokenCache {
|
|||
|
||||
return null;
|
||||
}
|
||||
let f = fs.readFileSync(tokenCacheFile, "utf8");
|
||||
let f = fs.readFileSync(tokenCacheFile, 'utf8');
|
||||
j = JSON.parse(f);
|
||||
|
||||
interface Jwt {
|
||||
|
@ -25,7 +25,7 @@ export class TokenCache {
|
|||
const decodedJwt: Jwt = jwtDecode(j.AccessToken);
|
||||
|
||||
let now = Math.floor(Date.now() / 1000);
|
||||
let exp = decodedJwt["exp"];
|
||||
let exp = decodedJwt['exp'];
|
||||
let timeLeft = exp - now;
|
||||
|
||||
let timeLeftInMinutes = Math.floor(timeLeft / 60);
|
||||
|
@ -48,7 +48,7 @@ export class TokenCache {
|
|||
|
||||
public Write(session: Session): void {
|
||||
let s = JSON.stringify(session, null, 4);
|
||||
fs.writeFile(".token_cache", s, (err: any) => {
|
||||
fs.writeFile('.token_cache', s, (err: any) => {
|
||||
if (err) {
|
||||
return console.error(err);
|
||||
}
|
||||
|
|
|
@ -26,17 +26,17 @@ const argv = yargs.options({
|
|||
username: { type: 'string', demandOption: false },
|
||||
outputDirectory: { type: 'string', alias: 'outputdirectory', default: 'videos' },
|
||||
format: {
|
||||
alias:"f",
|
||||
alias: 'f',
|
||||
describe: `Expose youtube-dl --format option, for details see\n
|
||||
https://github.com/ytdl-org/youtube-dl/blob/master/README.md#format-selection`,
|
||||
type: 'string',
|
||||
demandOption: false
|
||||
},
|
||||
simulate: {
|
||||
alias: "s",
|
||||
alias: 's',
|
||||
describe: `If this is set to true no video will be downloaded and the script
|
||||
will log the video info (default: false)`,
|
||||
type: "boolean",
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
demandOption: false
|
||||
},
|
||||
|
@ -91,7 +91,7 @@ async function DoInteractiveLogin(username?: string): Promise<Session> {
|
|||
console.log('Navigating to microsoftonline.com login page...');
|
||||
|
||||
// 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"]');
|
||||
|
||||
if (username) {
|
||||
|
@ -108,7 +108,7 @@ async function DoInteractiveLogin(username?: string): Promise<Session> {
|
|||
console.info('Got cookie. Consuming cookie...');
|
||||
|
||||
await sleep(4000);
|
||||
console.info("Calling Microsoft Stream API...");
|
||||
console.info('Calling Microsoft Stream API...');
|
||||
|
||||
let sessionInfo: any;
|
||||
let session = await page.evaluate(
|
||||
|
@ -122,7 +122,7 @@ async function DoInteractiveLogin(username?: string): Promise<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(`ApiGatewayVersion: ${session.ApiGatewayVersion}`);
|
||||
|
@ -144,7 +144,7 @@ function extractVideoGuid(videoUrls: string[]): string[] {
|
|||
else
|
||||
urls = videoUrls as string[];
|
||||
let videoGuids: string[] = [];
|
||||
let guid: string | undefined = "";
|
||||
let guid: string | undefined = '';
|
||||
for (let url of urls) {
|
||||
console.log(url);
|
||||
try {
|
||||
|
@ -169,7 +169,7 @@ async function downloadVideo(videoUrls: string[], outputDirectory: string, sessi
|
|||
console.log(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);
|
||||
await Promise.all(metadata.map(async video => {
|
||||
video.title = sanitize(video.title);
|
||||
|
@ -179,13 +179,13 @@ async function downloadVideo(videoUrls: string[], outputDirectory: string, sessi
|
|||
await drawThumbnail(video.posterImage, session.AccessToken);
|
||||
|
||||
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 +
|
||||
` --output "${outputDirectory}/${video.title}.mp4" --add-header ` +
|
||||
`Authorization:"Bearer ${session.AccessToken}" "${video.playbackUrl}"`;
|
||||
|
||||
if (argv.simulate) {
|
||||
youtubedlCmd = youtubedlCmd + " -s";
|
||||
youtubedlCmd = youtubedlCmd + ' -s';
|
||||
}
|
||||
|
||||
execSync(youtubedlCmd, { stdio: 'inherit' });
|
||||
|
|
Loading…
Reference in a new issue