mirror of
https://github.com/snobu/destreamer.git
synced 2026-02-27 08:48:23 +00:00
removed useless old code
This commit is contained in:
@@ -6,10 +6,10 @@ import { ERROR_CODE } from './Errors';
|
|||||||
import { setProcessEvents } from './Events';
|
import { setProcessEvents } from './Events';
|
||||||
import { logger } from './Logger';
|
import { logger } from './Logger';
|
||||||
import { getPuppeteerChromiumPath } from './PuppeteerHelper';
|
import { getPuppeteerChromiumPath } from './PuppeteerHelper';
|
||||||
// import { drawThumbnail } from './Thumbnail';
|
import { drawThumbnail } from './Thumbnail';
|
||||||
import { TokenCache/* , refreshSession */} from './TokenCache';
|
import { TokenCache} from './TokenCache';
|
||||||
import { Video, Session } from './Types';
|
import { Video, Session } from './Types';
|
||||||
import { checkRequirements, /* ffmpegTimemarkToChunk, */parseInputFile, parseCLIinput, getUrlsFromPlaylist} from './Utils';
|
import { checkRequirements, parseInputFile, parseCLIinput, getUrlsFromPlaylist} from './Utils';
|
||||||
import { getVideosInfo, createUniquePaths } from './VideoUtils';
|
import { getVideosInfo, createUniquePaths } from './VideoUtils';
|
||||||
|
|
||||||
import { exec, execSync } from 'child_process';
|
import { exec, execSync } from 'child_process';
|
||||||
@@ -20,16 +20,15 @@ import path from 'path';
|
|||||||
import tmp from 'tmp';
|
import tmp from 'tmp';
|
||||||
|
|
||||||
|
|
||||||
const m3u8Parser: any = require('m3u8-parser'); // TODO: can we create an export or something for this?
|
// TODO: can we create an export or something for this?
|
||||||
|
const m3u8Parser: any = require('m3u8-parser');
|
||||||
const tokenCache: TokenCache = new TokenCache();
|
const tokenCache: TokenCache = new TokenCache();
|
||||||
export const chromeCacheFolder = '.chrome_data';
|
export const chromeCacheFolder = '.chrome_data';
|
||||||
tmp.setGracefulCleanup();
|
tmp.setGracefulCleanup();
|
||||||
|
|
||||||
// const { FFmpegCommand, FFmpegInput, FFmpegOutput } = require('@tedconf/fessonia')();
|
|
||||||
|
|
||||||
|
|
||||||
async function init(): Promise<void> {
|
async function init(): Promise<void> {
|
||||||
setProcessEvents(); // must be first!
|
setProcessEvents(); // must be first!
|
||||||
|
|
||||||
logger.level = argv.debug ? 'debug' : (argv.verbose ? 'verbose' : 'info');
|
logger.level = argv.debug ? 'debug' : (argv.verbose ? 'verbose' : 'info');
|
||||||
|
|
||||||
@@ -225,6 +224,10 @@ async function downloadVideo(videoGUIDs: Array<string>,
|
|||||||
const videoDecrypter = await getDecrypter(videoPlaylistUrl, session);
|
const videoDecrypter = await getDecrypter(videoPlaylistUrl, session);
|
||||||
const audioDecrypter = await getDecrypter(videoPlaylistUrl, session);
|
const audioDecrypter = await getDecrypter(videoPlaylistUrl, session);
|
||||||
|
|
||||||
|
if (!argv.noExperiments) {
|
||||||
|
await drawThumbnail(video.posterImageUrl, session);
|
||||||
|
}
|
||||||
|
|
||||||
// video download
|
// video download
|
||||||
const videoSegmentsDir = tmp.dirSync({
|
const videoSegmentsDir = tmp.dirSync({
|
||||||
prefix: 'video',
|
prefix: 'video',
|
||||||
@@ -313,152 +316,6 @@ async function downloadVideo(videoGUIDs: Array<string>,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
async function downloadVideo(videoGUIDs: Array<string>, outputDirectories: Array<string>, session: Session): Promise<void> {
|
|
||||||
|
|
||||||
logger.info('Fetching videos info... \n');
|
|
||||||
const videos: Array<Video> = createUniquePath (
|
|
||||||
await getVideoInfo(videoGUIDs, session, argv.closedCaptions),
|
|
||||||
outputDirectories, argv.outputTemplate, argv.format, argv.skip
|
|
||||||
);
|
|
||||||
|
|
||||||
if (argv.simulate) {
|
|
||||||
videos.forEach((video: Video) => {
|
|
||||||
logger.info(
|
|
||||||
'\nTitle: '.green + video.title +
|
|
||||||
'\nOutPath: '.green + video.outPath +
|
|
||||||
'\nPublished Date: '.green + video.publishDate +
|
|
||||||
'\nPlayback URL: '.green + video.playbackUrl +
|
|
||||||
((video.captionsUrl) ? ('\nCC URL: '.green + video.captionsUrl) : '')
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const [index, video] of videos.entries()) {
|
|
||||||
|
|
||||||
if (argv.skip && fs.existsSync(video.outPath)) {
|
|
||||||
logger.info(`File already exists, skipping: ${video.outPath} \n`);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (argv.keepLoginCookies && index !== 0) {
|
|
||||||
logger.info('Trying to refresh token...');
|
|
||||||
session = await refreshSession('https://web.microsoftstream.com/video/' + videoGUIDs[index]);
|
|
||||||
}
|
|
||||||
|
|
||||||
const pbar: cliProgress.SingleBar = new cliProgress.SingleBar({
|
|
||||||
barCompleteChar: '\u2588',
|
|
||||||
barIncompleteChar: '\u2591',
|
|
||||||
format: 'progress [{bar}] {percentage}% {speed} {eta_formatted}',
|
|
||||||
// process.stdout.columns may return undefined in some terminals (Cygwin/MSYS)
|
|
||||||
barsize: Math.floor((process.stdout.columns || 30) / 3),
|
|
||||||
stopOnComplete: true,
|
|
||||||
hideCursor: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
logger.info(`\nDownloading Video: ${video.title} \n`);
|
|
||||||
logger.verbose('Extra video info \n' +
|
|
||||||
'\t Video m3u8 playlist URL: '.cyan + video.playbackUrl + '\n' +
|
|
||||||
'\t Video tumbnail URL: '.cyan + video.posterImageUrl + '\n' +
|
|
||||||
'\t Video subtitle URL (may not exist): '.cyan + video.captionsUrl + '\n' +
|
|
||||||
'\t Video total chunks: '.cyan + video.totalChunks + '\n');
|
|
||||||
|
|
||||||
logger.info('Spawning ffmpeg with access token and HLS URL. This may take a few seconds...\n\n');
|
|
||||||
if (!process.stdout.columns) {
|
|
||||||
logger.warn(
|
|
||||||
'Unable to get number of columns from terminal.\n' +
|
|
||||||
'This happens sometimes in Cygwin/MSYS.\n' +
|
|
||||||
'No progress bar can be rendered, however the download process should not be affected.\n\n' +
|
|
||||||
'Please use PowerShell or cmd.exe to run destreamer on Windows.'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const headers: string = 'Authorization: Bearer ' + session.AccessToken;
|
|
||||||
|
|
||||||
if (!argv.noExperiments) {
|
|
||||||
await drawThumbnail(video.posterImageUrl, session);
|
|
||||||
}
|
|
||||||
|
|
||||||
const ffmpegInpt: any = new FFmpegInput(video.playbackUrl, new Map([
|
|
||||||
['headers', headers]
|
|
||||||
]));
|
|
||||||
const ffmpegOutput: any = new FFmpegOutput(video.outPath, new Map([
|
|
||||||
argv.acodec === 'none' ? ['an', null] : ['c:a', argv.acodec],
|
|
||||||
argv.vcodec === 'none' ? ['vn', null] : ['c:v', argv.vcodec],
|
|
||||||
['n', null]
|
|
||||||
]));
|
|
||||||
const ffmpegCmd: any = new FFmpegCommand();
|
|
||||||
|
|
||||||
const cleanupFn: () => void = () => {
|
|
||||||
pbar.stop();
|
|
||||||
|
|
||||||
if (argv.noCleanup) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
fs.unlinkSync(video.outPath);
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
// Future handling of an error (maybe)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
pbar.start(video.totalChunks, 0, {
|
|
||||||
speed: '0'
|
|
||||||
});
|
|
||||||
|
|
||||||
// prepare ffmpeg command line
|
|
||||||
ffmpegCmd.addInput(ffmpegInpt);
|
|
||||||
ffmpegCmd.addOutput(ffmpegOutput);
|
|
||||||
if (argv.closedCaptions && video.captionsUrl) {
|
|
||||||
const captionsInpt: any = new FFmpegInput(video.captionsUrl, new Map([
|
|
||||||
['headers', headers]
|
|
||||||
]));
|
|
||||||
|
|
||||||
ffmpegCmd.addInput(captionsInpt);
|
|
||||||
}
|
|
||||||
|
|
||||||
ffmpegCmd.on('update', async (data: any) => {
|
|
||||||
const currentChunks: number = ffmpegTimemarkToChunk(data.out_time);
|
|
||||||
|
|
||||||
pbar.update(currentChunks, {
|
|
||||||
speed: data.bitrate
|
|
||||||
});
|
|
||||||
|
|
||||||
// Graceful fallback in case we can't get columns (Cygwin/MSYS)
|
|
||||||
if (!process.stdout.columns) {
|
|
||||||
process.stdout.write(`--- Speed: ${data.bitrate}, Cursor: ${data.out_time}\r`);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
process.on('SIGINT', cleanupFn);
|
|
||||||
|
|
||||||
// let the magic begin...
|
|
||||||
await new Promise((resolve: any) => {
|
|
||||||
ffmpegCmd.on('error', (error: any) => {
|
|
||||||
cleanupFn();
|
|
||||||
|
|
||||||
logger.error(`FFmpeg returned an error: ${error.message}`);
|
|
||||||
process.exit(ERROR_CODE.UNK_FFMPEG_ERROR);
|
|
||||||
});
|
|
||||||
|
|
||||||
ffmpegCmd.on('success', () => {
|
|
||||||
pbar.update(video.totalChunks); // set progress bar to 100%
|
|
||||||
logger.info(`\nDownload finished: ${video.outPath} \n`);
|
|
||||||
resolve();
|
|
||||||
});
|
|
||||||
|
|
||||||
ffmpegCmd.spawn();
|
|
||||||
});
|
|
||||||
|
|
||||||
process.removeListener('SIGINT', cleanupFn);
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async function main(): Promise<void> {
|
async function main(): Promise<void> {
|
||||||
await init(); // must be first
|
await init(); // must be first
|
||||||
|
|||||||
Reference in New Issue
Block a user