1
0
mirror of https://github.com/snobu/destreamer.git synced 2026-02-09 00:09:44 +00:00

Merge branch 'tokencache' of https://github.com/snobu/destreamer into tokencache

This commit is contained in:
kylon
2020-04-10 12:35:32 +02:00
3 changed files with 217 additions and 23 deletions

View File

@@ -6,6 +6,7 @@ import { drawThumbnail } from './Thumbnail';
import isElevated from 'is-elevated';
import puppeteer from 'puppeteer';
import { execSync } from 'child_process';
import colors from 'colors';
import fs from 'fs';
import os from 'os';
@@ -170,32 +171,44 @@ async function downloadVideo(videoUrls: string[], outputDirectory: string, sessi
// Very experimental inline thumbnail rendering
await drawThumbnail(video.posterImage, session.AccessToken);
console.info('Spawning ffmpeg with access token and HLS URL...');
console.info('Spawning ffmpeg with access token and HLS URL. This may take a few seconds...\n');
const outputPath = outputDirectory + path.sep + video.title + '.mp4';
ffmpeg()
.input(video.playbackUrl)
.inputOption([
// Never remove those "useless" escapes or ffmpeg will not
// pick up the header correctly
// eslint-disable-next-line no-useless-escape
'-headers', `Authorization:\ Bearer\ ${session.AccessToken}`
])
.format('mp4')
.saveToFile(outputPath)
.on('codecData', data => {
console.log(`Input is ${data.video} with ${data.audio} audio.`);
})
.on('progress', progress => {
console.log(progress);
})
.on('error', err => {
console.log(`ffmpeg returned an error: ${err.message}`);
})
.on('end', () => {
console.log(`Download finished: ${outputPath}`);
});
// TODO: Remove this mess and it's fluent-ffmpeg dependency
//
// ffmpeg()
// .input(video.playbackUrl)
// .inputOption([
// // Never remove those "useless" escapes or ffmpeg will not
// // pick up the header correctly
// // eslint-disable-next-line no-useless-escape
// '-headers', `Authorization:\ Bearer\ ${session.AccessToken}`
// ])
// .format('mp4')
// .saveToFile(outputPath)
// .on('codecData', data => {
// console.log(`Input is ${data.video} with ${data.audio} audio.`);
// })
// .on('progress', progress => {
// console.log(progress);
// })
// .on('error', err => {
// console.log(`ffmpeg returned an error: ${err.message}`);
// })
// .on('end', () => {
// console.log(`Download finished: ${outputPath}`);
// });
// We probably need a way to be deterministic about
// how we locate that ffmpeg-bar wrapper, npx maybe?
// Do not remove those "useless" escapes or ffmpeg will
// not pick up the header correctly.
// eslint-disable-next-line no-useless-escape
let cmd = `node_modules/.bin/ffmpeg-bar -headers "Authorization:\ Bearer\ ${session.AccessToken}" -i "${video.playbackUrl}" -y "${outputPath}"`;
execSync(cmd, {stdio: 'inherit'});
console.info(`Download finished: ${outputPath}`);
}));
}