Will thumbnails render on Windows?

This commit is contained in:
snobu 2020-04-08 11:26:02 +03:00
parent a48812cb58
commit 1fc80d8366
3 changed files with 21 additions and 28 deletions

View file

@ -1,8 +1,7 @@
import axios from 'axios';
import { terminal as term } from 'terminal-kit';
import { Metadata, Session } from './Types';
import fs from 'fs';
import os from 'os';
import { drawThumbnail } from './Thumbnail';
export async function getVideoMetadata(videoGuids: string[], session: Session): Promise<Metadata[]> {
@ -28,7 +27,7 @@ export async function getVideoMetadata(videoGuids: string[], session: Session):
.map((item: { [x: string]: string }) => { return item["playbackUrl"]; })[0];
posterImage = response.data["posterImage"]["medium"]["url"];
term.brightMagenta(`\n title = ${title}\n playbackUrl = ${playbackUrl}\n`);
metadata.push({

View file

@ -1,27 +1,16 @@
import os from 'os';
import { terminal as term } from 'terminal-kit';
import { execSync } from 'child_process';
if (os.platform() !== "win32") {
term.brightWhite("Platform is not Windows, let's draw some thumbnails!\n");
let a = async () => {
response = await axios.get(posterImageUrl, {
headers: {
Authorization: `Bearer ${session.AccessToken}`
},
responseType: 'stream'
});
const writer = fs.createWriteStream('.thumbnail.png');
response.data.pipe(writer);
return new Promise((resolve, reject) => {
writer.on('finish', resolve);
writer.on('error', reject);
});
};
await a();
export function drawThumbnail(posterImage: string, accessToken: string): void {
let fetchCmd = `ffmpeg -hide_banner -loglevel warning ` +
`-headers "Authorization: Bearer ${accessToken}\r\n" ` +
`-i "${posterImage}" -y .thumbnail.png`;
execSync(fetchCmd, { stdio: 'inherit' });
try {
term.drawImage('.thumbnail.png', { shrink: { width: 50, height: 50 } });
}
catch (e) {
console.error(e);
}
}
term.drawImage('.thumbnail.png', { shrink: { width: 50, height: 50 } });

View file

@ -2,6 +2,7 @@ import { BrowserTests } from './Tests';
import { TokenCache } from './TokenCache';
import { getVideoMetadata } from './Metadata';
import { Metadata, Session } from './Types';
import { drawThumbnail } from './Thumbnail';
import { execSync } from 'child_process';
import puppeteer from 'puppeteer';
@ -171,9 +172,13 @@ async function downloadVideo(videoUrls: string[], outputDirectory: string, sessi
console.log("Fetching title and HLS URL...");
let metadata: Metadata[] = await getVideoMetadata(videoGuids, session);
metadata.forEach(video => {
await Promise.all(metadata.map(async video => {
video.title = sanitize(video.title);
term.blue(`\nDownloading Video: ${video.title}\n`);
drawThumbnail(video.posterImage, session.AccessToken);
await sleep(100); // there's something wrong with drawThumbnail we should not need this
console.log('Spawning youtube-dl with cookie and HLS URL...');
const format = argv.format ? `-f "${argv.format}"` : "";
var youtubedlCmd = 'youtube-dl --no-call-home --no-warnings ' + format +
@ -185,7 +190,7 @@ async function downloadVideo(videoUrls: string[], outputDirectory: string, sessi
}
execSync(youtubedlCmd, { stdio: 'inherit' });
});
}));
}