mirror of
https://github.com/snobu/destreamer.git
synced 2026-03-12 23:18:24 +00:00
Added a simulation flag to only extract video tile and urls without any file downloaded
Removede an outdated argv check because all arguments are now parsed with yargs
This commit is contained in:
@@ -15,17 +15,33 @@ const argv = yargs.options({
|
|||||||
videoUrls: { type: 'array', demandOption: true },
|
videoUrls: { type: 'array', demandOption: true },
|
||||||
username: { type: 'string', demandOption: true },
|
username: { type: 'string', demandOption: true },
|
||||||
outputDirectory: { type: 'string', default: 'videos' },
|
outputDirectory: { type: 'string', default: 'videos' },
|
||||||
format: { alias:"f",
|
format: {
|
||||||
|
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',
|
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',
|
type:'string',
|
||||||
demandOption: false
|
demandOption: false
|
||||||
|
},
|
||||||
|
simulate: {
|
||||||
|
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",
|
||||||
|
default: false,
|
||||||
|
demandOption: false
|
||||||
}
|
}
|
||||||
|
|
||||||
}).argv;
|
}).argv;
|
||||||
|
|
||||||
|
if (argv.simulate){
|
||||||
|
console.info('Video URLs: %s', argv.videoUrls);
|
||||||
|
console.info('Username: %s', argv.username);
|
||||||
|
term.blue("There will be no video downloaded, it's only a simulation \n")
|
||||||
|
} 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function sanityChecks() {
|
function sanityChecks() {
|
||||||
try {
|
try {
|
||||||
@@ -52,11 +68,8 @@ function sanityChecks() {
|
|||||||
fs.mkdirSync(argv.outputDirectory);
|
fs.mkdirSync(argv.outputDirectory);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args[0] == null || args[0].length < 10) {
|
/* Removed check on the first argoumenti not being null or
|
||||||
console.error('Pass in video URL as first argument:\n' +
|
longer than 10 since we have yargs now */
|
||||||
'Example: npm start https://www.microsoftstream.com/video/6f1a382b-e20c-44c0-98fc-5608286e48bc\n');
|
|
||||||
process.exit(-1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function rentVideoForLater(videoUrls: string[], username: string, outputDirectory: string) {
|
async function rentVideoForLater(videoUrls: string[], username: string, outputDirectory: string) {
|
||||||
@@ -92,20 +105,24 @@ async function rentVideoForLater(videoUrls: string[], username: string, outputDi
|
|||||||
|
|
||||||
await sleep(4000);
|
await sleep(4000);
|
||||||
console.log('Looking up AMS stream locator...');
|
console.log('Looking up AMS stream locator...');
|
||||||
// let amp: any;
|
|
||||||
let document: any;
|
let document: any;
|
||||||
const amsUrl = await page.evaluate(
|
const amsUrl = await page.evaluate(
|
||||||
// maybe there should be some check in case the url fetch fails
|
// maybe there should be some check in case the url fetch fails
|
||||||
() => { return document?.querySelector(".azuremediaplayer")?.player?.cache_?.src; }
|
() => {
|
||||||
|
return document?.querySelector(".azuremediaplayer")?.player?.cache_?.src;
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
// console.log(`Video url is: ${amsUrl}`);
|
// console.log(`Video url is: ${amsUrl}`);
|
||||||
console.log('Fetching title');
|
console.log('Fetching title...');
|
||||||
|
|
||||||
let title = await page.evaluate(
|
let title = await page.evaluate(
|
||||||
// Using optional chaining to return handle null case, generating default name
|
// Using optional chaining to return handle null case, generating default name
|
||||||
() => { return document?.querySelector(".title")?.textContent?.trim() ??
|
() => {
|
||||||
`Video${videoUrls.indexOf(videoUrl)}`; }
|
return document?.querySelector(".title")?.textContent?.trim() ??
|
||||||
|
`Video${videoUrls.indexOf(videoUrl)}`;
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
// Implemented sanitize-filename as suggested in issue #11
|
// Implemented sanitize-filename as suggested in issue #11
|
||||||
@@ -114,11 +131,13 @@ async function rentVideoForLater(videoUrls: string[], username: string, outputDi
|
|||||||
if (title == "")
|
if (title == "")
|
||||||
title = `Video${videoUrls.indexOf(videoUrl)}`
|
title = `Video${videoUrls.indexOf(videoUrl)}`
|
||||||
|
|
||||||
console.log(`Video title is: ${title}`);
|
//console.log(`Video title is: ${title}`);
|
||||||
|
|
||||||
console.log('Constructing HLS URL...');
|
console.log('Constructing HLS URL...');
|
||||||
const hlsUrl = amsUrl.substring(0, amsUrl.lastIndexOf('/')) + '/manifest(format=m3u8-aapl)';
|
const hlsUrl = amsUrl.substring(0, amsUrl.lastIndexOf('/')) + '/manifest(format=m3u8-aapl)';
|
||||||
|
|
||||||
|
// If the simulate flag is true skip the download
|
||||||
|
if (!argv.simulate) {
|
||||||
console.log('Spawning youtube-dl with cookie and HLS URL...');
|
console.log('Spawning youtube-dl with cookie and HLS URL...');
|
||||||
let format = ''
|
let format = ''
|
||||||
if (argv.format) {
|
if (argv.format) {
|
||||||
@@ -130,6 +149,13 @@ async function rentVideoForLater(videoUrls: string[], username: string, outputDi
|
|||||||
|
|
||||||
// console.log(`\n\n[DEBUG] Invoking youtube-dl: ${youtubedlCmd}\n\n`);
|
// console.log(`\n\n[DEBUG] Invoking youtube-dl: ${youtubedlCmd}\n\n`);
|
||||||
var result = execSync(youtubedlCmd, { stdio: 'inherit' });
|
var result = execSync(youtubedlCmd, { stdio: 'inherit' });
|
||||||
|
} else {
|
||||||
|
// Logging the video info
|
||||||
|
term.blue("Video title is: ")
|
||||||
|
console.log(`${title}`)
|
||||||
|
term.blue("Video url is: ")
|
||||||
|
console.log(`${hlsUrl}`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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...");
|
||||||
|
|||||||
Reference in New Issue
Block a user