1
0
mirror of https://github.com/snobu/destreamer.git synced 2026-02-13 18:19:41 +00:00

Created proper error logging (#55)

* changes in the evaluation of sessionInfo

* added Errors struct

* changed error handling if FFmpeg not present

* fixed error loggin thanks to the new Errors struct

* minor fix after changes in sanitizeUrls

* fix for succsesful execution and unknown code
This commit is contained in:
lukaarma
2020-04-11 10:27:48 +02:00
committed by GitHub
parent b5df2a83b1
commit d489b02d03
4 changed files with 58 additions and 46 deletions

View File

@@ -3,6 +3,7 @@ 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[] = [];
@@ -25,9 +26,10 @@ function sanitizeUrls(urls: string[]) {
sanitized.push(url+query);
}
return sanitized;
return sanitized.length ? sanitized : null;
}
export function parseVideoUrls(videoUrls: any) {
const t = videoUrls[0] as string;
const isPath = t.substring(t.length-4) === '.txt';
@@ -41,24 +43,25 @@ export function parseVideoUrls(videoUrls: any) {
return sanitizeUrls(urls);
}
export function sleep(ms: number) {
return new Promise(resolve => 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) {
console.error(colors.red(
'FFmpeg is missing.\nDestreamer requires a fairly recent release of FFmpeg to work properly.\n' +
'Please install it with your preferred package manager or copy FFmpeg binary in destreamer root directory.\n'
));
process.exit(22);
return null;
}
return true;
}
export function makeUniqueTitle(title: string, outDir: string) {
let ntitle = title;
let k = 0;
@@ -67,4 +70,4 @@ export function makeUniqueTitle(title: string, outDir: string) {
ntitle = title + ' - ' + (++k).toString();
return ntitle;
}
}