import { execSync } from 'child_process'; import colors from 'colors'; import fs from 'fs'; import path from 'path'; function sanitizeUrls(urls: string[]) { const rex = new RegExp(/(?:https:\/\/)?.*\/video\/[a-z0-9]{8}-(?:[a-z0-9]{4}\-){3}[a-z0-9]{12}$/, 'i'); const sanitized: string[] = []; for (let i=0, l=urls.length; i setTimeout(resolve, ms)); } export function checkRequirements() { try { const ffmpegVer = execSync('ffmpeg -version').toString().split('\n')[0]; console.info(colors.green(`Using ${ffmpegVer}\n`)); } catch (e) { return null; } return true; } export function makeUniqueTitle(title: string, outDir: string) { let ntitle = title; let k = 0; while (fs.existsSync(outDir + path.sep + ntitle + '.mp4')) ntitle = title + ' - ' + (++k).toString(); return ntitle; } export function ffmpegTimemarkToChunk(timemark: string) { const timeVals: string[] = timemark.split(':'); const hrs = parseInt(timeVals[0]); const mins = parseInt(timeVals[1]); const secs = parseInt(timeVals[2]); return hrs * 1000 + mins * 100 + secs; }