Will thumbnails render on Windows?
This commit is contained in:
parent
a48812cb58
commit
1fc80d8366
3 changed files with 21 additions and 28 deletions
|
@ -1,8 +1,7 @@
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { terminal as term } from 'terminal-kit';
|
import { terminal as term } from 'terminal-kit';
|
||||||
import { Metadata, Session } from './Types';
|
import { Metadata, Session } from './Types';
|
||||||
import fs from 'fs';
|
import { drawThumbnail } from './Thumbnail';
|
||||||
import os from 'os';
|
|
||||||
|
|
||||||
|
|
||||||
export async function getVideoMetadata(videoGuids: string[], session: Session): Promise<Metadata[]> {
|
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];
|
.map((item: { [x: string]: string }) => { return item["playbackUrl"]; })[0];
|
||||||
|
|
||||||
posterImage = response.data["posterImage"]["medium"]["url"];
|
posterImage = response.data["posterImage"]["medium"]["url"];
|
||||||
|
|
||||||
term.brightMagenta(`\n title = ${title}\n playbackUrl = ${playbackUrl}\n`);
|
term.brightMagenta(`\n title = ${title}\n playbackUrl = ${playbackUrl}\n`);
|
||||||
|
|
||||||
metadata.push({
|
metadata.push({
|
||||||
|
|
35
Thumbnail.ts
35
Thumbnail.ts
|
@ -1,27 +1,16 @@
|
||||||
import os from 'os';
|
|
||||||
import { terminal as term } from 'terminal-kit';
|
import { terminal as term } from 'terminal-kit';
|
||||||
|
import { execSync } from 'child_process';
|
||||||
|
|
||||||
|
|
||||||
if (os.platform() !== "win32") {
|
export function drawThumbnail(posterImage: string, accessToken: string): void {
|
||||||
term.brightWhite("Platform is not Windows, let's draw some thumbnails!\n");
|
let fetchCmd = `ffmpeg -hide_banner -loglevel warning ` +
|
||||||
let a = async () => {
|
`-headers "Authorization: Bearer ${accessToken}\r\n" ` +
|
||||||
response = await axios.get(posterImageUrl, {
|
`-i "${posterImage}" -y .thumbnail.png`;
|
||||||
headers: {
|
execSync(fetchCmd, { stdio: 'inherit' });
|
||||||
Authorization: `Bearer ${session.AccessToken}`
|
try {
|
||||||
},
|
term.drawImage('.thumbnail.png', { shrink: { width: 50, height: 50 } });
|
||||||
responseType: 'stream'
|
}
|
||||||
});
|
catch (e) {
|
||||||
|
console.error(e);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
term.drawImage('.thumbnail.png', { shrink: { width: 50, height: 50 } });
|
|
|
@ -2,6 +2,7 @@ import { BrowserTests } from './Tests';
|
||||||
import { TokenCache } from './TokenCache';
|
import { TokenCache } from './TokenCache';
|
||||||
import { getVideoMetadata } from './Metadata';
|
import { getVideoMetadata } from './Metadata';
|
||||||
import { Metadata, Session } from './Types';
|
import { Metadata, Session } from './Types';
|
||||||
|
import { drawThumbnail } from './Thumbnail';
|
||||||
|
|
||||||
import { execSync } from 'child_process';
|
import { execSync } from 'child_process';
|
||||||
import puppeteer from 'puppeteer';
|
import puppeteer from 'puppeteer';
|
||||||
|
@ -171,9 +172,13 @@ async function downloadVideo(videoUrls: string[], outputDirectory: string, sessi
|
||||||
|
|
||||||
console.log("Fetching title and HLS URL...");
|
console.log("Fetching title and HLS URL...");
|
||||||
let metadata: Metadata[] = await getVideoMetadata(videoGuids, session);
|
let metadata: Metadata[] = await getVideoMetadata(videoGuids, session);
|
||||||
metadata.forEach(video => {
|
await Promise.all(metadata.map(async video => {
|
||||||
video.title = sanitize(video.title);
|
video.title = sanitize(video.title);
|
||||||
term.blue(`\nDownloading Video: ${video.title}\n`);
|
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...');
|
console.log('Spawning youtube-dl with cookie and HLS URL...');
|
||||||
const format = argv.format ? `-f "${argv.format}"` : "";
|
const format = argv.format ? `-f "${argv.format}"` : "";
|
||||||
var youtubedlCmd = 'youtube-dl --no-call-home --no-warnings ' + 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' });
|
execSync(youtubedlCmd, { stdio: 'inherit' });
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue