added verbose option for additional information

fixed the response error printing
This commit is contained in:
Luca 2020-03-29 22:56:01 +02:00
parent 089fec6001
commit 0cb8594d0f

View file

@ -12,9 +12,11 @@ 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
* exitCode 29 = invalid response from API
* exitCode 88 = error extracting cookies * exitCode 88 = error extracting cookies
*/ */
const ApiVersion = "1.3-private"
const args: string[] = process.argv.slice(2); // TODO: Remove this const args: string[] = process.argv.slice(2); // TODO: Remove this
const argv = yargs.options({ const argv = yargs.options({
@ -23,18 +25,27 @@ const argv = yargs.options({
outputDirectory: { type: 'string', default: 'videos' }, outputDirectory: { type: 'string', default: 'videos' },
format: { 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', 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: { 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)", 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
},
verbose: {
alias: "v",
describe: `Print additional informations to the console
(don't use this if you don't need/ not told to)`,
type: "boolean", type: "boolean",
default: false, default: false,
demandOption: false demandOption: false
} }
}).argv; }).argv;
if (argv.simulate){ if (argv.simulate){
@ -182,17 +193,24 @@ async function getVideoInfo(videoID: string, accesToken: string) {
let hlsUrl: string; let hlsUrl: string;
let content = axios.get( let content = axios.get(
`https://euwe-1.api.microsoftstream.com/api/videos/${videoID}?$expand=creator,tokens,status,liveEvent,extensions&api-version=1.3-private`, `https://euwe-1.api.microsoftstream.com/api/videos/${videoID}` +
`?$expand=creator,tokens,status,liveEvent,extensions&api-version=${ApiVersion}`,
{ {
headers: { headers: {
Authorization: "Bearer " + accesToken Authorization: `Bearer ${accesToken}`
} }
}) })
.then(function (response) { .then(function (response) {
return response.data return response.data
}) })
.catch(function (error) { .catch(function (error) {
term.red("ERROR ")
console.error(error.response.status)
console.error("Exiting...")
if (argv.verbose)
console.error(error) console.error(error)
process.exit(29)
}) })
@ -201,6 +219,9 @@ async function getVideoInfo(videoID: string, accesToken: string) {
}) })
hlsUrl = await content.then(data => { hlsUrl = await content.then(data => {
if (argv.verbose)
console.log(JSON.stringify(data, undefined, 2))
for (const item of data["playbackUrls"]) { for (const item of data["playbackUrls"]) {
if (item["mimeType"] == "application/vnd.apple.mpegurl") if (item["mimeType"] == "application/vnd.apple.mpegurl")
return item["playbackUrl"] return item["playbackUrl"]